Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated ComputeSpecialFunctionsTestValues.py #248

Merged
merged 3 commits into from
May 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed safe_quad and NormalCdfLn2.csv
tminka committed May 14, 2020
commit 42cda5947cf175448722f304e73f75014dd0aa03
9 changes: 6 additions & 3 deletions src/Tools/PythonScripts/ComputeSpecialFunctionsTestValues.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@
import os
import csv
from mpmath import *
import mpmath
import time

mp.pretty = True
@@ -107,12 +106,16 @@ def safe_quad(f, points):
if verbose:
print(f"Rescaling integrand by {nstr(1/estimate)}")
result, err = quad(lambda x: f(x)/estimate, points, error=True, verbose=verbose)
result *= estimate
err *= estimate
if mpf(10)**output_dps * abs(err) > abs(result):
estimate = result
if verbose:
print(f"Rescaling integrand by {nstr(1/estimate)}")
result, err = quad(lambda x: f(x)/result, points, error=True, verbose=verbose)
return result*estimate, err*estimate
result, err = quad(lambda x: f(x)/estimate, points, error=True, verbose=verbose)
result *= estimate
err *= estimate
return result, err

def normal_cdf2_ln(x, y, r):
return ln(normal_cdf2(x, y, r))
9 changes: 5 additions & 4 deletions test/Tests/Core/SpecialFunctionsTest.cs
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ namespace Microsoft.ML.Probabilistic.Tests
public class SpecialFunctionsTests
{
public const double TOLERANCE = 1e-15;
const double defaultAssertTolerance = 1e-11;

public delegate double MathFcn(double arg);
public delegate double MathFcn2(double arg1, double arg2);
@@ -1909,22 +1910,22 @@ private static void WritePairs(double[,] pairs, string folder, string name)
}
}

private static void CheckFunctionValues(string name, MathFcn fcn, double[,] pairs, double assertTolerance = 1e-11)
private static void CheckFunctionValues(string name, MathFcn fcn, double[,] pairs, double assertTolerance = defaultAssertTolerance)
{
CheckFunctionValues(name, (Delegate)fcn, pairs, assertTolerance);
}

private static void CheckFunctionValues(string name, MathFcn2 fcn, double[,] pairs, double assertTolerance = 1e-11)
private static void CheckFunctionValues(string name, MathFcn2 fcn, double[,] pairs, double assertTolerance = defaultAssertTolerance)
{
CheckFunctionValues(name, (Delegate)fcn, pairs, assertTolerance);
}

private static void CheckFunctionValues(string name, MathFcn3 fcn, double[,] pairs, double assertTolerance = 1e-11)
private static void CheckFunctionValues(string name, MathFcn3 fcn, double[,] pairs, double assertTolerance = defaultAssertTolerance)
{
CheckFunctionValues(name, (Delegate)fcn, pairs, assertTolerance);
}

private static void CheckFunctionValues(string name, MathFcn4 fcn, double[,] pairs, double assertTolerance = 1e-11)
private static void CheckFunctionValues(string name, MathFcn4 fcn, double[,] pairs, double assertTolerance = defaultAssertTolerance)
{
CheckFunctionValues(name, (Delegate)fcn, pairs, assertTolerance);
}
2 changes: 1 addition & 1 deletion test/Tests/Data/SpecialFunctionsValues/NormalCdfLn2.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
arg0,arg1,arg2,expectedresult
-Infinity,Infinity,0.5,-Infinity
-9945842.62906782515347003936767578125,9945822.06800303049385547637939453125,-0.9891958110248051383450729190371930599212646484375,-49459892801285.500323383881351469927253362271460929
-312498.3686245033168233931064605712890625,312498.2982211210182867944240570068359375,-0.9999893339082690513208717675297521054744720458984375,-48827615315.319765922897082624700306671686794709198
-312498.3686245033168233931064605712890625,312498.2982211210182867944240570068359375,-0.9999893339082690513208717675297521054744720458984375,-48827615210.059272573857776712857226747641701183369
-63,63,-0.46374946374946379723525069493916817009449005126953125,-1989.5623250537256917339818749521250583973045698991
-20,-21,0.5,-287.59599647372995645990323264954196323654372871123
-20,21,-1,-203.91715537228815923684690020322401045645572501133