[poincare/norm_cdf] Evaluation using NormalDistribution

This commit is contained in:
Léa Saviot
2019-08-23 11:04:31 +02:00
parent 0840ca7a1e
commit e1fd5ce5fa
2 changed files with 16 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
#include <poincare/norm_cdf.h>
#include <poincare/layout_helper.h>
#include <poincare/normal_distribution.h>
#include <poincare/serialization_helper.h>
#include <assert.h>
@@ -28,8 +29,18 @@ Expression NormCDFNode::shallowReduce(ReductionContext reductionContext) {
template<typename T>
Evaluation<T> NormCDFNode::templatedApproximate(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
//TODO LEA
return Complex<T>::Builder(0.0);
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);
T a = aEvaluation.toScalar();
T mu = muEvaluation.toScalar();
T sigma = sigmaEvaluation.toScalar();
if (std::isnan(a) || std::isnan(mu) || std::isnan(sigma)) {
return Complex<T>::Undefined();
}
return Complex<T>::Builder(NormalDistribution::CumulativeDistributiveFunctionAtAbscissa(a, mu, sigma));
}
Expression NormCDF::shallowReduce(ExpressionNode::ReductionContext reductionContext) {

View File

@@ -276,6 +276,9 @@ QUIZ_CASE(poincare_approximation_function) {
assert_expression_approximates_to<float>("log(2)", "0.30103");
assert_expression_approximates_to<double>("log(2)", "3.0102999566398ᴇ-1");
assert_expression_approximates_to<float>("normcdf(1.2, 3.4, 5.6)", "0.3472125");
assert_expression_approximates_to<double>("normcdf(1.2, 3.4, 5.6)", "3.4721249841587ᴇ-1");
assert_expression_approximates_to<float>("permute(10, 4)", "5040");
assert_expression_approximates_to<double>("permute(10, 4)", "5040");