зеркало из https://github.com/dotnet/infer.git
GammaUpper tests
This commit is contained in:
Родитель
5b7d93b1b6
Коммит
0f6612e2de
|
@ -1337,11 +1337,12 @@ namespace Microsoft.ML.Probabilistic.Math
|
|||
throw new ArgumentException($"x ({x}) < 0");
|
||||
if (!regularized)
|
||||
{
|
||||
if (a < 1 && x >= 0.1) return GammaUpperConFrac2(a, x, regularized);
|
||||
if (a < 1 && x >= 1) return GammaUpperConFrac2(a, x, regularized);
|
||||
else if (a <= GammaSmallX)
|
||||
{
|
||||
if (x < 1)
|
||||
{
|
||||
// This case is needed by TruncatedGamma_GetMeanPower_WithinBounds
|
||||
double logx = Math.Log(x);
|
||||
return GammaUpperSeries1(a, x, logx, regularized) + GammaUpperConFrac2(a, 1, regularized);
|
||||
}
|
||||
|
@ -1622,7 +1623,7 @@ namespace Microsoft.ML.Probabilistic.Math
|
|||
double term;
|
||||
if (a + i == 0)
|
||||
{
|
||||
term = -Math.Log(x);
|
||||
term = -logx;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -84,6 +84,8 @@ namespace TestApp
|
|||
Stopwatch watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
new OperatorTests().GammaUpper_IsDecreasingInX();
|
||||
|
||||
bool runAllTests = false;
|
||||
if (runAllTests)
|
||||
{
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace Microsoft.ML.Probabilistic.Tests
|
|||
long count = 0;
|
||||
Parallel.ForEach(new[] {
|
||||
GammaPower.FromShapeAndRate(1.7976931348623157E+308, 1.7976931348623157E+308, -1.7976931348623157E+308),
|
||||
}.Concat(OperatorTests.GammaPowers(1000000)), gammaPower =>
|
||||
}.Concat(OperatorTests.GammaPowers(100000)), gammaPower =>
|
||||
{
|
||||
double argmax = double.NaN;
|
||||
double max = double.NegativeInfinity;
|
||||
|
|
|
@ -374,14 +374,22 @@ namespace Microsoft.ML.Probabilistic.Tests
|
|||
double x2 = 1.7976931348623466;
|
||||
x2 = 0.10000000000000024;
|
||||
x2 = 0.099999999999923289;
|
||||
x2 = 1 - 1e-15;
|
||||
double fp = double.NaN;
|
||||
bool anyIncreasing = false;
|
||||
for (int i = 0; i < 10000; i++)
|
||||
Stopwatch watch = new Stopwatch();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
double f = MMath.GammaUpper(4.94065645841247E-324, x2, false);
|
||||
watch.Restart();
|
||||
for (int j = 0; j < 10000; j++)
|
||||
{
|
||||
f = MMath.GammaUpper(4.94065645841247E-324, x2, false);
|
||||
}
|
||||
var elapsed = watch.ElapsedMilliseconds;
|
||||
string star = (f > fp) ? "increasing" : "";
|
||||
anyIncreasing |= (f > fp);
|
||||
Trace.WriteLine($"{x2:g17} {f:g17} {star}");
|
||||
Trace.WriteLine($"{x2:g17} {f:g17} {elapsed} {star}");
|
||||
x2 = MMath.NextDouble(x2);
|
||||
fp = f;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче