-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathigamma.go
43 lines (35 loc) · 1.21 KB
/
igamma.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
// Inverse Gamma distribution (not to be confused with Inverse CDF of Gamma distribution)
package stat
import (
"math"
. "github.com/ematvey/go-fn/fn"
)
// Inverse Gamma distribution: probability density function
func InvGamma_PDF(a, b float64) func(x float64) float64 {
return func(x float64) float64 {
return math.Exp(a*math.Log(b) - LnΓ(a) - (a+1)*math.Log(x) - b*1.0/x)
}
}
// Inverse Gamma distribution: natural logarithm of the probability density function
func InvGamma_LnPDF(a, b float64) func(x float64) float64 {
return func(x float64) float64 {
return a*math.Log(b) - LnΓ(a) - (a+1)*math.Log(x) - b*1.0/x
}
}
// Inverse Gamma distribution: probability density function at x
func InvGamma_PDF_At(a, b float64) func(x float64) float64 {
return func(x float64) float64 {
return math.Exp(a*math.Log(b) - LnΓ(a) - (a+1)*math.Log(x) - b*1.0/x)
}
}
// Inverse Gamma distribution: cumulative distribution function
func InvGamma_CDF(a, b float64) func(x float64) float64 {
return func(x float64) float64 {
return 1 - IΓ(a, b*1.0/x)
}
}
// Inverse Gamma distribution: value of the cumulative distribution function at x
func InvGamma_CDF_At(a, b, x float64) float64 {
cdf := InvGamma_CDF(a, b)
return cdf(x)
}