mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/normalDistribution] Fix sigma/var typo
This commit is contained in:
@@ -7,9 +7,9 @@ namespace Poincare {
|
||||
|
||||
class NormalDistribution final {
|
||||
public:
|
||||
template<typename T> static T EvaluateAtAbscissa(T x, T mu, T sigma);
|
||||
template<typename T> static T CumulativeDistributiveFunctionAtAbscissa(T x, T mu, T sigma);
|
||||
template<typename T> static T CumulativeDistributiveInverseForProbability(T probability, T mu, T sigma);
|
||||
template<typename T> static T EvaluateAtAbscissa(T x, T mu, T var);
|
||||
template<typename T> static T CumulativeDistributiveFunctionAtAbscissa(T x, T mu, T var);
|
||||
template<typename T> static T CumulativeDistributiveInverseForProbability(T probability, T mu, T var);
|
||||
private:
|
||||
/* For the standard normal distribution, P(X < y) > 0.9999995 for y >= 4.892 so the
|
||||
* value displayed is 1. But this is dependent on the fact that we display
|
||||
|
||||
@@ -29,16 +29,16 @@ template<typename T>
|
||||
Evaluation<T> InvNormNode::templatedApproximate(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
Evaluation<T> aEvaluation = childAtIndex(0)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> muEvaluation = childAtIndex(1)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> sigmaEvaluation = childAtIndex(2)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> varEvaluation = childAtIndex(2)->approximate(T(), context, complexFormat, angleUnit);
|
||||
|
||||
T a = aEvaluation.toScalar();
|
||||
T mu = muEvaluation.toScalar();
|
||||
T sigma = sigmaEvaluation.toScalar();
|
||||
T var = varEvaluation.toScalar();
|
||||
|
||||
if (std::isnan(a) || std::isnan(mu) || std::isnan(sigma)) {
|
||||
if (std::isnan(a) || std::isnan(mu) || std::isnan(var)) {
|
||||
return Complex<T>::Undefined();
|
||||
}
|
||||
return Complex<T>::Builder(NormalDistribution::CumulativeDistributiveInverseForProbability<T>(a, mu, sigma));
|
||||
return Complex<T>::Builder(NormalDistribution::CumulativeDistributiveInverseForProbability<T>(a, mu, var));
|
||||
}
|
||||
|
||||
Expression InvNorm::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||
|
||||
@@ -31,16 +31,16 @@ template<typename T>
|
||||
Evaluation<T> NormCDFNode::templatedApproximate(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
Evaluation<T> aEvaluation = childAtIndex(0)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> muEvaluation = childAtIndex(1)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> sigmaEvaluation = childAtIndex(2)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> varEvaluation = childAtIndex(2)->approximate(T(), context, complexFormat, angleUnit);
|
||||
|
||||
T a = aEvaluation.toScalar();
|
||||
T mu = muEvaluation.toScalar();
|
||||
T sigma = sigmaEvaluation.toScalar();
|
||||
T var = varEvaluation.toScalar();
|
||||
|
||||
if (std::isnan(a) || std::isnan(mu) || std::isnan(sigma)) {
|
||||
if (std::isnan(a) || std::isnan(mu) || std::isnan(var)) {
|
||||
return Complex<T>::Undefined();
|
||||
}
|
||||
return Complex<T>::Builder(NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(a, mu, sigma));
|
||||
return Complex<T>::Builder(NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(a, mu, var));
|
||||
}
|
||||
|
||||
Expression NormCDF::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||
|
||||
@@ -32,20 +32,20 @@ Evaluation<T> NormCDF2Node::templatedApproximate(Context * context, Preferences:
|
||||
Evaluation<T> aEvaluation = childAtIndex(0)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> bEvaluation = childAtIndex(1)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> muEvaluation = childAtIndex(2)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> sigmaEvaluation = childAtIndex(3)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> varEvaluation = childAtIndex(3)->approximate(T(), context, complexFormat, angleUnit);
|
||||
|
||||
T a = aEvaluation.toScalar();
|
||||
T b = bEvaluation.toScalar();
|
||||
T mu = muEvaluation.toScalar();
|
||||
T sigma = sigmaEvaluation.toScalar();
|
||||
T var = varEvaluation.toScalar();
|
||||
|
||||
if (std::isnan(a) || std::isnan(b) || std::isnan(mu) || std::isnan(sigma)) {
|
||||
if (std::isnan(a) || std::isnan(b) || std::isnan(mu) || std::isnan(var)) {
|
||||
return Complex<T>::Undefined();
|
||||
}
|
||||
if (b <= a) {
|
||||
return Complex<T>::Builder((T)0.0);
|
||||
}
|
||||
return Complex<T>::Builder(NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(b, mu, sigma) - NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(a, mu, sigma));
|
||||
return Complex<T>::Builder(NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(b, mu, var) - NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(a, mu, var));
|
||||
}
|
||||
|
||||
Expression NormCDF2::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||
|
||||
@@ -31,16 +31,16 @@ template<typename T>
|
||||
Evaluation<T> NormPDFNode::templatedApproximate(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
Evaluation<T> xEvaluation = childAtIndex(0)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> muEvaluation = childAtIndex(1)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> sigmaEvaluation = childAtIndex(2)->approximate(T(), context, complexFormat, angleUnit);
|
||||
Evaluation<T> varEvaluation = childAtIndex(2)->approximate(T(), context, complexFormat, angleUnit);
|
||||
|
||||
T x = xEvaluation.toScalar();
|
||||
T mu = muEvaluation.toScalar();
|
||||
T sigma = sigmaEvaluation.toScalar();
|
||||
T var = varEvaluation.toScalar();
|
||||
|
||||
if (std::isnan(x) || std::isnan(mu) || std::isnan(sigma)) {
|
||||
if (std::isnan(x) || std::isnan(mu) || std::isnan(var)) {
|
||||
return Complex<T>::Undefined();
|
||||
}
|
||||
return Complex<T>::Builder(NormalDistribution::EvaluateAtAbscissa(x, mu, sigma));
|
||||
return Complex<T>::Builder(NormalDistribution::EvaluateAtAbscissa(x, mu, var));
|
||||
}
|
||||
|
||||
Expression NormPDF::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||
|
||||
@@ -7,29 +7,29 @@
|
||||
namespace Poincare {
|
||||
|
||||
template<typename T>
|
||||
T NormalDistribution::EvaluateAtAbscissa(T x, T mu, T sigma) {
|
||||
assert(!std::isnan(x) && !std::isnan(mu) && !std::isnan(sigma));
|
||||
if (sigma == (T)0.0) {
|
||||
T NormalDistribution::EvaluateAtAbscissa(T x, T mu, T var) {
|
||||
assert(!std::isnan(x) && !std::isnan(mu) && !std::isnan(var));
|
||||
if (var == (T)0.0) {
|
||||
return NAN;
|
||||
}
|
||||
const float xMinusMuOverSigma = (x - mu)/sigma;
|
||||
return ((T)1.0)/(std::fabs(sigma) * std::sqrt(((T)2.0) * M_PI)) * std::exp(-((T)0.5) * xMinusMuOverSigma * xMinusMuOverSigma);
|
||||
const float xMinusMuOverVar = (x - mu)/var;
|
||||
return ((T)1.0)/(std::fabs(var) * std::sqrt(((T)2.0) * M_PI)) * std::exp(-((T)0.5) * xMinusMuOverVar * xMinusMuOverVar);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(T x, T mu, T sigma) {
|
||||
if (sigma == (T)0.0) {
|
||||
T NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(T x, T mu, T var) {
|
||||
if (var == (T)0.0) {
|
||||
return NAN;
|
||||
}
|
||||
return StandardNormalCumulativeDistributiveFunctionAtAbscissa<T>((x-mu)/std::fabs(sigma));
|
||||
return StandardNormalCumulativeDistributiveFunctionAtAbscissa<T>((x-mu)/std::fabs(var));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NormalDistribution::CumulativeDistributiveInverseForProbability(T probability, T mu, T sigma) {
|
||||
if (sigma == (T)0.0) {
|
||||
T NormalDistribution::CumulativeDistributiveInverseForProbability(T probability, T mu, T var) {
|
||||
if (var == (T)0.0) {
|
||||
return NAN;
|
||||
}
|
||||
return StandardNormalCumulativeDistributiveInverseForProbability(probability) * std::fabs(sigma) + mu;
|
||||
return StandardNormalCumulativeDistributiveInverseForProbability(probability) * std::fabs(var) + mu;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user