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