mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/norm_cdf] Evaluation using NormalDistribution
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user