mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
[poincare] Add tests for prediction intervals
Change-Id: Ife5c8c7dac83e8631debe2b61e6ef57ae2749161
This commit is contained in:
@@ -39,8 +39,8 @@ Expression * PredictionInterval::privateEvaluate(Context& context, AngleUnit ang
|
||||
float p = m_args[0]->approximate(context, angleUnit);
|
||||
float n = m_args[1]->approximate(context, angleUnit);
|
||||
Expression * operands[2];
|
||||
operands[0] = new Complex(Complex::Float(p - 1.96f*sqrtf(p*(1-p))/sqrtf(n)));
|
||||
operands[1] = new Complex(Complex::Float(p + 1.96f*sqrtf(p*(1-p))/sqrtf(n)));
|
||||
operands[0] = new Complex(Complex::Float(p - 1.96f*sqrtf(p*(1.0f-p))/sqrtf(n)));
|
||||
operands[1] = new Complex(Complex::Float(p + 1.96f*sqrtf(p*(1.0f-p))/sqrtf(n)));
|
||||
return new Matrix(new MatrixData(operands, 2, 2, 1, false));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ QUIZ_CASE(poincare_parse_function) {
|
||||
assert(e->type() == Expression::Type::Determinant);
|
||||
delete e;
|
||||
|
||||
e = Expression::parse("confidence(0.1, 100)");
|
||||
assert(e->type() == Expression::Type::ConfidenceInterval);
|
||||
delete e;
|
||||
|
||||
e = Expression::parse("conj(2)");
|
||||
assert(e->type() == Expression::Type::Conjugate);
|
||||
delete e;
|
||||
@@ -81,6 +85,14 @@ QUIZ_CASE(poincare_parse_function) {
|
||||
assert(e->type() == Expression::Type::PermuteCoefficient);
|
||||
delete e;
|
||||
|
||||
e = Expression::parse("prediction(0.1, 100)");
|
||||
assert(e->type() == Expression::Type::ConfidenceInterval);
|
||||
delete e;
|
||||
|
||||
e = Expression::parse("prediction95(0.1, 100)");
|
||||
assert(e->type() == Expression::Type::PredictionInterval);
|
||||
delete e;
|
||||
|
||||
e = Expression::parse("product(n, 4, 10)");
|
||||
assert(e->type() == Expression::Type::Product);
|
||||
delete e;
|
||||
@@ -238,6 +250,13 @@ QUIZ_CASE(poincare_function_evaluate) {
|
||||
delete a;
|
||||
delete e;
|
||||
|
||||
a = Expression::parse("confidence(0.1, 100)");
|
||||
e = a->evaluate(globalContext);
|
||||
assert(fabsf(e->operand(0)->approximate(globalContext)- 0.1f + sqrtf(1.0f/100.0f)) <= 0.00001f);
|
||||
assert(fabsf(e->operand(1)->approximate(globalContext) - 0.1f - sqrtf(1.0f/100.0f)) <= 0.00001f);
|
||||
delete a;
|
||||
delete e;
|
||||
|
||||
a = Expression::parse("dim([[1,2,3][4,5,-6]])");
|
||||
e = a->evaluate(globalContext);
|
||||
assert(fabsf(e->operand(0)->approximate(globalContext)-2.0f) <= 0.00001f);
|
||||
@@ -267,6 +286,20 @@ QUIZ_CASE(poincare_function_evaluate) {
|
||||
delete a;
|
||||
delete e;
|
||||
|
||||
a = Expression::parse("prediction(0.1, 100)");
|
||||
e = a->evaluate(globalContext);
|
||||
assert(fabsf(e->operand(0)->approximate(globalContext)- 0.1f + sqrtf(1.0f/100.0f)) <= 0.00001f);
|
||||
assert(fabsf(e->operand(1)->approximate(globalContext) - 0.1f - sqrtf(1.0f/100.0f)) <= 0.00001f);
|
||||
delete a;
|
||||
delete e;
|
||||
|
||||
a = Expression::parse("prediction95(0.1, 100)");
|
||||
e = a->evaluate(globalContext);
|
||||
assert(fabsf(e->operand(0)->approximate(globalContext)- 0.1f + 1.96f*sqrtf((0.1f*0.9f)/100.0f)) <= 0.00001f);
|
||||
assert(fabsf(e->operand(1)->approximate(globalContext) - 0.1f - 1.96f*sqrtf((0.1f*0.9f)/100.0f)) <= 0.00001f);
|
||||
delete a;
|
||||
delete e;
|
||||
|
||||
char productText[20] ={'p', 'r', 'o', 'd', 'u', 'c', 't', '(', '2', '+', 'n', '*', Ion::Charset::IComplex, ',', '1', ',','5',')', 0};
|
||||
a = Expression::parse(productText);
|
||||
e = a->evaluate(globalContext);
|
||||
|
||||
Reference in New Issue
Block a user