mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
first version of obidemerge, obijoin and a new filter for obicleandb but to be finnished
Former-commit-id: 8a1ed26e5548c30db75644c294d478ec4d753f19
This commit is contained in:
37
pkg/obistats/tdist.go
Normal file
37
pkg/obistats/tdist.go
Normal file
@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user