-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgostats_test.go
244 lines (216 loc) · 4.62 KB
/
gostats_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package stats_test
import (
"fmt"
"github.com/r0fls/gostats"
)
func ExampleBernoulliRandom() {
stats.Seed()
b := stats.Bernoulli(.6)
fmt.Println(b.Random())
}
func ExampleBernoulliPMF() {
b := stats.Bernoulli(.6)
fmt.Println(b.Pmf(0))
// Output: 0.4
}
func ExampleFitBernoulli() {
data := []int{1, 1, 1, 0, 0}
b := stats.FitBernoulli(data)
fmt.Println(b.Cdf(0))
// Output: 0.4
}
func ExampleBernoulliCDF() {
b := stats.Bernoulli(.6)
fmt.Println(b.Cdf(0))
// Output: 0.4
}
func ExampleBernoulliQuantile() {
b := stats.Bernoulli(.6)
fmt.Println(b.Quantile(.3))
// Output: 0
}
func ExampleLaplaceRandom() {
l := stats.Laplace(0, 1)
fmt.Println(l.Random())
}
func ExampleLaplacePDF() {
l := stats.Laplace(0, 1)
fmt.Println(l.Pdf(0))
// Output: 0.5
}
func ExampleLaplaceCDF() {
l := stats.Laplace(0, 1)
fmt.Println(l.Cdf(0))
// Output: 0.5
}
func ExampleLaplaceQuantile() {
l := stats.Laplace(0, 1)
fmt.Println(l.Quantile(.5))
// Output: 0
}
func ExampleFitLaplace() {
data := []float64{1, 1, 1, 0, 0}
l := stats.FitLaplace(data)
fmt.Println(l.Quantile(.5))
// Output: 1
}
func ExamplePoissonRandom() {
p := stats.Poisson(5)
fmt.Println(p.Random())
}
func ExamplePoissonPMF() {
p := stats.Poisson(5)
fmt.Println(p.Pmf(5))
// Output: 0.1754673697678507
}
func ExamplePoissonCDF() {
p := stats.Poisson(5)
fmt.Println(p.Cdf(10))
// Output: 0.9863047314016171
}
func ExamplePoissonQuantile() {
p := stats.Poisson(5)
fmt.Println(p.Quantile(.5))
// Output: 5
}
func ExampleFitPoisson() {
data := []int{10, 3, 3, 4, 5}
p := stats.FitPoisson(data)
fmt.Println(p.Quantile(.5))
// Output: 5
}
func ExampleGeometricRandom() {
g := stats.Geometric(.2)
fmt.Println(g.Random())
}
func ExampleGeometricPMF() {
g := stats.Geometric(.2)
fmt.Println(g.Pmf(5))
// Output: 0.08192000000000005
}
func ExampleGeometricCDF() {
g := stats.Geometric(.2)
fmt.Println(g.Cdf(10))
// Output: 0.8926258175999999
}
func ExampleGeometricQuantile() {
g := stats.Geometric(.2)
fmt.Println(g.Quantile(.5))
// Output: 4
}
func ExampleFitGeometric() {
data := []int{10, 3, 3, 4, 5}
g := stats.FitGeometric(data)
fmt.Println(g.Quantile(.5))
// Output: 4
}
func ExampleWeibullRandom() {
w := stats.Weibull(.2, 1)
fmt.Println(w.Random())
}
func ExampleWeibullPDF() {
w := stats.Weibull(.2, 1)
fmt.Println(w.Pdf(5))
}
func ExampleWeibullCDF() {
w := stats.Weibull(.2, 1)
fmt.Println(w.Cdf(10))
}
func ExampleWeibullQuantile() {
w := stats.Weibull(.2, 1)
fmt.Println(w.Quantile(.5))
}
func ExampleExponentialRandom() {
e := stats.Exponential(.2)
fmt.Println(e.Random())
}
func ExampleExponentialPDF() {
e := stats.Exponential(.2)
fmt.Println(e.Pdf(5))
// Output: 0.07357588823428847
}
func ExampleExponentialCDF() {
e := stats.Exponential(.2)
fmt.Println(e.Cdf(10))
// Output: 0.8646647167633873
}
func ExampleExponentialQuantile() {
e := stats.Exponential(.2)
fmt.Println(e.Quantile(.5))
// Output: 3.465735902799726
}
func ExampleFitExponential() {
data := []float64{10, 3, 3, 4, 5}
g := stats.FitExponential(data)
fmt.Println(g.Quantile(.5))
// Output: 3.465735902799726
}
func ExampleBinomialRandom() {
r := stats.Binomial(10, .5)
fmt.Println(r.Random())
}
func ExampleBinomialPMF() {
r := stats.Binomial(10, .5)
fmt.Println(r.Pmf(5))
// Output: 0.24609375
}
func ExampleBinomialCDF() {
r := stats.Binomial(10, .5)
fmt.Println(r.Cdf(10))
// Output: 1
}
func ExampleBinomialQuantile() {
r := stats.Binomial(10, .5)
fmt.Println(r.Quantile(.5))
// Output: 5
}
func ExampleNegativeBinomialRandom() {
r := stats.NegativeBinomial(10, .5)
fmt.Println(r.Random())
}
func ExampleNegativeBinomialPMF() {
r := stats.NegativeBinomial(10, .5)
fmt.Println(r.Pmf(5))
// Output: 0.06109619140625
}
func ExampleNegativeBinomialCDF() {
r := stats.NegativeBinomial(10, .5)
fmt.Println(r.Cdf(10))
// Output: 0.5880985260009766
}
func ExampleNegativeBinomialQuantile() {
r := stats.NegativeBinomial(10, .5)
fmt.Println(r.Quantile(.5))
// Output: 9
}
// test common functions
func ExampleSumInt() {
s := []int{2, 3, 5, 7, 11, 13}
sum := stats.SumInt(s)
fmt.Println(sum)
// Output: 41
}
func ExampleSumFloat64() {
s := []float64{2, 3, 5, 7, 11, 13}
sum := stats.SumFloat64(s)
fmt.Println(sum)
// Output: 41
}
func ExampleFactorial() {
fmt.Println(stats.Factorial(4))
// Output: 24
}
func ExampleChoose() {
fmt.Println(stats.Choose(4, 2))
// Output: 6
}
func ExampleMedianInt() {
s := []int{2, 3, 5, 7, 11, 13}
fmt.Println(stats.MedianInt(s))
// Output: 6
}
func ExampleLSR() {
data := [][]float64{{60.0, 3.1}, {61.0, 3.6}, {62.0, 3.8}, {63, 4}, {65.0, 4.1}}
fmt.Println(stats.LSR(data))
// Output: [-7.963513513513208 0.18783783783783292]
}