This repository has been archived by the owner on Nov 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgamma_inc_test.go
138 lines (132 loc) · 4.14 KB
/
gamma_inc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright ©2016 The gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathext
import (
"math"
"testing"
)
func TestGammaInc(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
// Results computed using scipy.special.gamminc
{0, 0, 0},
{0.0001, 1, 0.99997805936186279},
{0.001, 0.005, 0.99528424172333985},
{0.01, 10, 0.99999995718295021},
{0.1, 10, 0.99999944520142825},
{0.25, 0.75, 0.89993651328449831},
{0.5, 0.5, 0.68268949213708596},
{0.5, 2, 0.95449973610364147},
{0.75, 2.5, 0.95053039734695643},
{1, 0.5, 0.39346934028736652},
{1, 1, 0.63212055882855778},
{1.5, 0.75, 0.31772966966378746},
{2.5, 1, 0.15085496391539038},
{3, 0.05, 2.0067493624397931e-05},
{3, 20, 0.99999954448504946},
{5, 50, 1},
{7, 10, 0.86985857911751696},
{10, 0.9, 4.2519575433351128e-08},
{10, 5, 0.031828057306204811},
{25, 10, 4.6949381426799868e-05},
} {
if got := GammaInc(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
t.Errorf("test %d GammaInc(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}
func TestGammaIncComp(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
// Results computed using scipy.special.gammincc
{0.00001, 0.075, 2.0866541002417804e-05},
{0.0001, 1, 2.1940638138146658e-05},
{0.001, 0.005, 0.0047157582766601536},
{0.01, 0.9, 0.0026263432520514662},
{0.25, 0.75, 0.10006348671550169},
{0.5, 0.5, 0.31731050786291404},
{0.75, 0.25, 0.65343980284081038},
{0.9, 0.01, 0.98359881081593148},
{1, 0, 1},
{1, 0.075, 0.92774348632855297},
{1, 1, 0.36787944117144233},
{1, 10, 4.5399929762484861e-05},
{1, math.Inf(1), 0},
{3, 20, 4.5551495055892125e-07},
{5, 10, 0.029252688076961127},
{10, 3, 0.99889751186988451},
{50, 25, 0.99999304669475242},
{100, 10, 1},
{500, 500, 0.49405285382921321},
{500, 550, 0.014614408126291296},
} {
if got := GammaIncComp(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
t.Errorf("test %d GammaIncComp(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}
func TestGammaIncInv(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
// Results computed using scipy.special.gammincinv
{0.001, 0.99, 2.4259428385570885e-05},
{0.01, 0.99, 0.26505255025157959},
{0.1, 0.5, 0.00059339110446022798},
{0.2, 0.8, 0.26354363204872067},
{0.25, 0.5, 0.043673802352873381},
{0.5, 0.25, 0.050765522133810789},
{0.5, 0.5, 0.22746821155978625},
{0.75, 0.25, 0.15340752707472377},
{1, 0, 0},
{1, 0.075, 0.077961541469711862},
{1, 1, math.Inf(1)},
{2.5, 0.99, 7.5431362346944937},
{10, 0.5, 9.6687146147141299},
{25, 0.01, 14.853341349420646},
{25, 0.99, 38.076945624506337},
{50, 0.75, 54.570620535040511},
{100, 0.25, 93.08583383712174},
{1000, 0.01, 927.90815979664251},
{1000, 0.99, 1075.0328320864389},
{10000, 0.5, 9999.6666686420485},
} {
if got := GammaIncInv(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
t.Errorf("test %d GammaIncInv(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}
func TestGammaIncCompInv(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
// Results computed using scipy.special.gamminccinv
{0.001, 0.01, 2.4259428385570885e-05},
{0.01, 0.01, 0.26505255025158292},
{0.03, 0.4, 2.316980536227699e-08},
{0.1, 0.5, 0.00059339110446022798},
{0.1, 0.75, 5.7917132949696076e-07},
{0.25, 0.25, 0.26062600197823282},
{0.5, 0.1, 1.3527717270477047},
{0.5, 0.5, 0.22746821155978625},
{0.75, 0.25, 1.0340914067758025},
{1, 0, math.Inf(1)},
{1, 0.5, 0.69314718055994529},
{1, 1, 0},
{3, 0.75, 1.727299417860519},
{25, 0.4, 25.945791937289371},
{25, 0.7, 22.156653488661991},
{10, 0.5, 9.6687146147141299},
{100, 0.25, 106.5510925269767},
{1000, 0.01, 1075.0328320864389},
{1000, 0.99, 927.90815979664251},
{10000, 0.5, 9999.6666686420485},
} {
if got := GammaIncCompInv(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
t.Errorf("test %d GammaIncCompInv(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}