mathext: Rename GammaInc and friends to GammaIncReg
Fixes
MODIFY
mathext/gamma_inc_inv.go
mathext/gamma_inc_inv.go
@@ -18,17 +18,17 @@ const (
allowedRTol = 1e-6
)
-func gammaInc(x float64, params []float64) float64 {
+func gammaIncReg(x float64, params []float64) float64 {
return cephes.Igam(params[0], x) - params[1]
}
-// gammaIncInv is the inverse of the incomplete Gamma integral. That is, it
+// gammaIncRegInv is the inverse of the regularized incomplete Gamma integral. That is, it
// returns x such that:
// Igam(a, x) = y
// The input argument a must be positive and y must be between 0 and 1
-// inclusive or gammaIncInv will panic. gammaIncInv should return a
+// inclusive or gammaIncRegInv will panic. gammaIncRegInv should return a
// positive number, but can return NaN if there is a failure to converge.
-func gammaIncInv(a, y float64) float64 {
+func gammaIncRegInv(a, y float64) float64 {
// For y not small, we just use
// IgamI(a, 1-y)
// (inverse of the complemented incomplete Gamma integral). For y small,
@@ -47,7 +47,7 @@ func gammaIncInv(a, y float64) float64 {
// Also, after we generate a small interval by bisection above, false
// position will do a large step from an interval of width ~1e-4 to ~1e-14
// in one step (a=10, x=0.05, but similar for other values).
- result, bestX, _, errEst := falsePosition(lo, hi, flo, fhi, 2*machEp, 2*machEp, 1e-2*a, gammaInc, params)
+ result, bestX, _, errEst := falsePosition(lo, hi, flo, fhi, 2*machEp, 2*machEp, 1e-2*a, gammaIncReg, params)
if result == fSolveMaxIterations && errEst > allowedATol+allowedRTol*math.Abs(bestX) {
bestX = math.NaN()
}

MODIFY
mathext/gamma_inc_test.go
mathext/gamma_inc_test.go
@@ -9,7 +9,7 @@ import (
"testing"
)
-func TestGammaInc(t *testing.T) {
+func TestGammaIncReg(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
@@ -35,13 +35,13 @@ func TestGammaInc(t *testing.T) {
{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)
+ if got := GammaIncReg(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
+ t.Errorf("test %d GammaIncReg(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}
-func TestGammaIncComp(t *testing.T) {
+func TestGammaIncRegComp(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
@@ -67,13 +67,13 @@ func TestGammaIncComp(t *testing.T) {
{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)
+ if got := GammaIncRegComp(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
+ t.Errorf("test %d GammaIncRegComp(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}
-func TestGammaIncInv(t *testing.T) {
+func TestGammaIncRegInv(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
@@ -99,13 +99,13 @@ func TestGammaIncInv(t *testing.T) {
{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)
+ if got := GammaIncRegInv(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
+ t.Errorf("test %d GammaIncRegInv(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}
-func TestGammaIncCompInv(t *testing.T) {
+func TestGammaIncRegCompInv(t *testing.T) {
for i, test := range []struct {
a, x, want float64
}{
@@ -131,8 +131,8 @@ func TestGammaIncCompInv(t *testing.T) {
{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)
+ if got := GammaIncRegCompInv(test.a, test.x); math.Abs(got-test.want) > 1e-10 {
+ t.Errorf("test %d GammaIncRegCompInv(%g, %g) failed: got %g want %g", i, test.a, test.x, got, test.want)
}
}
}

MODIFY
stat/distuv/chisquared.go
stat/distuv/chisquared.go
@@ -30,7 +30,7 @@ type ChiSquared struct {
// CDF computes the value of the cumulative density function at x.
func (c ChiSquared) CDF(x float64) float64 {
- return mathext.GammaInc(c.K/2, x/2)
+ return mathext.GammaIncReg(c.K/2, x/2)
}
// ExKurtosis returns the excess kurtosis of the distribution.
@@ -78,7 +78,7 @@ func (c ChiSquared) Quantile(p float64) float64 {
if p < 0 || p > 1 {
panic(badPercentile)
}
- return mathext.GammaIncInv(0.5*c.K, p) * 2
+ return mathext.GammaIncRegInv(0.5*c.K, p) * 2
}
// StdDev returns the standard deviation of the probability distribution.
@@ -91,7 +91,7 @@ func (c ChiSquared) Survival(x float64) float64 {
if x < 0 {
return 1
}
- return mathext.GammaIncComp(0.5*c.K, 0.5*x)
+ return mathext.GammaIncRegComp(0.5*c.K, 0.5*x)
}
// Variance returns the variance of the probability distribution.

MODIFY
stat/distuv/gamma.go
stat/distuv/gamma.go
@@ -35,7 +35,7 @@ func (g Gamma) CDF(x float64) float64 {
if x < 0 {
return 0
}
- return mathext.GammaInc(g.Alpha, g.Beta*x)
+ return mathext.GammaIncReg(g.Alpha, g.Beta*x)
}
// ExKurtosis returns the excess kurtosis of the distribution.
@@ -86,7 +86,7 @@ func (g Gamma) Quantile(p float64) float64 {
if p < 0 || p > 1 {
panic(badPercentile)
}
- return mathext.GammaIncInv(g.Alpha, p) / g.Beta
+ return mathext.GammaIncRegInv(g.Alpha, p) / g.Beta
}
// Rand returns a random sample drawn from the distribution.
@@ -232,7 +232,7 @@ func (g Gamma) Survival(x float64) float64 {
if x < 0 {
return 1
}
- return mathext.GammaIncComp(g.Alpha, g.Beta*x)
+ return mathext.GammaIncRegComp(g.Alpha, g.Beta*x)
}
// StdDev returns the standard deviation of the probability distribution.

MODIFY
stat/distuv/inversegamma.go
stat/distuv/inversegamma.go
@@ -38,7 +38,7 @@ func (g InverseGamma) CDF(x float64) float64 {
// TODO(btracey): Replace this with a direct call to the upper regularized
// gamma function if mathext gets it.
//return 1 - mathext.GammaInc(g.Alpha, g.Beta/x)
- return mathext.GammaIncComp(g.Alpha, g.Beta/x)
+ return mathext.GammaIncRegComp(g.Alpha, g.Beta/x)
}
// ExKurtosis returns the excess kurtosis of the distribution.
@@ -89,7 +89,7 @@ func (g InverseGamma) Quantile(p float64) float64 {
if p < 0 || 1 < p {
panic(badPercentile)
}
- return (1 / (mathext.GammaIncCompInv(g.Alpha, p))) * g.Beta
+ return (1 / (mathext.GammaIncRegCompInv(g.Alpha, p))) * g.Beta
}
// Rand returns a random sample drawn from the distribution.
@@ -105,7 +105,7 @@ func (g InverseGamma) Survival(x float64) float64 {
if x < 0 {
return 1
}
- return mathext.GammaInc(g.Alpha, g.Beta/x)
+ return mathext.GammaIncReg(g.Alpha, g.Beta/x)
}
// StdDev returns the standard deviation of the probability distribution.

MODIFY
stat/distuv/poisson.go
stat/distuv/poisson.go
@@ -31,7 +31,7 @@ func (p Poisson) CDF(x float64) float64 {
if x < 0 {
return 0
}
- return mathext.GammaIncComp(math.Floor(x+1), p.Lambda)
+ return mathext.GammaIncRegComp(math.Floor(x+1), p.Lambda)
}
// ExKurtosis returns the excess kurtosis of the distribution.

mathext: Rename GammaInc and friends to GammaIncReg (#782)

Fixes #470.