Files
obitools4/pkg/obistats/tdist.go
Eric Coissac c7ed47e110 first version of obidemerge, obijoin and a new filter for obicleandb but to be finnished
Former-commit-id: 8a1ed26e5548c30db75644c294d478ec4d753f19
2024-07-10 15:21:42 +02:00

38 lines
789 B
Go

package obistats
//
// Dupplicated code from internal module available at :
// https://github.com/golang-design/bench.git
//
import "math"
// A TDist is a Student's t-distribution with V degrees of freedom.
type TDist struct {
V float64
}
// PDF is the probability distribution function
func (t TDist) PDF(x float64) float64 {
return math.Exp(lgamma((t.V+1)/2)-lgamma(t.V/2)) /
math.Sqrt(t.V*math.Pi) * math.Pow(1+(x*x)/t.V, -(t.V+1)/2)
}
// CDF is the cumulative distribution function
func (t TDist) CDF(x float64) float64 {
if x == 0 {
return 0.5
} else if x > 0 {
return 1 - 0.5*mathBetaInc(t.V/(t.V+x*x), t.V/2, 0.5)
} else if x < 0 {
return 1 - t.CDF(-x)
} else {
return math.NaN()
}
}
// Bounds ...
func (t TDist) Bounds() (float64, float64) {
return -4, 4
}