Browse code

libnetwork: Remove montanaflynn/stats dependency

Replace the stats library usage in cluster_test.go with a small inline
distributionStats helper that computes mean, stddev, min, and max using
stdlib math.

The library was only used in a single test file and pulled in ~4k of
vendored code for trivial arithmetic.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>

Paweł Gronowski authored on 2026/04/16 19:09:08
Showing 43 changed files
... ...
@@ -1,6 +1,7 @@
1 1
 package networkdb
2 2
 
3 3
 import (
4
+	"iter"
4 5
 	"maps"
5 6
 	"math"
6 7
 	"math/bits"
... ...
@@ -8,7 +9,6 @@ import (
8 8
 	"strings"
9 9
 	"testing"
10 10
 
11
-	"github.com/montanaflynn/stats"
12 11
 	"gotest.tools/v3/assert"
13 12
 	is "gotest.tools/v3/assert/cmp"
14 13
 	"pgregory.net/rapid"
... ...
@@ -106,11 +106,7 @@ func TestMRandomNodes(t *testing.T) {
106 106
 			}
107 107
 			// Adding multiple samples together should yield a normal distribution
108 108
 			// if the samples are unbiased.
109
-			countsf := stats.LoadRawData(slices.Collect(maps.Values(counts)))
110
-			nf := stats.NormFit(countsf)
111
-			mean, stdev := nf[0], nf[1]
112
-			minv, _ := countsf.Min()
113
-			maxv, _ := countsf.Max()
109
+			mean, stdev, minv, maxv := distributionStats(maps.Values(counts))
114 110
 			if minv < mean-4*stdev || maxv > mean+4*stdev {
115 111
 				extremes++
116 112
 				t.Logf("Mean: %f, StdDev: %f, Min: %f, Max: %f", mean, stdev, minv, maxv)
... ...
@@ -151,3 +147,26 @@ func kpermutations(n, k uint64) uint64 {
151 151
 	}
152 152
 	return p
153 153
 }
154
+
155
+// distributionStats computes mean, population standard deviation, min, and max
156
+// over the values yielded by the iterator.
157
+func distributionStats(vals iter.Seq[int]) (mean, stdev, minv, maxv float64) {
158
+	var sum, sumSq float64
159
+	var n int
160
+	minv = math.MaxFloat64
161
+	maxv = -math.MaxFloat64
162
+	for v := range vals {
163
+		f := float64(v)
164
+		sum += f
165
+		sumSq += f * f
166
+		minv = min(minv, f)
167
+		maxv = max(maxv, f)
168
+		n++
169
+	}
170
+	if n == 0 {
171
+		return 0, 0, 0, 0
172
+	}
173
+	mean = sum / float64(n)
174
+	stdev = math.Sqrt(sumSq/float64(n) - mean*mean)
175
+	return mean, stdev, minv, maxv
176
+}
... ...
@@ -79,7 +79,6 @@ require (
79 79
 	github.com/moby/sys/user v0.4.0
80 80
 	github.com/moby/sys/userns v0.1.0
81 81
 	github.com/moby/term v0.5.2
82
-	github.com/montanaflynn/stats v0.9.0
83 82
 	github.com/opencontainers/cgroups v0.0.6
84 83
 	github.com/opencontainers/go-digest v1.0.0
85 84
 	github.com/opencontainers/image-spec v1.1.1
... ...
@@ -604,8 +604,6 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
604 604
 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
605 605
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
606 606
 github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
607
-github.com/montanaflynn/stats v0.9.0 h1:tsBJ0RXwph9BmAuFoCmqGv6e8xa0MENQ8m0ptKq29mQ=
608
-github.com/montanaflynn/stats v0.9.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
609 607
 github.com/morikuni/aec v1.1.0 h1:vBBl0pUnvi/Je71dsRrhMBtreIqNMYErSAbEeb8jrXQ=
610 608
 github.com/morikuni/aec v1.1.0/go.mod h1:xDRgiq/iw5l+zkao76YTKzKttOp2cwPEne25HDkJnBw=
611 609
 github.com/mreiferson/go-httpclient v0.0.0-20160630210159-31f0106b4474/go.mod h1:OQA4XLvDbMgS8P0CevmM4m9Q3Jq4phKUzcocxuGJ5m8=
612 610
deleted file mode 100644
... ...
@@ -1 +0,0 @@
1
-test
2 1
\ No newline at end of file
3 2
deleted file mode 100644
... ...
@@ -1,7 +0,0 @@
1
-coverage.out
2
-coverage.txt
3
-release-notes.txt
4
-.directory
5
-.chglog
6
-.vscode
7
-.DS_Store
8 1
\ No newline at end of file
9 2
deleted file mode 100644
... ...
@@ -1,14 +0,0 @@
1
-version: 2
2
-
3
-builds:
4
-  - skip: true
5
-
6
-changelog:
7
-  sort: asc
8
-  groups:
9
-    - title: Fix
10
-      regexp: '^fix:'
11
-    - title: Features
12
-      regexp: '^feat:'
13
-    - title: Other
14
-      order: 999
15 1
deleted file mode 100644
... ...
@@ -1,545 +0,0 @@
1
-<a name="unreleased"></a>
2
-## [Unreleased]
3
-
4
-
5
-<a name="v0.8.0"></a>
6
-## [v0.8.0] - 2026-03-11
7
-### Fix
8
-- Fix Percentile to use standard NIST linear interpolation method ([#92](https://github.com/montanaflynn/stats/issues/92))
9
-- Fix Percentile underflow bug ([#88](https://github.com/montanaflynn/stats/issues/88))
10
-
11
-### Update
12
-- Update Codecov upload to v4 and pass token
13
-
14
-
15
-<a name="v0.7.1"></a>
16
-## [v0.7.1] - 2023-05-11
17
-### Add
18
-- Add describe functions ([#77](https://github.com/montanaflynn/stats/issues/77))
19
-
20
-### Update
21
-- Update .gitignore
22
-- Update README.md, LICENSE and DOCUMENTATION.md files
23
-- Update github action go workflow to run on push
24
-
25
-
26
-<a name="v0.7.0"></a>
27
-## [v0.7.0] - 2023-01-08
28
-### Add
29
-- Add geometric distribution functions ([#75](https://github.com/montanaflynn/stats/issues/75))
30
-- Add GitHub action go workflow
31
-
32
-### Remove
33
-- Remove travis CI config
34
-
35
-### Update
36
-- Update changelog with v0.7.0 changes
37
-- Update changelog with v0.7.0 changes
38
-- Update github action go workflow
39
-- Update geometric distribution tests
40
-
41
-
42
-<a name="v0.6.6"></a>
43
-## [v0.6.6] - 2021-04-26
44
-### Add
45
-- Add support for string and io.Reader in LoadRawData (pr [#68](https://github.com/montanaflynn/stats/issues/68))
46
-- Add latest versions of Go to test against
47
-
48
-### Update
49
-- Update changelog with v0.6.6 changes
50
-
51
-### Use
52
-- Use math.Sqrt in StandardDeviation (PR [#64](https://github.com/montanaflynn/stats/issues/64))
53
-
54
-
55
-<a name="v0.6.5"></a>
56
-## [v0.6.5] - 2021-02-21
57
-### Add
58
-- Add Float64Data.Quartiles documentation
59
-- Add Quartiles method to Float64Data type (issue [#60](https://github.com/montanaflynn/stats/issues/60))
60
-
61
-### Fix
62
-- Fix make release changelog command and add changelog history
63
-
64
-### Update
65
-- Update changelog with v0.6.5 changes
66
-- Update changelog with v0.6.4 changes
67
-- Update README.md links to CHANGELOG.md and DOCUMENTATION.md
68
-- Update README.md and Makefile with new release commands
69
-
70
-
71
-<a name="v0.6.4"></a>
72
-## [v0.6.4] - 2021-01-13
73
-### Fix
74
-- Fix failing tests due to precision errors on arm64 ([#58](https://github.com/montanaflynn/stats/issues/58))
75
-
76
-### Update
77
-- Update changelog with v0.6.4 changes
78
-- Update examples directory to include a README.md used for synopsis
79
-- Update go.mod to include go version where modules are enabled by default
80
-- Update changelog with v0.6.3 changes
81
-
82
-
83
-<a name="v0.6.3"></a>
84
-## [v0.6.3] - 2020-02-18
85
-### Add
86
-- Add creating and committing changelog to Makefile release directive
87
-- Add release-notes.txt and .chglog directory to .gitignore
88
-
89
-### Update
90
-- Update exported tests to use import for better example documentation
91
-- Update documentation using godoc2md
92
-- Update changelog with v0.6.2 release
93
-
94
-
95
-<a name="v0.6.2"></a>
96
-## [v0.6.2] - 2020-02-18
97
-### Fix
98
-- Fix linting errcheck warnings in go benchmarks
99
-
100
-### Update
101
-- Update Makefile release directive to use correct release name
102
-
103
-
104
-<a name="v0.6.1"></a>
105
-## [v0.6.1] - 2020-02-18
106
-### Add
107
-- Add StableSample function signature to readme
108
-
109
-### Fix
110
-- Fix linting warnings for normal distribution functions formatting and tests
111
-
112
-### Update
113
-- Update documentation links and rename DOC.md to DOCUMENTATION.md
114
-- Update README with link to pkg.go.dev reference and release section
115
-- Update Makefile with new changelog, docs, and release directives
116
-- Update DOC.md links to GitHub source code
117
-- Update doc.go comment and add DOC.md package reference file
118
-- Update changelog using git-chglog
119
-
120
-
121
-<a name="v0.6.0"></a>
122
-## [v0.6.0] - 2020-02-17
123
-### Add
124
-- Add Normal Distribution Functions ([#56](https://github.com/montanaflynn/stats/issues/56))
125
-- Add previous versions of Go to travis CI config
126
-- Add check for distinct values in Mode function ([#51](https://github.com/montanaflynn/stats/issues/51))
127
-- Add StableSample function ([#48](https://github.com/montanaflynn/stats/issues/48))
128
-- Add doc.go file to show description and usage on godoc.org
129
-- Add comments to new error and legacy error variables
130
-- Add ExampleRound function to tests
131
-- Add go.mod file for module support
132
-- Add Sigmoid, SoftMax and Entropy methods and tests
133
-- Add Entropy documentation, example and benchmarks
134
-- Add Entropy function ([#44](https://github.com/montanaflynn/stats/issues/44))
135
-
136
-### Fix
137
-- Fix percentile when only one element ([#47](https://github.com/montanaflynn/stats/issues/47))
138
-- Fix AutoCorrelation name in comments and remove unneeded Sprintf
139
-
140
-### Improve
141
-- Improve documentation section with command comments
142
-
143
-### Remove
144
-- Remove very old versions of Go in travis CI config
145
-- Remove boolean comparison to get rid of gometalinter warning
146
-
147
-### Update
148
-- Update license dates
149
-- Update Distance functions signatures to use Float64Data
150
-- Update Sigmoid examples
151
-- Update error names with backward compatibility
152
-
153
-### Use
154
-- Use relative link to examples/main.go
155
-- Use a single var block for exported errors
156
-
157
-
158
-<a name="v0.5.0"></a>
159
-## [v0.5.0] - 2019-01-16
160
-### Add
161
-- Add Sigmoid and Softmax functions
162
-
163
-### Fix
164
-- Fix syntax highlighting and add CumulativeSum func
165
-
166
-
167
-<a name="v0.4.0"></a>
168
-## [v0.4.0] - 2019-01-14
169
-### Add
170
-- Add goreport badge and documentation section to README.md
171
-- Add Examples to test files
172
-- Add AutoCorrelation and nist tests
173
-- Add String method to statsErr type
174
-- Add Y coordinate error for ExponentialRegression
175
-- Add syntax highlighting ([#43](https://github.com/montanaflynn/stats/issues/43))
176
-- Add CumulativeSum ([#40](https://github.com/montanaflynn/stats/issues/40))
177
-- Add more tests and rename distance files
178
-- Add coverage and benchmarks to azure pipeline
179
-- Add go tests to azure pipeline
180
-
181
-### Change
182
-- Change travis tip alias to master
183
-- Change codecov to coveralls for code coverage
184
-
185
-### Fix
186
-- Fix a few lint warnings
187
-- Fix example error
188
-
189
-### Improve
190
-- Improve test coverage of distance functions
191
-
192
-### Only
193
-- Only run travis on stable and tip versions
194
-- Only check code coverage on tip
195
-
196
-### Remove
197
-- Remove azure CI pipeline
198
-- Remove unnecessary type conversions
199
-
200
-### Return
201
-- Return EmptyInputErr instead of EmptyInput
202
-
203
-### Set
204
-- Set up CI with Azure Pipelines
205
-
206
-
207
-<a name="0.3.0"></a>
208
-## [0.3.0] - 2017-12-02
209
-### Add
210
-- Add Chebyshev, Manhattan, Euclidean and Minkowski distance functions ([#35](https://github.com/montanaflynn/stats/issues/35))
211
-- Add function for computing chebyshev distance. ([#34](https://github.com/montanaflynn/stats/issues/34))
212
-- Add support for time.Duration
213
-- Add LoadRawData to docs and examples
214
-- Add unit test for edge case that wasn't covered
215
-- Add unit tests for edge cases that weren't covered
216
-- Add pearson alias delegating to correlation
217
-- Add CovariancePopulation to Float64Data
218
-- Add pearson product-moment correlation coefficient
219
-- Add population covariance
220
-- Add random slice benchmarks
221
-- Add all applicable functions as methods to Float64Data type
222
-- Add MIT license badge
223
-- Add link to examples/methods.go
224
-- Add Protips for usage and documentation sections
225
-- Add tests for rounding up
226
-- Add webdoc target and remove linting from test target
227
-- Add example usage and consolidate contributing information
228
-
229
-### Added
230
-- Added MedianAbsoluteDeviation
231
-
232
-### Annotation
233
-- Annotation spelling error
234
-
235
-### Auto
236
-- auto commit
237
-- auto commit
238
-
239
-### Calculate
240
-- Calculate correlation with sdev and covp
241
-
242
-### Clean
243
-- Clean up README.md and add info for offline docs
244
-
245
-### Consolidated
246
-- Consolidated all error values.
247
-
248
-### Fix
249
-- Fix Percentile logic
250
-- Fix InterQuartileRange method test
251
-- Fix zero percent bug and add test
252
-- Fix usage example output typos
253
-
254
-### Improve
255
-- Improve bounds checking in Percentile
256
-- Improve error log messaging
257
-
258
-### Imput
259
-- Imput -> Input
260
-
261
-### Include
262
-- Include alternative way to set Float64Data in example
263
-
264
-### Make
265
-- Make various changes to README.md
266
-
267
-### Merge
268
-- Merge branch 'master' of github.com:montanaflynn/stats
269
-- Merge master
270
-
271
-### Mode
272
-- Mode calculation fix and tests
273
-
274
-### Realized
275
-- Realized the obvious efficiency gains of ignoring the unique numbers at the beginning of the slice.  Benchmark joy ensued.
276
-
277
-### Refactor
278
-- Refactor testing of Round()
279
-- Refactor setting Coordinate y field using Exp in place of Pow
280
-- Refactor Makefile and add docs target
281
-
282
-### Remove
283
-- Remove deep links to types and functions
284
-
285
-### Rename
286
-- Rename file from types to data
287
-
288
-### Retrieve
289
-- Retrieve InterQuartileRange for the Float64Data.
290
-
291
-### Split
292
-- Split up stats.go into separate files
293
-
294
-### Support
295
-- Support more types on LoadRawData() ([#36](https://github.com/montanaflynn/stats/issues/36))
296
-
297
-### Switch
298
-- Switch default and check targets
299
-
300
-### Update
301
-- Update Readme
302
-- Update example methods and some text
303
-- Update README and include Float64Data type method examples
304
-
305
-### Pull Requests
306
-- Merge pull request [#32](https://github.com/montanaflynn/stats/issues/32) from a-robinson/percentile
307
-- Merge pull request [#30](https://github.com/montanaflynn/stats/issues/30) from montanaflynn/fix-test
308
-- Merge pull request [#29](https://github.com/montanaflynn/stats/issues/29) from edupsousa/master
309
-- Merge pull request [#27](https://github.com/montanaflynn/stats/issues/27) from andrey-yantsen/fix-percentile-out-of-bounds
310
-- Merge pull request [#25](https://github.com/montanaflynn/stats/issues/25) from kazhuravlev/patch-1
311
-- Merge pull request [#22](https://github.com/montanaflynn/stats/issues/22) from JanBerktold/time-duration
312
-- Merge pull request [#24](https://github.com/montanaflynn/stats/issues/24) from alouche/master
313
-- Merge pull request [#21](https://github.com/montanaflynn/stats/issues/21) from brydavis/master
314
-- Merge pull request [#19](https://github.com/montanaflynn/stats/issues/19) from ginodeis/mode-bug
315
-- Merge pull request [#17](https://github.com/montanaflynn/stats/issues/17) from Kunde21/master
316
-- Merge pull request [#3](https://github.com/montanaflynn/stats/issues/3) from montanaflynn/master
317
-- Merge pull request [#2](https://github.com/montanaflynn/stats/issues/2) from montanaflynn/master
318
-- Merge pull request [#13](https://github.com/montanaflynn/stats/issues/13) from toashd/pearson
319
-- Merge pull request [#12](https://github.com/montanaflynn/stats/issues/12) from alixaxel/MAD
320
-- Merge pull request [#1](https://github.com/montanaflynn/stats/issues/1) from montanaflynn/master
321
-- Merge pull request [#11](https://github.com/montanaflynn/stats/issues/11) from Kunde21/modeMemReduce
322
-- Merge pull request [#10](https://github.com/montanaflynn/stats/issues/10) from Kunde21/ModeRewrite
323
-
324
-
325
-<a name="0.2.0"></a>
326
-## [0.2.0] - 2015-10-14
327
-### Add
328
-- Add Makefile with gometalinter, testing, benchmarking and coverage report targets
329
-- Add comments describing functions and structs
330
-- Add Correlation func
331
-- Add Covariance func
332
-- Add tests for new function shortcuts
333
-- Add StandardDeviation function as a shortcut to StandardDeviationPopulation
334
-- Add Float64Data and Series types
335
-
336
-### Change
337
-- Change Sample to return a standard []float64 type
338
-
339
-### Fix
340
-- Fix broken link to Makefile
341
-- Fix broken link and simplify code coverage reporting command
342
-- Fix go vet warning about printf type placeholder
343
-- Fix failing codecov test coverage reporting
344
-- Fix link to CHANGELOG.md
345
-
346
-### Fixed
347
-- Fixed typographical error, changed accomdate to accommodate in README.
348
-
349
-### Include
350
-- Include Variance and StandardDeviation shortcuts
351
-
352
-### Pass
353
-- Pass gometalinter
354
-
355
-### Refactor
356
-- Refactor Variance function to be the same as population variance
357
-
358
-### Release
359
-- Release version 0.2.0
360
-
361
-### Remove
362
-- Remove unneeded do packages and update cover URL
363
-- Remove sudo from pip install
364
-
365
-### Reorder
366
-- Reorder functions and sections
367
-
368
-### Revert
369
-- Revert to legacy containers to preserve go1.1 testing
370
-
371
-### Switch
372
-- Switch from legacy to container-based CI infrastructure
373
-
374
-### Update
375
-- Update contributing instructions and mention Makefile
376
-
377
-### Pull Requests
378
-- Merge pull request [#5](https://github.com/montanaflynn/stats/issues/5) from orthographic-pedant/spell_check/accommodate
379
-
380
-
381
-<a name="0.1.0"></a>
382
-## [0.1.0] - 2015-08-19
383
-### Add
384
-- Add CONTRIBUTING.md
385
-
386
-### Rename
387
-- Rename functions while preserving backwards compatibility
388
-
389
-
390
-<a name="0.0.9"></a>
391
-## 0.0.9 - 2015-08-18
392
-### Add
393
-- Add HarmonicMean func
394
-- Add GeometricMean func
395
-- Add .gitignore to avoid commiting test coverage report
396
-- Add Outliers stuct and QuantileOutliers func
397
-- Add Interquartile Range, Midhinge and Trimean examples
398
-- Add Trimean
399
-- Add Midhinge
400
-- Add Inter Quartile Range
401
-- Add a unit test to check for an empty slice error
402
-- Add Quantiles struct and Quantile func
403
-- Add more tests and fix a typo
404
-- Add Golang 1.5 to build tests
405
-- Add a standard MIT license file
406
-- Add basic benchmarking
407
-- Add regression models
408
-- Add codecov token
409
-- Add codecov
410
-- Add check for slices with a single item
411
-- Add coverage tests
412
-- Add back previous Go versions to Travis CI
413
-- Add Travis CI
414
-- Add GoDoc badge
415
-- Add Percentile and Float64ToInt functions
416
-- Add another rounding test for whole numbers
417
-- Add build status badge
418
-- Add code coverage badge
419
-- Add test for NaN, achieving 100% code coverage
420
-- Add round function
421
-- Add standard deviation function
422
-- Add sum function
423
-
424
-### Add
425
-- add tests for sample
426
-- add sample
427
-
428
-### Added
429
-- Added sample and population variance and deviation functions
430
-- Added README
431
-
432
-### Adjust
433
-- Adjust API ordering
434
-
435
-### Avoid
436
-- Avoid unintended consequence of using sort
437
-
438
-### Better
439
-- Better performing min/max
440
-- Better description
441
-
442
-### Change
443
-- Change package path to potentially fix a bug in earlier versions of Go
444
-
445
-### Clean
446
-- Clean up README and add some more information
447
-- Clean up test error
448
-
449
-### Consistent
450
-- Consistent empty slice error messages
451
-- Consistent var naming
452
-- Consistent func declaration
453
-
454
-### Convert
455
-- Convert ints to floats
456
-
457
-### Duplicate
458
-- Duplicate packages for all versions
459
-
460
-### Export
461
-- Export Coordinate struct fields
462
-
463
-### First
464
-- First commit
465
-
466
-### Fix
467
-- Fix copy pasta mistake testing the wrong function
468
-- Fix error message
469
-- Fix usage output and edit API doc section
470
-- Fix testing edgecase where map was in wrong order
471
-- Fix usage example
472
-- Fix usage examples
473
-
474
-### Include
475
-- Include the Nearest Rank method of calculating percentiles
476
-
477
-### More
478
-- More commenting
479
-
480
-### Move
481
-- Move GoDoc link to top
482
-
483
-### Redirect
484
-- Redirect kills newer versions of Go
485
-
486
-### Refactor
487
-- Refactor code and error checking
488
-
489
-### Remove
490
-- Remove unnecassary typecasting in sum func
491
-- Remove cover since it doesn't work for later versions of go
492
-- Remove golint and gocoveralls
493
-
494
-### Rename
495
-- Rename StandardDev to StdDev
496
-- Rename StandardDev to StdDev
497
-
498
-### Return
499
-- Return errors for all functions
500
-
501
-### Run
502
-- Run go fmt to clean up formatting
503
-
504
-### Simplify
505
-- Simplify min/max function
506
-
507
-### Start
508
-- Start with minimal tests
509
-
510
-### Switch
511
-- Switch wercker to travis and update todos
512
-
513
-### Table
514
-- table testing style
515
-
516
-### Update
517
-- Update README and move the example main.go into it's own file
518
-- Update TODO list
519
-- Update README
520
-- Update usage examples and todos
521
-
522
-### Use
523
-- Use codecov the recommended way
524
-- Use correct string formatting types
525
-
526
-### Pull Requests
527
-- Merge pull request [#4](https://github.com/montanaflynn/stats/issues/4) from saromanov/sample
528
-
529
-
530
-[Unreleased]: https://github.com/montanaflynn/stats/compare/v0.8.0...HEAD
531
-[v0.8.0]: https://github.com/montanaflynn/stats/compare/v0.7.1...v0.8.0
532
-[v0.7.1]: https://github.com/montanaflynn/stats/compare/v0.7.0...v0.7.1
533
-[v0.7.0]: https://github.com/montanaflynn/stats/compare/v0.6.6...v0.7.0
534
-[v0.6.6]: https://github.com/montanaflynn/stats/compare/v0.6.5...v0.6.6
535
-[v0.6.5]: https://github.com/montanaflynn/stats/compare/v0.6.4...v0.6.5
536
-[v0.6.4]: https://github.com/montanaflynn/stats/compare/v0.6.3...v0.6.4
537
-[v0.6.3]: https://github.com/montanaflynn/stats/compare/v0.6.2...v0.6.3
538
-[v0.6.2]: https://github.com/montanaflynn/stats/compare/v0.6.1...v0.6.2
539
-[v0.6.1]: https://github.com/montanaflynn/stats/compare/v0.6.0...v0.6.1
540
-[v0.6.0]: https://github.com/montanaflynn/stats/compare/v0.5.0...v0.6.0
541
-[v0.5.0]: https://github.com/montanaflynn/stats/compare/v0.4.0...v0.5.0
542
-[v0.4.0]: https://github.com/montanaflynn/stats/compare/0.3.0...v0.4.0
543
-[0.3.0]: https://github.com/montanaflynn/stats/compare/0.2.0...0.3.0
544
-[0.2.0]: https://github.com/montanaflynn/stats/compare/0.1.0...0.2.0
545
-[0.1.0]: https://github.com/montanaflynn/stats/compare/0.0.9...0.1.0
546 1
deleted file mode 100644
... ...
@@ -1,1347 +0,0 @@
1
-
2
-
3
-# stats
4
-`import "github.com/montanaflynn/stats"`
5
-
6
-* [Overview](#pkg-overview)
7
-* [Index](#pkg-index)
8
-* [Examples](#pkg-examples)
9
-* [Subdirectories](#pkg-subdirectories)
10
-
11
-## <a name="pkg-overview">Overview</a>
12
-Package stats is a well tested and comprehensive
13
-statistics library package with no dependencies.
14
-
15
-Example Usage:
16
-
17
-
18
-	// start with some source data to use
19
-	data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8}
20
-	
21
-	// you could also use different types like this
22
-	// data := stats.LoadRawData([]int{1, 2, 3, 4, 5})
23
-	// data := stats.LoadRawData([]interface{}{1.1, "2", 3})
24
-	// etc...
25
-	
26
-	median, _ := stats.Median(data)
27
-	fmt.Println(median) // 3.65
28
-	
29
-	roundedMedian, _ := stats.Round(median, 0)
30
-	fmt.Println(roundedMedian) // 4
31
-
32
-MIT License Copyright (c) 2014-2026 Montana Flynn (<a href="https://montanaflynn.com">https://montanaflynn.com</a>)
33
-
34
-
35
-
36
-
37
-## <a name="pkg-index">Index</a>
38
-* [Variables](#pkg-variables)
39
-* [func AutoCorrelation(data Float64Data, lags int) (float64, error)](#AutoCorrelation)
40
-* [func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)](#ChebyshevDistance)
41
-* [func Correlation(data1, data2 Float64Data) (float64, error)](#Correlation)
42
-* [func Covariance(data1, data2 Float64Data) (float64, error)](#Covariance)
43
-* [func CovariancePopulation(data1, data2 Float64Data) (float64, error)](#CovariancePopulation)
44
-* [func CumulativeSum(input Float64Data) ([]float64, error)](#CumulativeSum)
45
-* [func Entropy(input Float64Data) (float64, error)](#Entropy)
46
-* [func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)](#EuclideanDistance)
47
-* [func ExpGeom(p float64) (exp float64, err error)](#ExpGeom)
48
-* [func GeometricMean(input Float64Data) (float64, error)](#GeometricMean)
49
-* [func HarmonicMean(input Float64Data) (float64, error)](#HarmonicMean)
50
-* [func InterQuartileRange(input Float64Data) (float64, error)](#InterQuartileRange)
51
-* [func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)](#ManhattanDistance)
52
-* [func Max(input Float64Data) (max float64, err error)](#Max)
53
-* [func Mean(input Float64Data) (float64, error)](#Mean)
54
-* [func Median(input Float64Data) (median float64, err error)](#Median)
55
-* [func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error)](#MedianAbsoluteDeviation)
56
-* [func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error)](#MedianAbsoluteDeviationPopulation)
57
-* [func Midhinge(input Float64Data) (float64, error)](#Midhinge)
58
-* [func Min(input Float64Data) (min float64, err error)](#Min)
59
-* [func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error)](#MinkowskiDistance)
60
-* [func Mode(input Float64Data) (mode []float64, err error)](#Mode)
61
-* [func Ncr(n, r int) int](#Ncr)
62
-* [func NormBoxMullerRvs(loc float64, scale float64, size int) []float64](#NormBoxMullerRvs)
63
-* [func NormCdf(x float64, loc float64, scale float64) float64](#NormCdf)
64
-* [func NormEntropy(loc float64, scale float64) float64](#NormEntropy)
65
-* [func NormFit(data []float64) [2]float64](#NormFit)
66
-* [func NormInterval(alpha float64, loc float64, scale float64) [2]float64](#NormInterval)
67
-* [func NormIsf(p float64, loc float64, scale float64) (x float64)](#NormIsf)
68
-* [func NormLogCdf(x float64, loc float64, scale float64) float64](#NormLogCdf)
69
-* [func NormLogPdf(x float64, loc float64, scale float64) float64](#NormLogPdf)
70
-* [func NormLogSf(x float64, loc float64, scale float64) float64](#NormLogSf)
71
-* [func NormMean(loc float64, scale float64) float64](#NormMean)
72
-* [func NormMedian(loc float64, scale float64) float64](#NormMedian)
73
-* [func NormMoment(n int, loc float64, scale float64) float64](#NormMoment)
74
-* [func NormPdf(x float64, loc float64, scale float64) float64](#NormPdf)
75
-* [func NormPpf(p float64, loc float64, scale float64) (x float64)](#NormPpf)
76
-* [func NormPpfRvs(loc float64, scale float64, size int) []float64](#NormPpfRvs)
77
-* [func NormSf(x float64, loc float64, scale float64) float64](#NormSf)
78
-* [func NormStats(loc float64, scale float64, moments string) []float64](#NormStats)
79
-* [func NormStd(loc float64, scale float64) float64](#NormStd)
80
-* [func NormVar(loc float64, scale float64) float64](#NormVar)
81
-* [func Pearson(data1, data2 Float64Data) (float64, error)](#Pearson)
82
-* [func Percentile(input Float64Data, percent float64) (percentile float64, err error)](#Percentile)
83
-* [func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error)](#PercentileNearestRank)
84
-* [func PopulationVariance(input Float64Data) (pvar float64, err error)](#PopulationVariance)
85
-* [func ProbGeom(a int, b int, p float64) (prob float64, err error)](#ProbGeom)
86
-* [func Round(input float64, places int) (rounded float64, err error)](#Round)
87
-* [func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error)](#Sample)
88
-* [func SampleVariance(input Float64Data) (svar float64, err error)](#SampleVariance)
89
-* [func Sigmoid(input Float64Data) ([]float64, error)](#Sigmoid)
90
-* [func SoftMax(input Float64Data) ([]float64, error)](#SoftMax)
91
-* [func StableSample(input Float64Data, takenum int) ([]float64, error)](#StableSample)
92
-* [func StandardDeviation(input Float64Data) (sdev float64, err error)](#StandardDeviation)
93
-* [func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)](#StandardDeviationPopulation)
94
-* [func StandardDeviationSample(input Float64Data) (sdev float64, err error)](#StandardDeviationSample)
95
-* [func StdDevP(input Float64Data) (sdev float64, err error)](#StdDevP)
96
-* [func StdDevS(input Float64Data) (sdev float64, err error)](#StdDevS)
97
-* [func Sum(input Float64Data) (sum float64, err error)](#Sum)
98
-* [func Trimean(input Float64Data) (float64, error)](#Trimean)
99
-* [func VarGeom(p float64) (exp float64, err error)](#VarGeom)
100
-* [func VarP(input Float64Data) (sdev float64, err error)](#VarP)
101
-* [func VarS(input Float64Data) (sdev float64, err error)](#VarS)
102
-* [func Variance(input Float64Data) (sdev float64, err error)](#Variance)
103
-* [type Coordinate](#Coordinate)
104
-  * [func ExpReg(s []Coordinate) (regressions []Coordinate, err error)](#ExpReg)
105
-  * [func LinReg(s []Coordinate) (regressions []Coordinate, err error)](#LinReg)
106
-  * [func LogReg(s []Coordinate) (regressions []Coordinate, err error)](#LogReg)
107
-* [type Description](#Description)
108
-  * [func Describe(input Float64Data, allowNaN bool, percentiles *[]float64) (*Description, error)](#Describe)
109
-  * [func DescribePercentileFunc(input Float64Data, allowNaN bool, percentiles *[]float64, percentileFunc func(Float64Data, float64) (float64, error)) (*Description, error)](#DescribePercentileFunc)
110
-  * [func (d *Description) String(decimals int) string](#Description.String)
111
-* [type Float64Data](#Float64Data)
112
-  * [func LoadRawData(raw interface{}) (f Float64Data)](#LoadRawData)
113
-  * [func (f Float64Data) AutoCorrelation(lags int) (float64, error)](#Float64Data.AutoCorrelation)
114
-  * [func (f Float64Data) Correlation(d Float64Data) (float64, error)](#Float64Data.Correlation)
115
-  * [func (f Float64Data) Covariance(d Float64Data) (float64, error)](#Float64Data.Covariance)
116
-  * [func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error)](#Float64Data.CovariancePopulation)
117
-  * [func (f Float64Data) CumulativeSum() ([]float64, error)](#Float64Data.CumulativeSum)
118
-  * [func (f Float64Data) Entropy() (float64, error)](#Float64Data.Entropy)
119
-  * [func (f Float64Data) GeometricMean() (float64, error)](#Float64Data.GeometricMean)
120
-  * [func (f Float64Data) Get(i int) float64](#Float64Data.Get)
121
-  * [func (f Float64Data) HarmonicMean() (float64, error)](#Float64Data.HarmonicMean)
122
-  * [func (f Float64Data) InterQuartileRange() (float64, error)](#Float64Data.InterQuartileRange)
123
-  * [func (f Float64Data) Len() int](#Float64Data.Len)
124
-  * [func (f Float64Data) Less(i, j int) bool](#Float64Data.Less)
125
-  * [func (f Float64Data) Max() (float64, error)](#Float64Data.Max)
126
-  * [func (f Float64Data) Mean() (float64, error)](#Float64Data.Mean)
127
-  * [func (f Float64Data) Median() (float64, error)](#Float64Data.Median)
128
-  * [func (f Float64Data) MedianAbsoluteDeviation() (float64, error)](#Float64Data.MedianAbsoluteDeviation)
129
-  * [func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error)](#Float64Data.MedianAbsoluteDeviationPopulation)
130
-  * [func (f Float64Data) Midhinge(d Float64Data) (float64, error)](#Float64Data.Midhinge)
131
-  * [func (f Float64Data) Min() (float64, error)](#Float64Data.Min)
132
-  * [func (f Float64Data) Mode() ([]float64, error)](#Float64Data.Mode)
133
-  * [func (f Float64Data) Pearson(d Float64Data) (float64, error)](#Float64Data.Pearson)
134
-  * [func (f Float64Data) Percentile(p float64) (float64, error)](#Float64Data.Percentile)
135
-  * [func (f Float64Data) PercentileNearestRank(p float64) (float64, error)](#Float64Data.PercentileNearestRank)
136
-  * [func (f Float64Data) PopulationVariance() (float64, error)](#Float64Data.PopulationVariance)
137
-  * [func (f Float64Data) Quartile(d Float64Data) (Quartiles, error)](#Float64Data.Quartile)
138
-  * [func (f Float64Data) QuartileOutliers() (Outliers, error)](#Float64Data.QuartileOutliers)
139
-  * [func (f Float64Data) Quartiles() (Quartiles, error)](#Float64Data.Quartiles)
140
-  * [func (f Float64Data) Sample(n int, r bool) ([]float64, error)](#Float64Data.Sample)
141
-  * [func (f Float64Data) SampleVariance() (float64, error)](#Float64Data.SampleVariance)
142
-  * [func (f Float64Data) Sigmoid() ([]float64, error)](#Float64Data.Sigmoid)
143
-  * [func (f Float64Data) SoftMax() ([]float64, error)](#Float64Data.SoftMax)
144
-  * [func (f Float64Data) StandardDeviation() (float64, error)](#Float64Data.StandardDeviation)
145
-  * [func (f Float64Data) StandardDeviationPopulation() (float64, error)](#Float64Data.StandardDeviationPopulation)
146
-  * [func (f Float64Data) StandardDeviationSample() (float64, error)](#Float64Data.StandardDeviationSample)
147
-  * [func (f Float64Data) Sum() (float64, error)](#Float64Data.Sum)
148
-  * [func (f Float64Data) Swap(i, j int)](#Float64Data.Swap)
149
-  * [func (f Float64Data) Trimean(d Float64Data) (float64, error)](#Float64Data.Trimean)
150
-  * [func (f Float64Data) Variance() (float64, error)](#Float64Data.Variance)
151
-* [type Outliers](#Outliers)
152
-  * [func QuartileOutliers(input Float64Data) (Outliers, error)](#QuartileOutliers)
153
-* [type Quartiles](#Quartiles)
154
-  * [func Quartile(input Float64Data) (Quartiles, error)](#Quartile)
155
-* [type Series](#Series)
156
-  * [func ExponentialRegression(s Series) (regressions Series, err error)](#ExponentialRegression)
157
-  * [func LinearRegression(s Series) (regressions Series, err error)](#LinearRegression)
158
-  * [func LogarithmicRegression(s Series) (regressions Series, err error)](#LogarithmicRegression)
159
-
160
-#### <a name="pkg-examples">Examples</a>
161
-* [AutoCorrelation](#example_AutoCorrelation)
162
-* [ChebyshevDistance](#example_ChebyshevDistance)
163
-* [Correlation](#example_Correlation)
164
-* [CumulativeSum](#example_CumulativeSum)
165
-* [Entropy](#example_Entropy)
166
-* [ExpGeom](#example_ExpGeom)
167
-* [LinearRegression](#example_LinearRegression)
168
-* [LoadRawData](#example_LoadRawData)
169
-* [Max](#example_Max)
170
-* [Median](#example_Median)
171
-* [Min](#example_Min)
172
-* [ProbGeom](#example_ProbGeom)
173
-* [Round](#example_Round)
174
-* [Sigmoid](#example_Sigmoid)
175
-* [SoftMax](#example_SoftMax)
176
-* [Sum](#example_Sum)
177
-* [VarGeom](#example_VarGeom)
178
-
179
-#### <a name="pkg-files">Package files</a>
180
-[correlation.go](/src/github.com/montanaflynn/stats/correlation.go) [cumulative_sum.go](/src/github.com/montanaflynn/stats/cumulative_sum.go) [data.go](/src/github.com/montanaflynn/stats/data.go) [describe.go](/src/github.com/montanaflynn/stats/describe.go) [deviation.go](/src/github.com/montanaflynn/stats/deviation.go) [distances.go](/src/github.com/montanaflynn/stats/distances.go) [doc.go](/src/github.com/montanaflynn/stats/doc.go) [entropy.go](/src/github.com/montanaflynn/stats/entropy.go) [errors.go](/src/github.com/montanaflynn/stats/errors.go) [geometric_distribution.go](/src/github.com/montanaflynn/stats/geometric_distribution.go) [legacy.go](/src/github.com/montanaflynn/stats/legacy.go) [load.go](/src/github.com/montanaflynn/stats/load.go) [max.go](/src/github.com/montanaflynn/stats/max.go) [mean.go](/src/github.com/montanaflynn/stats/mean.go) [median.go](/src/github.com/montanaflynn/stats/median.go) [min.go](/src/github.com/montanaflynn/stats/min.go) [mode.go](/src/github.com/montanaflynn/stats/mode.go) [norm.go](/src/github.com/montanaflynn/stats/norm.go) [outlier.go](/src/github.com/montanaflynn/stats/outlier.go) [percentile.go](/src/github.com/montanaflynn/stats/percentile.go) [quartile.go](/src/github.com/montanaflynn/stats/quartile.go) [ranksum.go](/src/github.com/montanaflynn/stats/ranksum.go) [regression.go](/src/github.com/montanaflynn/stats/regression.go) [round.go](/src/github.com/montanaflynn/stats/round.go) [sample.go](/src/github.com/montanaflynn/stats/sample.go) [sigmoid.go](/src/github.com/montanaflynn/stats/sigmoid.go) [softmax.go](/src/github.com/montanaflynn/stats/softmax.go) [sum.go](/src/github.com/montanaflynn/stats/sum.go) [util.go](/src/github.com/montanaflynn/stats/util.go) [variance.go](/src/github.com/montanaflynn/stats/variance.go) 
181
-
182
-
183
-
184
-## <a name="pkg-variables">Variables</a>
185
-``` go
186
-var (
187
-    // ErrEmptyInput Input must not be empty
188
-    ErrEmptyInput = statsError{"Input must not be empty."}
189
-    // ErrNaN Not a number
190
-    ErrNaN = statsError{"Not a number."}
191
-    // ErrNegative Must not contain negative values
192
-    ErrNegative = statsError{"Must not contain negative values."}
193
-    // ErrZero Must not contain zero values
194
-    ErrZero = statsError{"Must not contain zero values."}
195
-    // ErrBounds Input is outside of range
196
-    ErrBounds = statsError{"Input is outside of range."}
197
-    // ErrSize Must be the same length
198
-    ErrSize = statsError{"Must be the same length."}
199
-    // ErrInfValue Value is infinite
200
-    ErrInfValue = statsError{"Value is infinite."}
201
-    // ErrYCoord Y Value must be greater than zero
202
-    ErrYCoord = statsError{"Y Value must be greater than zero."}
203
-)
204
-```
205
-These are the package-wide error values.
206
-All error identification should use these values.
207
-<a href="https://github.com/golang/go/wiki/Errors#naming">https://github.com/golang/go/wiki/Errors#naming</a>
208
-
209
-``` go
210
-var (
211
-    EmptyInputErr = ErrEmptyInput
212
-    NaNErr        = ErrNaN
213
-    NegativeErr   = ErrNegative
214
-    ZeroErr       = ErrZero
215
-    BoundsErr     = ErrBounds
216
-    SizeErr       = ErrSize
217
-    InfValue      = ErrInfValue
218
-    YCoordErr     = ErrYCoord
219
-    EmptyInput    = ErrEmptyInput
220
-)
221
-```
222
-Legacy error names that didn't start with Err
223
-
224
-
225
-
226
-## <a name="AutoCorrelation">func</a> [AutoCorrelation](/correlation.go?s=853:918#L38)
227
-``` go
228
-func AutoCorrelation(data Float64Data, lags int) (float64, error)
229
-```
230
-AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay
231
-
232
-
233
-
234
-## <a name="ChebyshevDistance">func</a> [ChebyshevDistance](/distances.go?s=368:456#L20)
235
-``` go
236
-func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)
237
-```
238
-ChebyshevDistance computes the Chebyshev distance between two data sets
239
-
240
-
241
-
242
-## <a name="Correlation">func</a> [Correlation](/correlation.go?s=112:171#L8)
243
-``` go
244
-func Correlation(data1, data2 Float64Data) (float64, error)
245
-```
246
-Correlation describes the degree of relationship between two sets of data
247
-
248
-
249
-
250
-## <a name="Covariance">func</a> [Covariance](/variance.go?s=1284:1342#L53)
251
-``` go
252
-func Covariance(data1, data2 Float64Data) (float64, error)
253
-```
254
-Covariance is a measure of how much two sets of data change
255
-
256
-
257
-
258
-## <a name="CovariancePopulation">func</a> [CovariancePopulation](/variance.go?s=1864:1932#L81)
259
-``` go
260
-func CovariancePopulation(data1, data2 Float64Data) (float64, error)
261
-```
262
-CovariancePopulation computes covariance for entire population between two variables.
263
-
264
-
265
-
266
-## <a name="CumulativeSum">func</a> [CumulativeSum](/cumulative_sum.go?s=81:137#L4)
267
-``` go
268
-func CumulativeSum(input Float64Data) ([]float64, error)
269
-```
270
-CumulativeSum calculates the cumulative sum of the input slice
271
-
272
-
273
-
274
-## <a name="Entropy">func</a> [Entropy](/entropy.go?s=77:125#L6)
275
-``` go
276
-func Entropy(input Float64Data) (float64, error)
277
-```
278
-Entropy provides calculation of the entropy
279
-
280
-
281
-
282
-## <a name="EuclideanDistance">func</a> [EuclideanDistance](/distances.go?s=836:924#L36)
283
-``` go
284
-func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)
285
-```
286
-EuclideanDistance computes the Euclidean distance between two data sets
287
-
288
-
289
-
290
-## <a name="ExpGeom">func</a> [ExpGeom](/geometric_distribution.go?s=652:700#L27)
291
-``` go
292
-func ExpGeom(p float64) (exp float64, err error)
293
-```
294
-ProbGeom generates the expectation or average number of trials
295
-for a geometric random variable with parameter p
296
-
297
-
298
-
299
-## <a name="GeometricMean">func</a> [GeometricMean](/mean.go?s=319:373#L18)
300
-``` go
301
-func GeometricMean(input Float64Data) (float64, error)
302
-```
303
-GeometricMean gets the geometric mean for a slice of numbers
304
-
305
-
306
-
307
-## <a name="HarmonicMean">func</a> [HarmonicMean](/mean.go?s=717:770#L40)
308
-``` go
309
-func HarmonicMean(input Float64Data) (float64, error)
310
-```
311
-HarmonicMean gets the harmonic mean for a slice of numbers
312
-
313
-
314
-
315
-## <a name="InterQuartileRange">func</a> [InterQuartileRange](/quartile.go?s=821:880#L45)
316
-``` go
317
-func InterQuartileRange(input Float64Data) (float64, error)
318
-```
319
-InterQuartileRange finds the range between Q1 and Q3
320
-
321
-
322
-
323
-## <a name="ManhattanDistance">func</a> [ManhattanDistance](/distances.go?s=1277:1365#L50)
324
-``` go
325
-func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)
326
-```
327
-ManhattanDistance computes the Manhattan distance between two data sets
328
-
329
-
330
-
331
-## <a name="Max">func</a> [Max](/max.go?s=78:130#L8)
332
-``` go
333
-func Max(input Float64Data) (max float64, err error)
334
-```
335
-Max finds the highest number in a slice
336
-
337
-
338
-
339
-## <a name="Mean">func</a> [Mean](/mean.go?s=77:122#L6)
340
-``` go
341
-func Mean(input Float64Data) (float64, error)
342
-```
343
-Mean gets the average of a slice of numbers
344
-
345
-
346
-
347
-## <a name="Median">func</a> [Median](/median.go?s=85:143#L6)
348
-``` go
349
-func Median(input Float64Data) (median float64, err error)
350
-```
351
-Median gets the median number in a slice of numbers
352
-
353
-
354
-
355
-## <a name="MedianAbsoluteDeviation">func</a> [MedianAbsoluteDeviation](/deviation.go?s=125:197#L6)
356
-``` go
357
-func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error)
358
-```
359
-MedianAbsoluteDeviation finds the median of the absolute deviations from the dataset median
360
-
361
-
362
-
363
-## <a name="MedianAbsoluteDeviationPopulation">func</a> [MedianAbsoluteDeviationPopulation](/deviation.go?s=360:442#L11)
364
-``` go
365
-func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error)
366
-```
367
-MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median
368
-
369
-
370
-
371
-## <a name="Midhinge">func</a> [Midhinge](/quartile.go?s=1075:1124#L55)
372
-``` go
373
-func Midhinge(input Float64Data) (float64, error)
374
-```
375
-Midhinge finds the average of the first and third quartiles
376
-
377
-
378
-
379
-## <a name="Min">func</a> [Min](/min.go?s=78:130#L6)
380
-``` go
381
-func Min(input Float64Data) (min float64, err error)
382
-```
383
-Min finds the lowest number in a set of data
384
-
385
-
386
-
387
-## <a name="MinkowskiDistance">func</a> [MinkowskiDistance](/distances.go?s=2133:2237#L78)
388
-``` go
389
-func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error)
390
-```
391
-MinkowskiDistance computes the Minkowski distance between two data sets
392
-
393
-Arguments:
394
-
395
-
396
-	dataPointX: First set of data points
397
-	dataPointY: Second set of data points. Length of both data
398
-	            sets must be equal.
399
-	lambda:     aka p or city blocks; With lambda = 1
400
-	            returned distance is manhattan distance and
401
-	            lambda = 2; it is euclidean distance. Lambda
402
-	            reaching to infinite - distance would be chebysev
403
-	            distance.
404
-
405
-Return:
406
-
407
-
408
-	Distance or error
409
-
410
-
411
-
412
-## <a name="Mode">func</a> [Mode](/mode.go?s=85:141#L4)
413
-``` go
414
-func Mode(input Float64Data) (mode []float64, err error)
415
-```
416
-Mode gets the mode [most frequent value(s)] of a slice of float64s
417
-
418
-
419
-
420
-## <a name="Ncr">func</a> [Ncr](/norm.go?s=7384:7406#L239)
421
-``` go
422
-func Ncr(n, r int) int
423
-```
424
-Ncr is an N choose R algorithm.
425
-Aaron Cannon's algorithm.
426
-
427
-
428
-
429
-## <a name="NormBoxMullerRvs">func</a> [NormBoxMullerRvs](/norm.go?s=667:736#L23)
430
-``` go
431
-func NormBoxMullerRvs(loc float64, scale float64, size int) []float64
432
-```
433
-NormBoxMullerRvs generates random variates using the Box–Muller transform.
434
-For more information please visit: <a href="http://mathworld.wolfram.com/Box-MullerTransformation.html">http://mathworld.wolfram.com/Box-MullerTransformation.html</a>
435
-
436
-
437
-
438
-## <a name="NormCdf">func</a> [NormCdf](/norm.go?s=1826:1885#L52)
439
-``` go
440
-func NormCdf(x float64, loc float64, scale float64) float64
441
-```
442
-NormCdf is the cumulative distribution function.
443
-
444
-
445
-
446
-## <a name="NormEntropy">func</a> [NormEntropy](/norm.go?s=5773:5825#L180)
447
-``` go
448
-func NormEntropy(loc float64, scale float64) float64
449
-```
450
-NormEntropy is the differential entropy of the RV.
451
-
452
-
453
-
454
-## <a name="NormFit">func</a> [NormFit](/norm.go?s=6058:6097#L187)
455
-``` go
456
-func NormFit(data []float64) [2]float64
457
-```
458
-NormFit returns the maximum likelihood estimators for the Normal Distribution.
459
-Takes array of float64 values.
460
-Returns array of Mean followed by Standard Deviation.
461
-
462
-
463
-
464
-## <a name="NormInterval">func</a> [NormInterval](/norm.go?s=6976:7047#L221)
465
-``` go
466
-func NormInterval(alpha float64, loc float64, scale float64) [2]float64
467
-```
468
-NormInterval finds endpoints of the range that contains alpha percent of the distribution.
469
-
470
-
471
-
472
-## <a name="NormIsf">func</a> [NormIsf](/norm.go?s=4330:4393#L137)
473
-``` go
474
-func NormIsf(p float64, loc float64, scale float64) (x float64)
475
-```
476
-NormIsf is the inverse survival function (inverse of sf).
477
-
478
-
479
-
480
-## <a name="NormLogCdf">func</a> [NormLogCdf](/norm.go?s=2016:2078#L57)
481
-``` go
482
-func NormLogCdf(x float64, loc float64, scale float64) float64
483
-```
484
-NormLogCdf is the log of the cumulative distribution function.
485
-
486
-
487
-
488
-## <a name="NormLogPdf">func</a> [NormLogPdf](/norm.go?s=1590:1652#L47)
489
-``` go
490
-func NormLogPdf(x float64, loc float64, scale float64) float64
491
-```
492
-NormLogPdf is the log of the probability density function.
493
-
494
-
495
-
496
-## <a name="NormLogSf">func</a> [NormLogSf](/norm.go?s=2423:2484#L67)
497
-``` go
498
-func NormLogSf(x float64, loc float64, scale float64) float64
499
-```
500
-NormLogSf is the log of the survival function.
501
-
502
-
503
-
504
-## <a name="NormMean">func</a> [NormMean](/norm.go?s=6560:6609#L206)
505
-``` go
506
-func NormMean(loc float64, scale float64) float64
507
-```
508
-NormMean is the mean/expected value of the distribution.
509
-
510
-
511
-
512
-## <a name="NormMedian">func</a> [NormMedian](/norm.go?s=6431:6482#L201)
513
-``` go
514
-func NormMedian(loc float64, scale float64) float64
515
-```
516
-NormMedian is the median of the distribution.
517
-
518
-
519
-
520
-## <a name="NormMoment">func</a> [NormMoment](/norm.go?s=4694:4752#L146)
521
-``` go
522
-func NormMoment(n int, loc float64, scale float64) float64
523
-```
524
-NormMoment approximates the non-central (raw) moment of order n.
525
-For more information please visit: <a href="https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution">https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution</a>
526
-
527
-
528
-
529
-## <a name="NormPdf">func</a> [NormPdf](/norm.go?s=1357:1416#L42)
530
-``` go
531
-func NormPdf(x float64, loc float64, scale float64) float64
532
-```
533
-NormPdf is the probability density function.
534
-
535
-
536
-
537
-## <a name="NormPpf">func</a> [NormPpf](/norm.go?s=2854:2917#L75)
538
-``` go
539
-func NormPpf(p float64, loc float64, scale float64) (x float64)
540
-```
541
-NormPpf is the point percentile function.
542
-This is based on Peter John Acklam's inverse normal CDF.
543
-algorithm: <a href="http://home.online.no/~pjacklam/notes/invnorm/">http://home.online.no/~pjacklam/notes/invnorm/</a> (no longer visible).
544
-For more information please visit: <a href="https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/">https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/</a>
545
-
546
-
547
-
548
-## <a name="NormPpfRvs">func</a> [NormPpfRvs](/norm.go?s=247:310#L12)
549
-``` go
550
-func NormPpfRvs(loc float64, scale float64, size int) []float64
551
-```
552
-NormPpfRvs generates random variates using the Point Percentile Function.
553
-For more information please visit: <a href="https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/">https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/</a>
554
-
555
-
556
-
557
-## <a name="NormSf">func</a> [NormSf](/norm.go?s=2250:2308#L62)
558
-``` go
559
-func NormSf(x float64, loc float64, scale float64) float64
560
-```
561
-NormSf is the survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
562
-
563
-
564
-
565
-## <a name="NormStats">func</a> [NormStats](/norm.go?s=5277:5345#L162)
566
-``` go
567
-func NormStats(loc float64, scale float64, moments string) []float64
568
-```
569
-NormStats returns the mean, variance, skew, and/or kurtosis.
570
-Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
571
-Takes string containing any of 'mvsk'.
572
-Returns array of m v s k in that order.
573
-
574
-
575
-
576
-## <a name="NormStd">func</a> [NormStd](/norm.go?s=6814:6862#L216)
577
-``` go
578
-func NormStd(loc float64, scale float64) float64
579
-```
580
-NormStd is the standard deviation of the distribution.
581
-
582
-
583
-
584
-## <a name="NormVar">func</a> [NormVar](/norm.go?s=6675:6723#L211)
585
-``` go
586
-func NormVar(loc float64, scale float64) float64
587
-```
588
-NormVar is the variance of the distribution.
589
-
590
-
591
-
592
-## <a name="Pearson">func</a> [Pearson](/correlation.go?s=655:710#L33)
593
-``` go
594
-func Pearson(data1, data2 Float64Data) (float64, error)
595
-```
596
-Pearson calculates the Pearson product-moment correlation coefficient between two variables
597
-
598
-
599
-
600
-## <a name="Percentile">func</a> [Percentile](/percentile.go?s=598:681#L20)
601
-``` go
602
-func Percentile(input Float64Data, percent float64) (percentile float64, err error)
603
-```
604
-Percentile finds the relative standing in a slice of floats.
605
-
606
-The function uses the Linear Interpolation Between Closest Ranks method
607
-as recommended by NIST [1] and used by Excel (PERCENTILE), Google Sheets,
608
-NumPy (default), and other standard tools.
609
-
610
-Algorithm (for percent p and sorted data of length n):
611
-
612
-
613
-	1. Compute the rank: rank = (p / 100) * (n - 1)
614
-	2. Split into integer part k and fractional part f
615
-	3. Result = data[k] + f * (data[k+1] - data[k])
616
-
617
-[1] <a href="https://www.itl.nist.gov/div898/handbook/prc/section2/prc262.htm">https://www.itl.nist.gov/div898/handbook/prc/section2/prc262.htm</a>
618
-
619
-
620
-
621
-## <a name="PercentileNearestRank">func</a> [PercentileNearestRank](/percentile.go?s=1382:1476#L55)
622
-``` go
623
-func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error)
624
-```
625
-PercentileNearestRank finds the relative standing in a slice of floats using the Nearest Rank method
626
-
627
-
628
-
629
-## <a name="PopulationVariance">func</a> [PopulationVariance](/variance.go?s=828:896#L31)
630
-``` go
631
-func PopulationVariance(input Float64Data) (pvar float64, err error)
632
-```
633
-PopulationVariance finds the amount of variance within a population
634
-
635
-
636
-
637
-## <a name="ProbGeom">func</a> [ProbGeom](/geometric_distribution.go?s=258:322#L10)
638
-``` go
639
-func ProbGeom(a int, b int, p float64) (prob float64, err error)
640
-```
641
-ProbGeom generates the probability for a geometric random variable
642
-with parameter p to achieve success in the interval of [a, b] trials
643
-See <a href="https://en.wikipedia.org/wiki/Geometric_distribution">https://en.wikipedia.org/wiki/Geometric_distribution</a> for more information
644
-
645
-
646
-
647
-## <a name="Round">func</a> [Round](/round.go?s=88:154#L6)
648
-``` go
649
-func Round(input float64, places int) (rounded float64, err error)
650
-```
651
-Round a float to a specific decimal place or precision
652
-
653
-
654
-
655
-## <a name="Sample">func</a> [Sample](/sample.go?s=112:192#L9)
656
-``` go
657
-func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error)
658
-```
659
-Sample returns sample from input with replacement or without
660
-
661
-
662
-
663
-## <a name="SampleVariance">func</a> [SampleVariance](/variance.go?s=1058:1122#L42)
664
-``` go
665
-func SampleVariance(input Float64Data) (svar float64, err error)
666
-```
667
-SampleVariance finds the amount of variance within a sample
668
-
669
-
670
-
671
-## <a name="Sigmoid">func</a> [Sigmoid](/sigmoid.go?s=228:278#L9)
672
-``` go
673
-func Sigmoid(input Float64Data) ([]float64, error)
674
-```
675
-Sigmoid returns the input values in the range of -1 to 1
676
-along the sigmoid or s-shaped curve, commonly used in
677
-machine learning while training neural networks as an
678
-activation function.
679
-
680
-
681
-
682
-## <a name="SoftMax">func</a> [SoftMax](/softmax.go?s=206:256#L8)
683
-``` go
684
-func SoftMax(input Float64Data) ([]float64, error)
685
-```
686
-SoftMax returns the input values in the range of 0 to 1
687
-with sum of all the probabilities being equal to one. It
688
-is commonly used in machine learning neural networks.
689
-
690
-
691
-
692
-## <a name="StableSample">func</a> [StableSample](/sample.go?s=974:1042#L50)
693
-``` go
694
-func StableSample(input Float64Data, takenum int) ([]float64, error)
695
-```
696
-StableSample like stable sort, it returns samples from input while keeps the order of original data.
697
-
698
-
699
-
700
-## <a name="StandardDeviation">func</a> [StandardDeviation](/deviation.go?s=695:762#L27)
701
-``` go
702
-func StandardDeviation(input Float64Data) (sdev float64, err error)
703
-```
704
-StandardDeviation the amount of variation in the dataset
705
-
706
-
707
-
708
-## <a name="StandardDeviationPopulation">func</a> [StandardDeviationPopulation](/deviation.go?s=892:969#L32)
709
-``` go
710
-func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)
711
-```
712
-StandardDeviationPopulation finds the amount of variation from the population
713
-
714
-
715
-
716
-## <a name="StandardDeviationSample">func</a> [StandardDeviationSample](/deviation.go?s=1250:1323#L46)
717
-``` go
718
-func StandardDeviationSample(input Float64Data) (sdev float64, err error)
719
-```
720
-StandardDeviationSample finds the amount of variation from a sample
721
-
722
-
723
-
724
-## <a name="StdDevP">func</a> [StdDevP](/legacy.go?s=339:396#L14)
725
-``` go
726
-func StdDevP(input Float64Data) (sdev float64, err error)
727
-```
728
-StdDevP is a shortcut to StandardDeviationPopulation
729
-
730
-
731
-
732
-## <a name="StdDevS">func</a> [StdDevS](/legacy.go?s=497:554#L19)
733
-``` go
734
-func StdDevS(input Float64Data) (sdev float64, err error)
735
-```
736
-StdDevS is a shortcut to StandardDeviationSample
737
-
738
-
739
-
740
-## <a name="Sum">func</a> [Sum](/sum.go?s=78:130#L6)
741
-``` go
742
-func Sum(input Float64Data) (sum float64, err error)
743
-```
744
-Sum adds all the numbers of a slice together
745
-
746
-
747
-
748
-## <a name="Trimean">func</a> [Trimean](/quartile.go?s=1320:1368#L65)
749
-``` go
750
-func Trimean(input Float64Data) (float64, error)
751
-```
752
-Trimean finds the average of the median and the midhinge
753
-
754
-
755
-
756
-## <a name="VarGeom">func</a> [VarGeom](/geometric_distribution.go?s=885:933#L37)
757
-``` go
758
-func VarGeom(p float64) (exp float64, err error)
759
-```
760
-ProbGeom generates the variance for number for a
761
-geometric random variable with parameter p
762
-
763
-
764
-
765
-## <a name="VarP">func</a> [VarP](/legacy.go?s=59:113#L4)
766
-``` go
767
-func VarP(input Float64Data) (sdev float64, err error)
768
-```
769
-VarP is a shortcut to PopulationVariance
770
-
771
-
772
-
773
-## <a name="VarS">func</a> [VarS](/legacy.go?s=193:247#L9)
774
-``` go
775
-func VarS(input Float64Data) (sdev float64, err error)
776
-```
777
-VarS is a shortcut to SampleVariance
778
-
779
-
780
-
781
-## <a name="Variance">func</a> [Variance](/variance.go?s=659:717#L26)
782
-``` go
783
-func Variance(input Float64Data) (sdev float64, err error)
784
-```
785
-Variance the amount of variation in the dataset
786
-
787
-
788
-
789
-
790
-## <a name="Coordinate">type</a> [Coordinate](/regression.go?s=143:183#L9)
791
-``` go
792
-type Coordinate struct {
793
-    X, Y float64
794
-}
795
-
796
-```
797
-Coordinate holds the data in a series
798
-
799
-
800
-
801
-
802
-
803
-
804
-
805
-### <a name="ExpReg">func</a> [ExpReg](/legacy.go?s=791:856#L29)
806
-``` go
807
-func ExpReg(s []Coordinate) (regressions []Coordinate, err error)
808
-```
809
-ExpReg is a shortcut to ExponentialRegression
810
-
811
-
812
-### <a name="LinReg">func</a> [LinReg](/legacy.go?s=643:708#L24)
813
-``` go
814
-func LinReg(s []Coordinate) (regressions []Coordinate, err error)
815
-```
816
-LinReg is a shortcut to LinearRegression
817
-
818
-
819
-### <a name="LogReg">func</a> [LogReg](/legacy.go?s=944:1009#L34)
820
-``` go
821
-func LogReg(s []Coordinate) (regressions []Coordinate, err error)
822
-```
823
-LogReg is a shortcut to LogarithmicRegression
824
-
825
-
826
-
827
-
828
-
829
-## <a name="Description">type</a> [Description](/describe.go?s=89:349#L6)
830
-``` go
831
-type Description struct {
832
-    Count                  int
833
-    Mean                   float64
834
-    Std                    float64
835
-    Max                    float64
836
-    Min                    float64
837
-    DescriptionPercentiles []descriptionPercentile
838
-    AllowedNaN             bool
839
-}
840
-
841
-```
842
-Holds information about the dataset provided to Describe
843
-
844
-
845
-
846
-
847
-
848
-
849
-
850
-### <a name="Describe">func</a> [Describe](/describe.go?s=579:672#L23)
851
-``` go
852
-func Describe(input Float64Data, allowNaN bool, percentiles *[]float64) (*Description, error)
853
-```
854
-Describe generates descriptive statistics about a provided dataset, similar to python's pandas.describe()
855
-
856
-
857
-### <a name="DescribePercentileFunc">func</a> [DescribePercentileFunc](/describe.go?s=917:1084#L29)
858
-``` go
859
-func DescribePercentileFunc(input Float64Data, allowNaN bool, percentiles *[]float64, percentileFunc func(Float64Data, float64) (float64, error)) (*Description, error)
860
-```
861
-Describe generates descriptive statistics about a provided dataset, similar to python's pandas.describe()
862
-Takes in a function to use for percentile calculation
863
-
864
-
865
-
866
-
867
-
868
-### <a name="Description.String">func</a> (\*Description) [String](/describe.go?s=2078:2127#L68)
869
-``` go
870
-func (d *Description) String(decimals int) string
871
-```
872
-Represents the Description instance in a string format with specified number of decimals
873
-
874
-
875
-	count   3
876
-	mean    2.00
877
-	std     0.82
878
-	max     3.00
879
-	min     1.00
880
-	25.00%  NaN
881
-	50.00%  1.50
882
-	75.00%  2.50
883
-	NaN OK  true
884
-
885
-
886
-
887
-
888
-## <a name="Float64Data">type</a> [Float64Data](/data.go?s=80:106#L4)
889
-``` go
890
-type Float64Data []float64
891
-```
892
-Float64Data is a named type for []float64 with helper methods
893
-
894
-
895
-
896
-
897
-
898
-
899
-
900
-### <a name="LoadRawData">func</a> [LoadRawData](/load.go?s=145:194#L12)
901
-``` go
902
-func LoadRawData(raw interface{}) (f Float64Data)
903
-```
904
-LoadRawData parses and converts a slice of mixed data types to floats
905
-
906
-
907
-
908
-
909
-
910
-### <a name="Float64Data.AutoCorrelation">func</a> (Float64Data) [AutoCorrelation](/data.go?s=3257:3320#L91)
911
-``` go
912
-func (f Float64Data) AutoCorrelation(lags int) (float64, error)
913
-```
914
-AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay
915
-
916
-
917
-
918
-
919
-### <a name="Float64Data.Correlation">func</a> (Float64Data) [Correlation](/data.go?s=3058:3122#L86)
920
-``` go
921
-func (f Float64Data) Correlation(d Float64Data) (float64, error)
922
-```
923
-Correlation describes the degree of relationship between two sets of data
924
-
925
-
926
-
927
-
928
-### <a name="Float64Data.Covariance">func</a> (Float64Data) [Covariance](/data.go?s=4801:4864#L141)
929
-``` go
930
-func (f Float64Data) Covariance(d Float64Data) (float64, error)
931
-```
932
-Covariance is a measure of how much two sets of data change
933
-
934
-
935
-
936
-
937
-### <a name="Float64Data.CovariancePopulation">func</a> (Float64Data) [CovariancePopulation](/data.go?s=4983:5056#L146)
938
-``` go
939
-func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error)
940
-```
941
-CovariancePopulation computes covariance for entire population between two variables
942
-
943
-
944
-
945
-
946
-### <a name="Float64Data.CumulativeSum">func</a> (Float64Data) [CumulativeSum](/data.go?s=883:938#L28)
947
-``` go
948
-func (f Float64Data) CumulativeSum() ([]float64, error)
949
-```
950
-CumulativeSum returns the cumulative sum of the data
951
-
952
-
953
-
954
-
955
-### <a name="Float64Data.Entropy">func</a> (Float64Data) [Entropy](/data.go?s=5480:5527#L162)
956
-``` go
957
-func (f Float64Data) Entropy() (float64, error)
958
-```
959
-Entropy provides calculation of the entropy
960
-
961
-
962
-
963
-
964
-### <a name="Float64Data.GeometricMean">func</a> (Float64Data) [GeometricMean](/data.go?s=1332:1385#L40)
965
-``` go
966
-func (f Float64Data) GeometricMean() (float64, error)
967
-```
968
-GeometricMean returns the median of the data
969
-
970
-
971
-
972
-
973
-### <a name="Float64Data.Get">func</a> (Float64Data) [Get](/data.go?s=129:168#L7)
974
-``` go
975
-func (f Float64Data) Get(i int) float64
976
-```
977
-Get item in slice
978
-
979
-
980
-
981
-
982
-### <a name="Float64Data.HarmonicMean">func</a> (Float64Data) [HarmonicMean](/data.go?s=1460:1512#L43)
983
-``` go
984
-func (f Float64Data) HarmonicMean() (float64, error)
985
-```
986
-HarmonicMean returns the mode of the data
987
-
988
-
989
-
990
-
991
-### <a name="Float64Data.InterQuartileRange">func</a> (Float64Data) [InterQuartileRange](/data.go?s=3755:3813#L106)
992
-``` go
993
-func (f Float64Data) InterQuartileRange() (float64, error)
994
-```
995
-InterQuartileRange finds the range between Q1 and Q3
996
-
997
-
998
-
999
-
1000
-### <a name="Float64Data.Len">func</a> (Float64Data) [Len](/data.go?s=217:247#L10)
1001
-``` go
1002
-func (f Float64Data) Len() int
1003
-```
1004
-Len returns length of slice
1005
-
1006
-
1007
-
1008
-
1009
-### <a name="Float64Data.Less">func</a> (Float64Data) [Less](/data.go?s=318:358#L13)
1010
-``` go
1011
-func (f Float64Data) Less(i, j int) bool
1012
-```
1013
-Less returns if one number is less than another
1014
-
1015
-
1016
-
1017
-
1018
-### <a name="Float64Data.Max">func</a> (Float64Data) [Max](/data.go?s=645:688#L22)
1019
-``` go
1020
-func (f Float64Data) Max() (float64, error)
1021
-```
1022
-Max returns the maximum number in the data
1023
-
1024
-
1025
-
1026
-
1027
-### <a name="Float64Data.Mean">func</a> (Float64Data) [Mean](/data.go?s=1005:1049#L31)
1028
-``` go
1029
-func (f Float64Data) Mean() (float64, error)
1030
-```
1031
-Mean returns the mean of the data
1032
-
1033
-
1034
-
1035
-
1036
-### <a name="Float64Data.Median">func</a> (Float64Data) [Median](/data.go?s=1111:1157#L34)
1037
-``` go
1038
-func (f Float64Data) Median() (float64, error)
1039
-```
1040
-Median returns the median of the data
1041
-
1042
-
1043
-
1044
-
1045
-### <a name="Float64Data.MedianAbsoluteDeviation">func</a> (Float64Data) [MedianAbsoluteDeviation](/data.go?s=1630:1693#L46)
1046
-``` go
1047
-func (f Float64Data) MedianAbsoluteDeviation() (float64, error)
1048
-```
1049
-MedianAbsoluteDeviation the median of the absolute deviations from the dataset median
1050
-
1051
-
1052
-
1053
-
1054
-### <a name="Float64Data.MedianAbsoluteDeviationPopulation">func</a> (Float64Data) [MedianAbsoluteDeviationPopulation](/data.go?s=1842:1915#L51)
1055
-``` go
1056
-func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error)
1057
-```
1058
-MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median
1059
-
1060
-
1061
-
1062
-
1063
-### <a name="Float64Data.Midhinge">func</a> (Float64Data) [Midhinge](/data.go?s=3912:3973#L111)
1064
-``` go
1065
-func (f Float64Data) Midhinge(d Float64Data) (float64, error)
1066
-```
1067
-Midhinge finds the average of the first and third quartiles
1068
-
1069
-
1070
-
1071
-
1072
-### <a name="Float64Data.Min">func</a> (Float64Data) [Min](/data.go?s=536:579#L19)
1073
-``` go
1074
-func (f Float64Data) Min() (float64, error)
1075
-```
1076
-Min returns the minimum number in the data
1077
-
1078
-
1079
-
1080
-
1081
-### <a name="Float64Data.Mode">func</a> (Float64Data) [Mode](/data.go?s=1217:1263#L37)
1082
-``` go
1083
-func (f Float64Data) Mode() ([]float64, error)
1084
-```
1085
-Mode returns the mode of the data
1086
-
1087
-
1088
-
1089
-
1090
-### <a name="Float64Data.Pearson">func</a> (Float64Data) [Pearson](/data.go?s=3455:3515#L96)
1091
-``` go
1092
-func (f Float64Data) Pearson(d Float64Data) (float64, error)
1093
-```
1094
-Pearson calculates the Pearson product-moment correlation coefficient between two variables.
1095
-
1096
-
1097
-
1098
-
1099
-### <a name="Float64Data.Percentile">func</a> (Float64Data) [Percentile](/data.go?s=2696:2755#L76)
1100
-``` go
1101
-func (f Float64Data) Percentile(p float64) (float64, error)
1102
-```
1103
-Percentile finds the relative standing in a slice of floats
1104
-
1105
-
1106
-
1107
-
1108
-### <a name="Float64Data.PercentileNearestRank">func</a> (Float64Data) [PercentileNearestRank](/data.go?s=2869:2939#L81)
1109
-``` go
1110
-func (f Float64Data) PercentileNearestRank(p float64) (float64, error)
1111
-```
1112
-PercentileNearestRank finds the relative standing using the Nearest Rank method
1113
-
1114
-
1115
-
1116
-
1117
-### <a name="Float64Data.PopulationVariance">func</a> (Float64Data) [PopulationVariance](/data.go?s=4495:4553#L131)
1118
-``` go
1119
-func (f Float64Data) PopulationVariance() (float64, error)
1120
-```
1121
-PopulationVariance finds the amount of variance within a population
1122
-
1123
-
1124
-
1125
-
1126
-### <a name="Float64Data.Quartile">func</a> (Float64Data) [Quartile](/data.go?s=3610:3673#L101)
1127
-``` go
1128
-func (f Float64Data) Quartile(d Float64Data) (Quartiles, error)
1129
-```
1130
-Quartile returns the three quartile points from a slice of data
1131
-
1132
-
1133
-
1134
-
1135
-### <a name="Float64Data.QuartileOutliers">func</a> (Float64Data) [QuartileOutliers](/data.go?s=2542:2599#L71)
1136
-``` go
1137
-func (f Float64Data) QuartileOutliers() (Outliers, error)
1138
-```
1139
-QuartileOutliers finds the mild and extreme outliers
1140
-
1141
-
1142
-
1143
-
1144
-### <a name="Float64Data.Quartiles">func</a> (Float64Data) [Quartiles](/data.go?s=5628:5679#L167)
1145
-``` go
1146
-func (f Float64Data) Quartiles() (Quartiles, error)
1147
-```
1148
-Quartiles returns the three quartile points from instance of Float64Data
1149
-
1150
-
1151
-
1152
-
1153
-### <a name="Float64Data.Sample">func</a> (Float64Data) [Sample](/data.go?s=4208:4269#L121)
1154
-``` go
1155
-func (f Float64Data) Sample(n int, r bool) ([]float64, error)
1156
-```
1157
-Sample returns sample from input with replacement or without
1158
-
1159
-
1160
-
1161
-
1162
-### <a name="Float64Data.SampleVariance">func</a> (Float64Data) [SampleVariance](/data.go?s=4652:4706#L136)
1163
-``` go
1164
-func (f Float64Data) SampleVariance() (float64, error)
1165
-```
1166
-SampleVariance finds the amount of variance within a sample
1167
-
1168
-
1169
-
1170
-
1171
-### <a name="Float64Data.Sigmoid">func</a> (Float64Data) [Sigmoid](/data.go?s=5169:5218#L151)
1172
-``` go
1173
-func (f Float64Data) Sigmoid() ([]float64, error)
1174
-```
1175
-Sigmoid returns the input values along the sigmoid or s-shaped curve
1176
-
1177
-
1178
-
1179
-
1180
-### <a name="Float64Data.SoftMax">func</a> (Float64Data) [SoftMax](/data.go?s=5359:5408#L157)
1181
-``` go
1182
-func (f Float64Data) SoftMax() ([]float64, error)
1183
-```
1184
-SoftMax returns the input values in the range of 0 to 1
1185
-with sum of all the probabilities being equal to one.
1186
-
1187
-
1188
-
1189
-
1190
-### <a name="Float64Data.StandardDeviation">func</a> (Float64Data) [StandardDeviation](/data.go?s=2026:2083#L56)
1191
-``` go
1192
-func (f Float64Data) StandardDeviation() (float64, error)
1193
-```
1194
-StandardDeviation the amount of variation in the dataset
1195
-
1196
-
1197
-
1198
-
1199
-### <a name="Float64Data.StandardDeviationPopulation">func</a> (Float64Data) [StandardDeviationPopulation](/data.go?s=2199:2266#L61)
1200
-``` go
1201
-func (f Float64Data) StandardDeviationPopulation() (float64, error)
1202
-```
1203
-StandardDeviationPopulation finds the amount of variation from the population
1204
-
1205
-
1206
-
1207
-
1208
-### <a name="Float64Data.StandardDeviationSample">func</a> (Float64Data) [StandardDeviationSample](/data.go?s=2382:2445#L66)
1209
-``` go
1210
-func (f Float64Data) StandardDeviationSample() (float64, error)
1211
-```
1212
-StandardDeviationSample finds the amount of variation from a sample
1213
-
1214
-
1215
-
1216
-
1217
-### <a name="Float64Data.Sum">func</a> (Float64Data) [Sum](/data.go?s=764:807#L25)
1218
-``` go
1219
-func (f Float64Data) Sum() (float64, error)
1220
-```
1221
-Sum returns the total of all the numbers in the data
1222
-
1223
-
1224
-
1225
-
1226
-### <a name="Float64Data.Swap">func</a> (Float64Data) [Swap](/data.go?s=425:460#L16)
1227
-``` go
1228
-func (f Float64Data) Swap(i, j int)
1229
-```
1230
-Swap switches out two numbers in slice
1231
-
1232
-
1233
-
1234
-
1235
-### <a name="Float64Data.Trimean">func</a> (Float64Data) [Trimean](/data.go?s=4059:4119#L116)
1236
-``` go
1237
-func (f Float64Data) Trimean(d Float64Data) (float64, error)
1238
-```
1239
-Trimean finds the average of the median and the midhinge
1240
-
1241
-
1242
-
1243
-
1244
-### <a name="Float64Data.Variance">func</a> (Float64Data) [Variance](/data.go?s=4350:4398#L126)
1245
-``` go
1246
-func (f Float64Data) Variance() (float64, error)
1247
-```
1248
-Variance the amount of variation in the dataset
1249
-
1250
-
1251
-
1252
-
1253
-## <a name="Outliers">type</a> [Outliers](/outlier.go?s=73:139#L4)
1254
-``` go
1255
-type Outliers struct {
1256
-    Mild    Float64Data
1257
-    Extreme Float64Data
1258
-}
1259
-
1260
-```
1261
-Outliers holds mild and extreme outliers found in data
1262
-
1263
-
1264
-
1265
-
1266
-
1267
-
1268
-
1269
-### <a name="QuartileOutliers">func</a> [QuartileOutliers](/outlier.go?s=197:255#L10)
1270
-``` go
1271
-func QuartileOutliers(input Float64Data) (Outliers, error)
1272
-```
1273
-QuartileOutliers finds the mild and extreme outliers
1274
-
1275
-
1276
-
1277
-
1278
-
1279
-## <a name="Quartiles">type</a> [Quartiles](/quartile.go?s=75:136#L6)
1280
-``` go
1281
-type Quartiles struct {
1282
-    Q1 float64
1283
-    Q2 float64
1284
-    Q3 float64
1285
-}
1286
-
1287
-```
1288
-Quartiles holds the three quartile points
1289
-
1290
-
1291
-
1292
-
1293
-
1294
-
1295
-
1296
-### <a name="Quartile">func</a> [Quartile](/quartile.go?s=205:256#L13)
1297
-``` go
1298
-func Quartile(input Float64Data) (Quartiles, error)
1299
-```
1300
-Quartile returns the three quartile points from a slice of data
1301
-
1302
-
1303
-
1304
-
1305
-
1306
-## <a name="Series">type</a> [Series](/regression.go?s=76:100#L6)
1307
-``` go
1308
-type Series []Coordinate
1309
-```
1310
-Series is a container for a series of data
1311
-
1312
-
1313
-
1314
-
1315
-
1316
-
1317
-
1318
-### <a name="ExponentialRegression">func</a> [ExponentialRegression](/regression.go?s=1089:1157#L50)
1319
-``` go
1320
-func ExponentialRegression(s Series) (regressions Series, err error)
1321
-```
1322
-ExponentialRegression returns an exponential regression on data series
1323
-
1324
-
1325
-### <a name="LinearRegression">func</a> [LinearRegression](/regression.go?s=262:325#L14)
1326
-``` go
1327
-func LinearRegression(s Series) (regressions Series, err error)
1328
-```
1329
-LinearRegression finds the least squares linear regression on data series
1330
-
1331
-
1332
-### <a name="LogarithmicRegression">func</a> [LogarithmicRegression](/regression.go?s=1903:1971#L85)
1333
-``` go
1334
-func LogarithmicRegression(s Series) (regressions Series, err error)
1335
-```
1336
-LogarithmicRegression returns an logarithmic regression on data series
1337
-
1338
-
1339
-
1340
-
1341
-
1342
-
1343
-
1344
-
1345
-
1346
-- - -
1347
-Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)
1348 1
deleted file mode 100644
... ...
@@ -1,21 +0,0 @@
1
-The MIT License (MIT)
2
-
3
-Copyright (c) 2014-2026 Montana Flynn (https://montanaflynn.com)
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in all
13
-copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
-SOFTWARE.
22 1
deleted file mode 100644
... ...
@@ -1,34 +0,0 @@
1
-.PHONY: all
2
-
3
-default: test lint
4
-
5
-format: 
6
-	go fmt .
7
-
8
-test:
9
-	go test -race 
10
-	
11
-check: format test
12
-
13
-benchmark:
14
-	go test -bench=. -benchmem
15
-
16
-coverage:
17
-	go test -coverprofile=coverage.out
18
-	go tool cover -html="coverage.out"
19
-
20
-lint: format
21
-	golangci-lint run .
22
-
23
-docs:
24
-	godoc2md github.com/montanaflynn/stats | sed -e s#src/target/##g > DOCUMENTATION.md
25
-
26
-release:
27
-	git-chglog --output CHANGELOG.md --next-tag ${TAG}
28
-	git add CHANGELOG.md
29
-	git commit -m "Update changelog with ${TAG} changes"
30
-	git tag ${TAG}
31
-	git-chglog $(TAG) | tail -n +4 | gsed '1s/^/$(TAG)\n/gm' > release-notes.txt
32
-	git push origin master ${TAG}
33
-	hub release create --copy -F release-notes.txt ${TAG}
34
-
35 1
deleted file mode 100644
... ...
@@ -1,221 +0,0 @@
1
-# Stats - Golang Statistics Package
2
-
3
-[![][action-svg]][action-url] [![][codecov-svg]][codecov-url] [![][goreport-svg]][goreport-url] [![][godoc-svg]][godoc-url] [![][pkggodev-svg]][pkggodev-url] [![][license-svg]][license-url]
4
-
5
-A well tested and comprehensive Golang statistics library / package / module with no dependencies.
6
-
7
-If you have any suggestions, problems or bug reports please [create an issue](https://github.com/montanaflynn/stats/issues) and I'll do my best to accommodate you. In addition simply starring the repo would show your support for the project and be very much appreciated!
8
-
9
-## Installation
10
-
11
-```
12
-go get github.com/montanaflynn/stats
13
-```
14
-
15
-## Example Usage
16
-
17
-All the functions can be seen in [examples/main.go](examples/main.go) but here's a little taste:
18
-
19
-```go
20
-// start with some source data to use
21
-data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8}
22
-
23
-// you could also use different types like this
24
-// data := stats.LoadRawData([]int{1, 2, 3, 4, 5})
25
-// data := stats.LoadRawData([]interface{}{1.1, "2", 3})
26
-// etc...
27
-
28
-median, _ := stats.Median(data)
29
-fmt.Println(median) // 3.65
30
-
31
-roundedMedian, _ := stats.Round(median, 0)
32
-fmt.Println(roundedMedian) // 4
33
-```
34
-
35
-## Documentation
36
-
37
-The entire API documentation is available on [GoDoc.org](http://godoc.org/github.com/montanaflynn/stats) or [pkg.go.dev](https://pkg.go.dev/github.com/montanaflynn/stats).
38
-
39
-You can also view docs offline with the following commands:
40
-
41
-```
42
-# Command line
43
-godoc .              # show all exported apis
44
-godoc . Median       # show a single function
45
-godoc -ex . Round    # show function with example
46
-godoc . Float64Data  # show the type and methods
47
-
48
-# Local website
49
-godoc -http=:4444    # start the godoc server on port 4444
50
-open http://localhost:4444/pkg/github.com/montanaflynn/stats/
51
-```
52
-
53
-The exported API is as follows:
54
-
55
-```go
56
-var (
57
-    ErrEmptyInput = statsError{"Input must not be empty."}
58
-    ErrNaN        = statsError{"Not a number."}
59
-    ErrNegative   = statsError{"Must not contain negative values."}
60
-    ErrZero       = statsError{"Must not contain zero values."}
61
-    ErrBounds     = statsError{"Input is outside of range."}
62
-    ErrSize       = statsError{"Must be the same length."}
63
-    ErrInfValue   = statsError{"Value is infinite."}
64
-    ErrYCoord     = statsError{"Y Value must be greater than zero."}
65
-)
66
-
67
-func Round(input float64, places int) (rounded float64, err error) {}
68
-
69
-type Float64Data []float64
70
-
71
-func LoadRawData(raw interface{}) (f Float64Data) {}
72
-
73
-func AutoCorrelation(data Float64Data, lags int) (float64, error) {}
74
-func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {}
75
-func Correlation(data1, data2 Float64Data) (float64, error) {}
76
-func Covariance(data1, data2 Float64Data) (float64, error) {}
77
-func CovariancePopulation(data1, data2 Float64Data) (float64, error) {}
78
-func CumulativeSum(input Float64Data) ([]float64, error) {}
79
-func Describe(input Float64Data, allowNaN bool, percentiles *[]float64) (*Description, error) {}
80
-func DescribePercentileFunc(input Float64Data, allowNaN bool, percentiles *[]float64, percentileFunc func(Float64Data, float64) (float64, error)) (*Description, error) {}
81
-func Entropy(input Float64Data) (float64, error) {}
82
-func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {}
83
-func GeometricMean(input Float64Data) (float64, error) {}
84
-func HarmonicMean(input Float64Data) (float64, error) {}
85
-func InterQuartileRange(input Float64Data) (float64, error) {}
86
-func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {}
87
-func Max(input Float64Data) (max float64, err error) {}
88
-func Mean(input Float64Data) (float64, error) {}
89
-func Median(input Float64Data) (median float64, err error) {}
90
-func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error) {}
91
-func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) {}
92
-func Midhinge(input Float64Data) (float64, error) {}
93
-func Min(input Float64Data) (min float64, err error) {}
94
-func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error) {}
95
-func Mode(input Float64Data) (mode []float64, err error) {}
96
-func NormBoxMullerRvs(loc float64, scale float64, size int) []float64 {}
97
-func NormCdf(x float64, loc float64, scale float64) float64 {}
98
-func NormEntropy(loc float64, scale float64) float64 {}
99
-func NormFit(data []float64) [2]float64{}
100
-func NormInterval(alpha float64, loc float64,  scale float64 ) [2]float64 {}
101
-func NormIsf(p float64, loc float64, scale float64) (x float64) {}
102
-func NormLogCdf(x float64, loc float64, scale float64) float64 {}
103
-func NormLogPdf(x float64, loc float64, scale float64) float64 {}
104
-func NormLogSf(x float64, loc float64, scale float64) float64 {}
105
-func NormMean(loc float64, scale float64) float64 {}
106
-func NormMedian(loc float64, scale float64) float64 {}
107
-func NormMoment(n int, loc float64, scale float64) float64 {}
108
-func NormPdf(x float64, loc float64, scale float64) float64 {}
109
-func NormPpf(p float64, loc float64, scale float64) (x float64) {}
110
-func NormPpfRvs(loc float64, scale float64, size int) []float64 {}
111
-func NormSf(x float64, loc float64, scale float64) float64 {}
112
-func NormStats(loc float64, scale float64, moments string) []float64 {}
113
-func NormStd(loc float64, scale float64) float64 {}
114
-func NormVar(loc float64, scale float64) float64 {}
115
-func Pearson(data1, data2 Float64Data) (float64, error) {}
116
-func Percentile(input Float64Data, percent float64) (percentile float64, err error) {}
117
-func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) {}
118
-func PopulationSkewness(input Float64Data) (float64, error) {}
119
-func PopulationVariance(input Float64Data) (pvar float64, err error) {}
120
-func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) {}
121
-func SampleSkewness(input Float64Data) (float64, error) {}
122
-func SampleVariance(input Float64Data) (svar float64, err error) {}
123
-func Skewness(input Float64Data) (float64, error) {}
124
-func Sigmoid(input Float64Data) ([]float64, error) {}
125
-func SoftMax(input Float64Data) ([]float64, error) {}
126
-func StableSample(input Float64Data, takenum int) ([]float64, error) {}
127
-func StandardDeviation(input Float64Data) (sdev float64, err error) {}
128
-func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) {}
129
-func StandardDeviationSample(input Float64Data) (sdev float64, err error) {}
130
-func StdDevP(input Float64Data) (sdev float64, err error) {}
131
-func StdDevS(input Float64Data) (sdev float64, err error) {}
132
-func Sum(input Float64Data) (sum float64, err error) {}
133
-func Trimean(input Float64Data) (float64, error) {}
134
-func VarP(input Float64Data) (sdev float64, err error) {}
135
-func VarS(input Float64Data) (sdev float64, err error) {}
136
-func Variance(input Float64Data) (sdev float64, err error) {}
137
-func ProbGeom(a int, b int, p float64) (prob float64, err error) {}
138
-func ExpGeom(p float64) (exp float64, err error) {}
139
-func VarGeom(p float64) (exp float64, err error) {}
140
-
141
-type Coordinate struct {
142
-    X, Y float64
143
-}
144
-
145
-type Series []Coordinate
146
-
147
-func ExponentialRegression(s Series) (regressions Series, err error) {}
148
-func LinearRegression(s Series) (regressions Series, err error) {}
149
-func LogarithmicRegression(s Series) (regressions Series, err error) {}
150
-
151
-type Outliers struct {
152
-    Mild    Float64Data
153
-    Extreme Float64Data
154
-}
155
-
156
-type Quartiles struct {
157
-    Q1 float64
158
-    Q2 float64
159
-    Q3 float64
160
-}
161
-
162
-func Quartile(input Float64Data) (Quartiles, error) {}
163
-func QuartileOutliers(input Float64Data) (Outliers, error) {}
164
-```
165
-
166
-## Contributing
167
-
168
-Pull request are always welcome no matter how big or small. I've included a [Makefile](https://github.com/montanaflynn/stats/blob/master/Makefile) that has a lot of helper targets for common actions such as linting, testing, code coverage reporting and more.
169
-
170
-1. Fork the repo and clone your fork
171
-2. Create new branch (`git checkout -b some-thing`)
172
-3. Make the desired changes
173
-4. Ensure tests pass (`go test -cover` or `make test`)
174
-5. Run lint and fix problems (`go vet .` or `make lint`)
175
-6. Commit changes (`git commit -am 'Did something'`)
176
-7. Push branch (`git push origin some-thing`)
177
-8. Submit pull request
178
-
179
-To make things as seamless as possible please also consider the following steps:
180
-
181
-- Update `examples/main.go` with a simple example of the new feature
182
-- Update `README.md` documentation section with any new exported API
183
-- Keep 100% code coverage (you can check with `make coverage`)
184
-- Squash commits into single units of work with `git rebase -i new-feature`
185
-
186
-## Releasing
187
-
188
-Releases are automated with [GoReleaser](https://goreleaser.com/) via GitHub Actions. To create a new release, push a version tag:
189
-
190
-```
191
-git tag v0.x.x
192
-git push origin v0.x.x
193
-```
194
-
195
-## MIT License
196
-
197
-Copyright (c) 2014-2026 Montana Flynn (https://montanaflynn.com)
198
-
199
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
200
-
201
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
202
-
203
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORpublicS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
204
-
205
-[action-url]: https://github.com/montanaflynn/stats/actions
206
-[action-svg]: https://img.shields.io/github/actions/workflow/status/montanaflynn/stats/go.yml
207
-
208
-[codecov-url]: https://app.codecov.io/gh/montanaflynn/stats
209
-[codecov-svg]: https://img.shields.io/codecov/c/github/montanaflynn/stats?token=wnw8dActnH
210
-
211
-[goreport-url]: https://goreportcard.com/report/github.com/montanaflynn/stats
212
-[goreport-svg]: https://goreportcard.com/badge/github.com/montanaflynn/stats
213
-
214
-[godoc-url]: https://godoc.org/github.com/montanaflynn/stats
215
-[godoc-svg]: https://godoc.org/github.com/montanaflynn/stats?status.svg
216
-
217
-[pkggodev-url]: https://pkg.go.dev/github.com/montanaflynn/stats
218
-[pkggodev-svg]: https://gistcdn.githack.com/montanaflynn/b02f1d78d8c0de8435895d7e7cd0d473/raw/17f2a5a69f1323ecd42c00e0683655da96d9ecc8/badge.svg
219
-
220
-[license-url]: https://github.com/montanaflynn/stats/blob/master/LICENSE
221
-[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
222 1
deleted file mode 100644
... ...
@@ -1,60 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"math"
5
-)
6
-
7
-// Correlation describes the degree of relationship between two sets of data
8
-func Correlation(data1, data2 Float64Data) (float64, error) {
9
-
10
-	l1 := data1.Len()
11
-	l2 := data2.Len()
12
-
13
-	if l1 == 0 || l2 == 0 {
14
-		return math.NaN(), EmptyInputErr
15
-	}
16
-
17
-	if l1 != l2 {
18
-		return math.NaN(), SizeErr
19
-	}
20
-
21
-	sdev1, _ := StandardDeviationPopulation(data1)
22
-	sdev2, _ := StandardDeviationPopulation(data2)
23
-
24
-	if sdev1 == 0 || sdev2 == 0 {
25
-		return 0, nil
26
-	}
27
-
28
-	covp, _ := CovariancePopulation(data1, data2)
29
-	return covp / (sdev1 * sdev2), nil
30
-}
31
-
32
-// Pearson calculates the Pearson product-moment correlation coefficient between two variables
33
-func Pearson(data1, data2 Float64Data) (float64, error) {
34
-	return Correlation(data1, data2)
35
-}
36
-
37
-// AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay
38
-func AutoCorrelation(data Float64Data, lags int) (float64, error) {
39
-	if len(data) < 1 {
40
-		return 0, EmptyInputErr
41
-	}
42
-
43
-	mean, _ := Mean(data)
44
-
45
-	var result, q float64
46
-
47
-	for i := 0; i < lags; i++ {
48
-		v := (data[0] - mean) * (data[0] - mean)
49
-		for i := 1; i < len(data); i++ {
50
-			delta0 := data[i-1] - mean
51
-			delta1 := data[i] - mean
52
-			q += (delta0*delta1 - q) / float64(i+1)
53
-			v += (delta1*delta1 - v) / float64(i+1)
54
-		}
55
-
56
-		result = q / v
57
-	}
58
-
59
-	return result, nil
60
-}
61 1
deleted file mode 100644
... ...
@@ -1,21 +0,0 @@
1
-package stats
2
-
3
-// CumulativeSum calculates the cumulative sum of the input slice
4
-func CumulativeSum(input Float64Data) ([]float64, error) {
5
-
6
-	if input.Len() == 0 {
7
-		return Float64Data{}, EmptyInput
8
-	}
9
-
10
-	cumSum := make([]float64, input.Len())
11
-
12
-	for i, val := range input {
13
-		if i == 0 {
14
-			cumSum[i] = val
15
-		} else {
16
-			cumSum[i] = cumSum[i-1] + val
17
-		}
18
-	}
19
-
20
-	return cumSum, nil
21
-}
22 1
deleted file mode 100644
... ...
@@ -1,169 +0,0 @@
1
-package stats
2
-
3
-// Float64Data is a named type for []float64 with helper methods
4
-type Float64Data []float64
5
-
6
-// Get item in slice
7
-func (f Float64Data) Get(i int) float64 { return f[i] }
8
-
9
-// Len returns length of slice
10
-func (f Float64Data) Len() int { return len(f) }
11
-
12
-// Less returns if one number is less than another
13
-func (f Float64Data) Less(i, j int) bool { return f[i] < f[j] }
14
-
15
-// Swap switches out two numbers in slice
16
-func (f Float64Data) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
17
-
18
-// Min returns the minimum number in the data
19
-func (f Float64Data) Min() (float64, error) { return Min(f) }
20
-
21
-// Max returns the maximum number in the data
22
-func (f Float64Data) Max() (float64, error) { return Max(f) }
23
-
24
-// Sum returns the total of all the numbers in the data
25
-func (f Float64Data) Sum() (float64, error) { return Sum(f) }
26
-
27
-// CumulativeSum returns the cumulative sum of the data
28
-func (f Float64Data) CumulativeSum() ([]float64, error) { return CumulativeSum(f) }
29
-
30
-// Mean returns the mean of the data
31
-func (f Float64Data) Mean() (float64, error) { return Mean(f) }
32
-
33
-// Median returns the median of the data
34
-func (f Float64Data) Median() (float64, error) { return Median(f) }
35
-
36
-// Mode returns the mode of the data
37
-func (f Float64Data) Mode() ([]float64, error) { return Mode(f) }
38
-
39
-// GeometricMean returns the median of the data
40
-func (f Float64Data) GeometricMean() (float64, error) { return GeometricMean(f) }
41
-
42
-// HarmonicMean returns the mode of the data
43
-func (f Float64Data) HarmonicMean() (float64, error) { return HarmonicMean(f) }
44
-
45
-// MedianAbsoluteDeviation the median of the absolute deviations from the dataset median
46
-func (f Float64Data) MedianAbsoluteDeviation() (float64, error) {
47
-	return MedianAbsoluteDeviation(f)
48
-}
49
-
50
-// MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median
51
-func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error) {
52
-	return MedianAbsoluteDeviationPopulation(f)
53
-}
54
-
55
-// StandardDeviation the amount of variation in the dataset
56
-func (f Float64Data) StandardDeviation() (float64, error) {
57
-	return StandardDeviation(f)
58
-}
59
-
60
-// StandardDeviationPopulation finds the amount of variation from the population
61
-func (f Float64Data) StandardDeviationPopulation() (float64, error) {
62
-	return StandardDeviationPopulation(f)
63
-}
64
-
65
-// StandardDeviationSample finds the amount of variation from a sample
66
-func (f Float64Data) StandardDeviationSample() (float64, error) {
67
-	return StandardDeviationSample(f)
68
-}
69
-
70
-// QuartileOutliers finds the mild and extreme outliers
71
-func (f Float64Data) QuartileOutliers() (Outliers, error) {
72
-	return QuartileOutliers(f)
73
-}
74
-
75
-// Percentile finds the relative standing in a slice of floats
76
-func (f Float64Data) Percentile(p float64) (float64, error) {
77
-	return Percentile(f, p)
78
-}
79
-
80
-// PercentileNearestRank finds the relative standing using the Nearest Rank method
81
-func (f Float64Data) PercentileNearestRank(p float64) (float64, error) {
82
-	return PercentileNearestRank(f, p)
83
-}
84
-
85
-// Correlation describes the degree of relationship between two sets of data
86
-func (f Float64Data) Correlation(d Float64Data) (float64, error) {
87
-	return Correlation(f, d)
88
-}
89
-
90
-// AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay
91
-func (f Float64Data) AutoCorrelation(lags int) (float64, error) {
92
-	return AutoCorrelation(f, lags)
93
-}
94
-
95
-// Pearson calculates the Pearson product-moment correlation coefficient between two variables.
96
-func (f Float64Data) Pearson(d Float64Data) (float64, error) {
97
-	return Pearson(f, d)
98
-}
99
-
100
-// Quartile returns the three quartile points from a slice of data
101
-func (f Float64Data) Quartile(d Float64Data) (Quartiles, error) {
102
-	return Quartile(d)
103
-}
104
-
105
-// InterQuartileRange finds the range between Q1 and Q3
106
-func (f Float64Data) InterQuartileRange() (float64, error) {
107
-	return InterQuartileRange(f)
108
-}
109
-
110
-// Midhinge finds the average of the first and third quartiles
111
-func (f Float64Data) Midhinge(d Float64Data) (float64, error) {
112
-	return Midhinge(d)
113
-}
114
-
115
-// Trimean finds the average of the median and the midhinge
116
-func (f Float64Data) Trimean(d Float64Data) (float64, error) {
117
-	return Trimean(d)
118
-}
119
-
120
-// Sample returns sample from input with replacement or without
121
-func (f Float64Data) Sample(n int, r bool) ([]float64, error) {
122
-	return Sample(f, n, r)
123
-}
124
-
125
-// Variance the amount of variation in the dataset
126
-func (f Float64Data) Variance() (float64, error) {
127
-	return Variance(f)
128
-}
129
-
130
-// PopulationVariance finds the amount of variance within a population
131
-func (f Float64Data) PopulationVariance() (float64, error) {
132
-	return PopulationVariance(f)
133
-}
134
-
135
-// SampleVariance finds the amount of variance within a sample
136
-func (f Float64Data) SampleVariance() (float64, error) {
137
-	return SampleVariance(f)
138
-}
139
-
140
-// Covariance is a measure of how much two sets of data change
141
-func (f Float64Data) Covariance(d Float64Data) (float64, error) {
142
-	return Covariance(f, d)
143
-}
144
-
145
-// CovariancePopulation computes covariance for entire population between two variables
146
-func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error) {
147
-	return CovariancePopulation(f, d)
148
-}
149
-
150
-// Sigmoid returns the input values along the sigmoid or s-shaped curve
151
-func (f Float64Data) Sigmoid() ([]float64, error) {
152
-	return Sigmoid(f)
153
-}
154
-
155
-// SoftMax returns the input values in the range of 0 to 1
156
-// with sum of all the probabilities being equal to one.
157
-func (f Float64Data) SoftMax() ([]float64, error) {
158
-	return SoftMax(f)
159
-}
160
-
161
-// Entropy provides calculation of the entropy
162
-func (f Float64Data) Entropy() (float64, error) {
163
-	return Entropy(f)
164
-}
165
-
166
-// Quartiles returns the three quartile points from instance of Float64Data
167
-func (f Float64Data) Quartiles() (Quartiles, error) {
168
-	return Quartile(f)
169
-}
170 1
deleted file mode 100644
... ...
@@ -1,81 +0,0 @@
1
-package stats
2
-
3
-import "fmt"
4
-
5
-// Holds information about the dataset provided to Describe
6
-type Description struct {
7
-	Count                  int
8
-	Mean                   float64
9
-	Std                    float64
10
-	Max                    float64
11
-	Min                    float64
12
-	DescriptionPercentiles []descriptionPercentile
13
-	AllowedNaN             bool
14
-}
15
-
16
-// Specifies percentiles to be computed
17
-type descriptionPercentile struct {
18
-	Percentile float64
19
-	Value      float64
20
-}
21
-
22
-// Describe generates descriptive statistics about a provided dataset, similar to python's pandas.describe()
23
-func Describe(input Float64Data, allowNaN bool, percentiles *[]float64) (*Description, error) {
24
-	return DescribePercentileFunc(input, allowNaN, percentiles, Percentile)
25
-}
26
-
27
-// Describe generates descriptive statistics about a provided dataset, similar to python's pandas.describe()
28
-// Takes in a function to use for percentile calculation
29
-func DescribePercentileFunc(input Float64Data, allowNaN bool, percentiles *[]float64, percentileFunc func(Float64Data, float64) (float64, error)) (*Description, error) {
30
-	var description Description
31
-	description.AllowedNaN = allowNaN
32
-	description.Count = input.Len()
33
-
34
-	if description.Count == 0 && !allowNaN {
35
-		return &description, ErrEmptyInput
36
-	}
37
-
38
-	// Disregard error, since it cannot be thrown if Count is > 0 and allowNaN is false, else NaN is accepted
39
-	description.Std, _ = StandardDeviation(input)
40
-	description.Max, _ = Max(input)
41
-	description.Min, _ = Min(input)
42
-	description.Mean, _ = Mean(input)
43
-
44
-	if percentiles != nil {
45
-		for _, percentile := range *percentiles {
46
-			if value, err := percentileFunc(input, percentile); err == nil || allowNaN {
47
-				description.DescriptionPercentiles = append(description.DescriptionPercentiles, descriptionPercentile{Percentile: percentile, Value: value})
48
-			}
49
-		}
50
-	}
51
-
52
-	return &description, nil
53
-}
54
-
55
-/*
56
-Represents the Description instance in a string format with specified number of decimals
57
-
58
-	count   3
59
-	mean    2.00
60
-	std     0.82
61
-	max     3.00
62
-	min     1.00
63
-	25.00%  NaN
64
-	50.00%  1.50
65
-	75.00%  2.50
66
-	NaN OK  true
67
-*/
68
-func (d *Description) String(decimals int) string {
69
-	var str string
70
-
71
-	str += fmt.Sprintf("count\t%d\n", d.Count)
72
-	str += fmt.Sprintf("mean\t%.*f\n", decimals, d.Mean)
73
-	str += fmt.Sprintf("std\t%.*f\n", decimals, d.Std)
74
-	str += fmt.Sprintf("max\t%.*f\n", decimals, d.Max)
75
-	str += fmt.Sprintf("min\t%.*f\n", decimals, d.Min)
76
-	for _, percentile := range d.DescriptionPercentiles {
77
-		str += fmt.Sprintf("%.2f%%\t%.*f\n", percentile.Percentile, decimals, percentile.Value)
78
-	}
79
-	str += fmt.Sprintf("NaN OK\t%t", d.AllowedNaN)
80
-	return str
81
-}
82 1
deleted file mode 100644
... ...
@@ -1,57 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// MedianAbsoluteDeviation finds the median of the absolute deviations from the dataset median
6
-func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error) {
7
-	return MedianAbsoluteDeviationPopulation(input)
8
-}
9
-
10
-// MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median
11
-func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) {
12
-	if input.Len() == 0 {
13
-		return math.NaN(), EmptyInputErr
14
-	}
15
-
16
-	i := copyslice(input)
17
-	m, _ := Median(i)
18
-
19
-	for key, value := range i {
20
-		i[key] = math.Abs(value - m)
21
-	}
22
-
23
-	return Median(i)
24
-}
25
-
26
-// StandardDeviation the amount of variation in the dataset
27
-func StandardDeviation(input Float64Data) (sdev float64, err error) {
28
-	return StandardDeviationPopulation(input)
29
-}
30
-
31
-// StandardDeviationPopulation finds the amount of variation from the population
32
-func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) {
33
-
34
-	if input.Len() == 0 {
35
-		return math.NaN(), EmptyInputErr
36
-	}
37
-
38
-	// Get the population variance
39
-	vp, _ := PopulationVariance(input)
40
-
41
-	// Return the population standard deviation
42
-	return math.Sqrt(vp), nil
43
-}
44
-
45
-// StandardDeviationSample finds the amount of variation from a sample
46
-func StandardDeviationSample(input Float64Data) (sdev float64, err error) {
47
-
48
-	if input.Len() == 0 {
49
-		return math.NaN(), EmptyInputErr
50
-	}
51
-
52
-	// Get the sample variance
53
-	vs, _ := SampleVariance(input)
54
-
55
-	// Return the sample standard deviation
56
-	return math.Sqrt(vs), nil
57
-}
58 1
deleted file mode 100644
... ...
@@ -1,91 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"math"
5
-)
6
-
7
-// Validate data for distance calculation
8
-func validateData(dataPointX, dataPointY Float64Data) error {
9
-	if len(dataPointX) == 0 || len(dataPointY) == 0 {
10
-		return EmptyInputErr
11
-	}
12
-
13
-	if len(dataPointX) != len(dataPointY) {
14
-		return SizeErr
15
-	}
16
-	return nil
17
-}
18
-
19
-// ChebyshevDistance computes the Chebyshev distance between two data sets
20
-func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {
21
-	err = validateData(dataPointX, dataPointY)
22
-	if err != nil {
23
-		return math.NaN(), err
24
-	}
25
-	var tempDistance float64
26
-	for i := 0; i < len(dataPointY); i++ {
27
-		tempDistance = math.Abs(dataPointX[i] - dataPointY[i])
28
-		if distance < tempDistance {
29
-			distance = tempDistance
30
-		}
31
-	}
32
-	return distance, nil
33
-}
34
-
35
-// EuclideanDistance computes the Euclidean distance between two data sets
36
-func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {
37
-
38
-	err = validateData(dataPointX, dataPointY)
39
-	if err != nil {
40
-		return math.NaN(), err
41
-	}
42
-	distance = 0
43
-	for i := 0; i < len(dataPointX); i++ {
44
-		distance = distance + ((dataPointX[i] - dataPointY[i]) * (dataPointX[i] - dataPointY[i]))
45
-	}
46
-	return math.Sqrt(distance), nil
47
-}
48
-
49
-// ManhattanDistance computes the Manhattan distance between two data sets
50
-func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {
51
-	err = validateData(dataPointX, dataPointY)
52
-	if err != nil {
53
-		return math.NaN(), err
54
-	}
55
-	distance = 0
56
-	for i := 0; i < len(dataPointX); i++ {
57
-		distance = distance + math.Abs(dataPointX[i]-dataPointY[i])
58
-	}
59
-	return distance, nil
60
-}
61
-
62
-// MinkowskiDistance computes the Minkowski distance between two data sets
63
-//
64
-// Arguments:
65
-//
66
-//	dataPointX: First set of data points
67
-//	dataPointY: Second set of data points. Length of both data
68
-//	            sets must be equal.
69
-//	lambda:     aka p or city blocks; With lambda = 1
70
-//	            returned distance is manhattan distance and
71
-//	            lambda = 2; it is euclidean distance. Lambda
72
-//	            reaching to infinite - distance would be chebysev
73
-//	            distance.
74
-//
75
-// Return:
76
-//
77
-//	Distance or error
78
-func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error) {
79
-	err = validateData(dataPointX, dataPointY)
80
-	if err != nil {
81
-		return math.NaN(), err
82
-	}
83
-	for i := 0; i < len(dataPointY); i++ {
84
-		distance = distance + math.Pow(math.Abs(dataPointX[i]-dataPointY[i]), lambda)
85
-	}
86
-	distance = math.Pow(distance, 1/lambda)
87
-	if math.IsInf(distance, 1) {
88
-		return math.NaN(), InfValue
89
-	}
90
-	return distance, nil
91
-}
92 1
deleted file mode 100644
... ...
@@ -1,23 +0,0 @@
1
-/*
2
-Package stats is a well tested and comprehensive
3
-statistics library package with no dependencies.
4
-
5
-Example Usage:
6
-
7
-	// start with some source data to use
8
-	data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8}
9
-
10
-	// you could also use different types like this
11
-	// data := stats.LoadRawData([]int{1, 2, 3, 4, 5})
12
-	// data := stats.LoadRawData([]interface{}{1.1, "2", 3})
13
-	// etc...
14
-
15
-	median, _ := stats.Median(data)
16
-	fmt.Println(median) // 3.65
17
-
18
-	roundedMedian, _ := stats.Round(median, 0)
19
-	fmt.Println(roundedMedian) // 4
20
-
21
-MIT License Copyright (c) 2014-2026 Montana Flynn (https://montanaflynn.com)
22
-*/
23
-package stats
24 1
deleted file mode 100644
... ...
@@ -1,31 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Entropy provides calculation of the entropy
6
-func Entropy(input Float64Data) (float64, error) {
7
-	input, err := normalize(input)
8
-	if err != nil {
9
-		return math.NaN(), err
10
-	}
11
-	var result float64
12
-	for i := 0; i < input.Len(); i++ {
13
-		v := input.Get(i)
14
-		if v == 0 {
15
-			continue
16
-		}
17
-		result += (v * math.Log(v))
18
-	}
19
-	return -result, nil
20
-}
21
-
22
-func normalize(input Float64Data) (Float64Data, error) {
23
-	sum, err := input.Sum()
24
-	if err != nil {
25
-		return Float64Data{}, err
26
-	}
27
-	for i := 0; i < input.Len(); i++ {
28
-		input[i] = input[i] / sum
29
-	}
30
-	return input, nil
31
-}
32 1
deleted file mode 100644
... ...
@@ -1,35 +0,0 @@
1
-package stats
2
-
3
-type statsError struct {
4
-	err string
5
-}
6
-
7
-func (s statsError) Error() string {
8
-	return s.err
9
-}
10
-
11
-func (s statsError) String() string {
12
-	return s.err
13
-}
14
-
15
-// These are the package-wide error values.
16
-// All error identification should use these values.
17
-// https://github.com/golang/go/wiki/Errors#naming
18
-var (
19
-	// ErrEmptyInput Input must not be empty
20
-	ErrEmptyInput = statsError{"Input must not be empty."}
21
-	// ErrNaN Not a number
22
-	ErrNaN = statsError{"Not a number."}
23
-	// ErrNegative Must not contain negative values
24
-	ErrNegative = statsError{"Must not contain negative values."}
25
-	// ErrZero Must not contain zero values
26
-	ErrZero = statsError{"Must not contain zero values."}
27
-	// ErrBounds Input is outside of range
28
-	ErrBounds = statsError{"Input is outside of range."}
29
-	// ErrSize Must be the same length
30
-	ErrSize = statsError{"Must be the same length."}
31
-	// ErrInfValue Value is infinite
32
-	ErrInfValue = statsError{"Value is infinite."}
33
-	// ErrYCoord Y Value must be greater than zero
34
-	ErrYCoord = statsError{"Y Value must be greater than zero."}
35
-)
36 1
deleted file mode 100644
... ...
@@ -1,42 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"math"
5
-)
6
-
7
-// ProbGeom generates the probability for a geometric random variable
8
-// with parameter p to achieve success in the interval of [a, b] trials
9
-// See https://en.wikipedia.org/wiki/Geometric_distribution for more information
10
-func ProbGeom(a int, b int, p float64) (prob float64, err error) {
11
-	if (a > b) || (a < 1) {
12
-		return math.NaN(), ErrBounds
13
-	}
14
-
15
-	prob = 0
16
-	q := 1 - p // probability of failure
17
-
18
-	for k := a + 1; k <= b; k++ {
19
-		prob = prob + p*math.Pow(q, float64(k-1))
20
-	}
21
-
22
-	return prob, nil
23
-}
24
-
25
-// ProbGeom generates the expectation or average number of trials
26
-// for a geometric random variable with parameter p
27
-func ExpGeom(p float64) (exp float64, err error) {
28
-	if (p > 1) || (p < 0) {
29
-		return math.NaN(), ErrNegative
30
-	}
31
-
32
-	return 1 / p, nil
33
-}
34
-
35
-// ProbGeom generates the variance for number for a
36
-// geometric random variable with parameter p
37
-func VarGeom(p float64) (exp float64, err error) {
38
-	if (p > 1) || (p < 0) {
39
-		return math.NaN(), ErrNegative
40
-	}
41
-	return (1 - p) / math.Pow(p, 2), nil
42
-}
43 1
deleted file mode 100644
... ...
@@ -1,49 +0,0 @@
1
-package stats
2
-
3
-// VarP is a shortcut to PopulationVariance
4
-func VarP(input Float64Data) (sdev float64, err error) {
5
-	return PopulationVariance(input)
6
-}
7
-
8
-// VarS is a shortcut to SampleVariance
9
-func VarS(input Float64Data) (sdev float64, err error) {
10
-	return SampleVariance(input)
11
-}
12
-
13
-// StdDevP is a shortcut to StandardDeviationPopulation
14
-func StdDevP(input Float64Data) (sdev float64, err error) {
15
-	return StandardDeviationPopulation(input)
16
-}
17
-
18
-// StdDevS is a shortcut to StandardDeviationSample
19
-func StdDevS(input Float64Data) (sdev float64, err error) {
20
-	return StandardDeviationSample(input)
21
-}
22
-
23
-// LinReg is a shortcut to LinearRegression
24
-func LinReg(s []Coordinate) (regressions []Coordinate, err error) {
25
-	return LinearRegression(s)
26
-}
27
-
28
-// ExpReg is a shortcut to ExponentialRegression
29
-func ExpReg(s []Coordinate) (regressions []Coordinate, err error) {
30
-	return ExponentialRegression(s)
31
-}
32
-
33
-// LogReg is a shortcut to LogarithmicRegression
34
-func LogReg(s []Coordinate) (regressions []Coordinate, err error) {
35
-	return LogarithmicRegression(s)
36
-}
37
-
38
-// Legacy error names that didn't start with Err
39
-var (
40
-	EmptyInputErr = ErrEmptyInput
41
-	NaNErr        = ErrNaN
42
-	NegativeErr   = ErrNegative
43
-	ZeroErr       = ErrZero
44
-	BoundsErr     = ErrBounds
45
-	SizeErr       = ErrSize
46
-	InfValue      = ErrInfValue
47
-	YCoordErr     = ErrYCoord
48
-	EmptyInput    = ErrEmptyInput
49
-)
50 1
deleted file mode 100644
... ...
@@ -1,199 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"bufio"
5
-	"io"
6
-	"strconv"
7
-	"strings"
8
-	"time"
9
-)
10
-
11
-// LoadRawData parses and converts a slice of mixed data types to floats
12
-func LoadRawData(raw interface{}) (f Float64Data) {
13
-	var r []interface{}
14
-	var s Float64Data
15
-
16
-	switch t := raw.(type) {
17
-	case []interface{}:
18
-		r = t
19
-	case []uint:
20
-		for _, v := range t {
21
-			s = append(s, float64(v))
22
-		}
23
-		return s
24
-	case []uint8:
25
-		for _, v := range t {
26
-			s = append(s, float64(v))
27
-		}
28
-		return s
29
-	case []uint16:
30
-		for _, v := range t {
31
-			s = append(s, float64(v))
32
-		}
33
-		return s
34
-	case []uint32:
35
-		for _, v := range t {
36
-			s = append(s, float64(v))
37
-		}
38
-		return s
39
-	case []uint64:
40
-		for _, v := range t {
41
-			s = append(s, float64(v))
42
-		}
43
-		return s
44
-	case []bool:
45
-		for _, v := range t {
46
-			if v {
47
-				s = append(s, 1.0)
48
-			} else {
49
-				s = append(s, 0.0)
50
-			}
51
-		}
52
-		return s
53
-	case []float64:
54
-		return Float64Data(t)
55
-	case []int:
56
-		for _, v := range t {
57
-			s = append(s, float64(v))
58
-		}
59
-		return s
60
-	case []int8:
61
-		for _, v := range t {
62
-			s = append(s, float64(v))
63
-		}
64
-		return s
65
-	case []int16:
66
-		for _, v := range t {
67
-			s = append(s, float64(v))
68
-		}
69
-		return s
70
-	case []int32:
71
-		for _, v := range t {
72
-			s = append(s, float64(v))
73
-		}
74
-		return s
75
-	case []int64:
76
-		for _, v := range t {
77
-			s = append(s, float64(v))
78
-		}
79
-		return s
80
-	case []string:
81
-		for _, v := range t {
82
-			r = append(r, v)
83
-		}
84
-	case []time.Duration:
85
-		for _, v := range t {
86
-			r = append(r, v)
87
-		}
88
-	case map[int]int:
89
-		for i := 0; i < len(t); i++ {
90
-			s = append(s, float64(t[i]))
91
-		}
92
-		return s
93
-	case map[int]int8:
94
-		for i := 0; i < len(t); i++ {
95
-			s = append(s, float64(t[i]))
96
-		}
97
-		return s
98
-	case map[int]int16:
99
-		for i := 0; i < len(t); i++ {
100
-			s = append(s, float64(t[i]))
101
-		}
102
-		return s
103
-	case map[int]int32:
104
-		for i := 0; i < len(t); i++ {
105
-			s = append(s, float64(t[i]))
106
-		}
107
-		return s
108
-	case map[int]int64:
109
-		for i := 0; i < len(t); i++ {
110
-			s = append(s, float64(t[i]))
111
-		}
112
-		return s
113
-	case map[int]string:
114
-		for i := 0; i < len(t); i++ {
115
-			r = append(r, t[i])
116
-		}
117
-	case map[int]uint:
118
-		for i := 0; i < len(t); i++ {
119
-			s = append(s, float64(t[i]))
120
-		}
121
-		return s
122
-	case map[int]uint8:
123
-		for i := 0; i < len(t); i++ {
124
-			s = append(s, float64(t[i]))
125
-		}
126
-		return s
127
-	case map[int]uint16:
128
-		for i := 0; i < len(t); i++ {
129
-			s = append(s, float64(t[i]))
130
-		}
131
-		return s
132
-	case map[int]uint32:
133
-		for i := 0; i < len(t); i++ {
134
-			s = append(s, float64(t[i]))
135
-		}
136
-		return s
137
-	case map[int]uint64:
138
-		for i := 0; i < len(t); i++ {
139
-			s = append(s, float64(t[i]))
140
-		}
141
-		return s
142
-	case map[int]bool:
143
-		for i := 0; i < len(t); i++ {
144
-			if t[i] {
145
-				s = append(s, 1.0)
146
-			} else {
147
-				s = append(s, 0.0)
148
-			}
149
-		}
150
-		return s
151
-	case map[int]float64:
152
-		for i := 0; i < len(t); i++ {
153
-			s = append(s, t[i])
154
-		}
155
-		return s
156
-	case map[int]time.Duration:
157
-		for i := 0; i < len(t); i++ {
158
-			r = append(r, t[i])
159
-		}
160
-	case string:
161
-		for _, v := range strings.Fields(t) {
162
-			r = append(r, v)
163
-		}
164
-	case io.Reader:
165
-		scanner := bufio.NewScanner(t)
166
-		for scanner.Scan() {
167
-			l := scanner.Text()
168
-			for _, v := range strings.Fields(l) {
169
-				r = append(r, v)
170
-			}
171
-		}
172
-	}
173
-
174
-	for _, v := range r {
175
-		switch t := v.(type) {
176
-		case int:
177
-			a := float64(t)
178
-			f = append(f, a)
179
-		case uint:
180
-			f = append(f, float64(t))
181
-		case float64:
182
-			f = append(f, t)
183
-		case string:
184
-			fl, err := strconv.ParseFloat(t, 64)
185
-			if err == nil {
186
-				f = append(f, fl)
187
-			}
188
-		case bool:
189
-			if t {
190
-				f = append(f, 1.0)
191
-			} else {
192
-				f = append(f, 0.0)
193
-			}
194
-		case time.Duration:
195
-			f = append(f, float64(t))
196
-		}
197
-	}
198
-	return f
199
-}
200 1
deleted file mode 100644
... ...
@@ -1,26 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"math"
5
-)
6
-
7
-// Max finds the highest number in a slice
8
-func Max(input Float64Data) (max float64, err error) {
9
-
10
-	// Return an error if there are no numbers
11
-	if input.Len() == 0 {
12
-		return math.NaN(), EmptyInputErr
13
-	}
14
-
15
-	// Get the first value as the starting point
16
-	max = input.Get(0)
17
-
18
-	// Loop and replace higher values
19
-	for i := 1; i < input.Len(); i++ {
20
-		if input.Get(i) > max {
21
-			max = input.Get(i)
22
-		}
23
-	}
24
-
25
-	return max, nil
26
-}
27 1
deleted file mode 100644
... ...
@@ -1,60 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Mean gets the average of a slice of numbers
6
-func Mean(input Float64Data) (float64, error) {
7
-
8
-	if input.Len() == 0 {
9
-		return math.NaN(), EmptyInputErr
10
-	}
11
-
12
-	sum, _ := input.Sum()
13
-
14
-	return sum / float64(input.Len()), nil
15
-}
16
-
17
-// GeometricMean gets the geometric mean for a slice of numbers
18
-func GeometricMean(input Float64Data) (float64, error) {
19
-
20
-	l := input.Len()
21
-	if l == 0 {
22
-		return math.NaN(), EmptyInputErr
23
-	}
24
-
25
-	// Get the product of all the numbers
26
-	var p float64
27
-	for _, n := range input {
28
-		if p == 0 {
29
-			p = n
30
-		} else {
31
-			p *= n
32
-		}
33
-	}
34
-
35
-	// Calculate the geometric mean
36
-	return math.Pow(p, 1/float64(l)), nil
37
-}
38
-
39
-// HarmonicMean gets the harmonic mean for a slice of numbers
40
-func HarmonicMean(input Float64Data) (float64, error) {
41
-
42
-	l := input.Len()
43
-	if l == 0 {
44
-		return math.NaN(), EmptyInputErr
45
-	}
46
-
47
-	// Get the sum of all the numbers reciprocals and return an
48
-	// error for values that cannot be included in harmonic mean
49
-	var p float64
50
-	for _, n := range input {
51
-		if n < 0 {
52
-			return math.NaN(), NegativeErr
53
-		} else if n == 0 {
54
-			return math.NaN(), ZeroErr
55
-		}
56
-		p += (1 / n)
57
-	}
58
-
59
-	return float64(l) / p, nil
60
-}
61 1
deleted file mode 100644
... ...
@@ -1,25 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Median gets the median number in a slice of numbers
6
-func Median(input Float64Data) (median float64, err error) {
7
-
8
-	// Start by sorting a copy of the slice
9
-	c := sortedCopy(input)
10
-
11
-	// No math is needed if there are no numbers
12
-	// For even numbers we add the two middle numbers
13
-	// and divide by two using the mean function above
14
-	// For odd numbers we just use the middle number
15
-	l := len(c)
16
-	if l == 0 {
17
-		return math.NaN(), EmptyInputErr
18
-	} else if l%2 == 0 {
19
-		median, _ = Mean(c[l/2-1 : l/2+1])
20
-	} else {
21
-		median = c[l/2]
22
-	}
23
-
24
-	return median, nil
25
-}
26 1
deleted file mode 100644
... ...
@@ -1,26 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Min finds the lowest number in a set of data
6
-func Min(input Float64Data) (min float64, err error) {
7
-
8
-	// Get the count of numbers in the slice
9
-	l := input.Len()
10
-
11
-	// Return an error if there are no numbers
12
-	if l == 0 {
13
-		return math.NaN(), EmptyInputErr
14
-	}
15
-
16
-	// Get the first value as the starting point
17
-	min = input.Get(0)
18
-
19
-	// Iterate until done checking for a lower value
20
-	for i := 1; i < l; i++ {
21
-		if input.Get(i) < min {
22
-			min = input.Get(i)
23
-		}
24
-	}
25
-	return min, nil
26
-}
27 1
deleted file mode 100644
... ...
@@ -1,47 +0,0 @@
1
-package stats
2
-
3
-// Mode gets the mode [most frequent value(s)] of a slice of float64s
4
-func Mode(input Float64Data) (mode []float64, err error) {
5
-	// Return the input if there's only one number
6
-	l := input.Len()
7
-	if l == 1 {
8
-		return input, nil
9
-	} else if l == 0 {
10
-		return nil, EmptyInputErr
11
-	}
12
-
13
-	c := sortedCopyDif(input)
14
-	// Traverse sorted array,
15
-	// tracking the longest repeating sequence
16
-	mode = make([]float64, 5)
17
-	cnt, maxCnt := 1, 1
18
-	for i := 1; i < l; i++ {
19
-		switch {
20
-		case c[i] == c[i-1]:
21
-			cnt++
22
-		case cnt == maxCnt && maxCnt != 1:
23
-			mode = append(mode, c[i-1])
24
-			cnt = 1
25
-		case cnt > maxCnt:
26
-			mode = append(mode[:0], c[i-1])
27
-			maxCnt, cnt = cnt, 1
28
-		default:
29
-			cnt = 1
30
-		}
31
-	}
32
-	switch {
33
-	case cnt == maxCnt:
34
-		mode = append(mode, c[l-1])
35
-	case cnt > maxCnt:
36
-		mode = append(mode[:0], c[l-1])
37
-		maxCnt = cnt
38
-	}
39
-
40
-	// Since length must be greater than 1,
41
-	// check for slices of distinct values
42
-	if maxCnt == 1 || len(mode)*maxCnt == l && maxCnt != l {
43
-		return Float64Data{}, nil
44
-	}
45
-
46
-	return mode, nil
47
-}
48 1
deleted file mode 100644
... ...
@@ -1,254 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"math"
5
-	"math/rand"
6
-	"strings"
7
-	"time"
8
-)
9
-
10
-// NormPpfRvs generates random variates using the Point Percentile Function.
11
-// For more information please visit: https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/
12
-func NormPpfRvs(loc float64, scale float64, size int) []float64 {
13
-	rand.Seed(time.Now().UnixNano())
14
-	var toReturn []float64
15
-	for i := 0; i < size; i++ {
16
-		toReturn = append(toReturn, NormPpf(rand.Float64(), loc, scale))
17
-	}
18
-	return toReturn
19
-}
20
-
21
-// NormBoxMullerRvs generates random variates using the Box–Muller transform.
22
-// For more information please visit: http://mathworld.wolfram.com/Box-MullerTransformation.html
23
-func NormBoxMullerRvs(loc float64, scale float64, size int) []float64 {
24
-	rand.Seed(time.Now().UnixNano())
25
-	var toReturn []float64
26
-	for i := 0; i < int(float64(size/2)+float64(size%2)); i++ {
27
-		// u1 and u2 are uniformly distributed random numbers between 0 and 1.
28
-		u1 := rand.Float64()
29
-		u2 := rand.Float64()
30
-		// x1 and x2 are normally distributed random numbers.
31
-		x1 := loc + (scale * (math.Sqrt(-2*math.Log(u1)) * math.Cos(2*math.Pi*u2)))
32
-		toReturn = append(toReturn, x1)
33
-		if (i+1)*2 <= size {
34
-			x2 := loc + (scale * (math.Sqrt(-2*math.Log(u1)) * math.Sin(2*math.Pi*u2)))
35
-			toReturn = append(toReturn, x2)
36
-		}
37
-	}
38
-	return toReturn
39
-}
40
-
41
-// NormPdf is the probability density function.
42
-func NormPdf(x float64, loc float64, scale float64) float64 {
43
-	return (math.Pow(math.E, -(math.Pow(x-loc, 2))/(2*math.Pow(scale, 2)))) / (scale * math.Sqrt(2*math.Pi))
44
-}
45
-
46
-// NormLogPdf is the log of the probability density function.
47
-func NormLogPdf(x float64, loc float64, scale float64) float64 {
48
-	return math.Log((math.Pow(math.E, -(math.Pow(x-loc, 2))/(2*math.Pow(scale, 2)))) / (scale * math.Sqrt(2*math.Pi)))
49
-}
50
-
51
-// NormCdf is the cumulative distribution function.
52
-func NormCdf(x float64, loc float64, scale float64) float64 {
53
-	return 0.5 * (1 + math.Erf((x-loc)/(scale*math.Sqrt(2))))
54
-}
55
-
56
-// NormLogCdf is the log of the cumulative distribution function.
57
-func NormLogCdf(x float64, loc float64, scale float64) float64 {
58
-	return math.Log(0.5 * (1 + math.Erf((x-loc)/(scale*math.Sqrt(2)))))
59
-}
60
-
61
-// NormSf is the survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
62
-func NormSf(x float64, loc float64, scale float64) float64 {
63
-	return 1 - 0.5*(1+math.Erf((x-loc)/(scale*math.Sqrt(2))))
64
-}
65
-
66
-// NormLogSf is the log of the survival function.
67
-func NormLogSf(x float64, loc float64, scale float64) float64 {
68
-	return math.Log(1 - 0.5*(1+math.Erf((x-loc)/(scale*math.Sqrt(2)))))
69
-}
70
-
71
-// NormPpf is the point percentile function.
72
-// This is based on Peter John Acklam's inverse normal CDF.
73
-// algorithm: http://home.online.no/~pjacklam/notes/invnorm/ (no longer visible).
74
-// For more information please visit: https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/
75
-func NormPpf(p float64, loc float64, scale float64) (x float64) {
76
-	const (
77
-		a1 = -3.969683028665376e+01
78
-		a2 = 2.209460984245205e+02
79
-		a3 = -2.759285104469687e+02
80
-		a4 = 1.383577518672690e+02
81
-		a5 = -3.066479806614716e+01
82
-		a6 = 2.506628277459239e+00
83
-
84
-		b1 = -5.447609879822406e+01
85
-		b2 = 1.615858368580409e+02
86
-		b3 = -1.556989798598866e+02
87
-		b4 = 6.680131188771972e+01
88
-		b5 = -1.328068155288572e+01
89
-
90
-		c1 = -7.784894002430293e-03
91
-		c2 = -3.223964580411365e-01
92
-		c3 = -2.400758277161838e+00
93
-		c4 = -2.549732539343734e+00
94
-		c5 = 4.374664141464968e+00
95
-		c6 = 2.938163982698783e+00
96
-
97
-		d1 = 7.784695709041462e-03
98
-		d2 = 3.224671290700398e-01
99
-		d3 = 2.445134137142996e+00
100
-		d4 = 3.754408661907416e+00
101
-
102
-		plow  = 0.02425
103
-		phigh = 1 - plow
104
-	)
105
-
106
-	if p < 0 || p > 1 {
107
-		return math.NaN()
108
-	} else if p == 0 {
109
-		return -math.Inf(0)
110
-	} else if p == 1 {
111
-		return math.Inf(0)
112
-	}
113
-
114
-	if p < plow {
115
-		q := math.Sqrt(-2 * math.Log(p))
116
-		x = (((((c1*q+c2)*q+c3)*q+c4)*q+c5)*q + c6) /
117
-			((((d1*q+d2)*q+d3)*q+d4)*q + 1)
118
-	} else if phigh < p {
119
-		q := math.Sqrt(-2 * math.Log(1-p))
120
-		x = -(((((c1*q+c2)*q+c3)*q+c4)*q+c5)*q + c6) /
121
-			((((d1*q+d2)*q+d3)*q+d4)*q + 1)
122
-	} else {
123
-		q := p - 0.5
124
-		r := q * q
125
-		x = (((((a1*r+a2)*r+a3)*r+a4)*r+a5)*r + a6) * q /
126
-			(((((b1*r+b2)*r+b3)*r+b4)*r+b5)*r + 1)
127
-	}
128
-
129
-	e := 0.5*math.Erfc(-x/math.Sqrt2) - p
130
-	u := e * math.Sqrt(2*math.Pi) * math.Exp(x*x/2)
131
-	x = x - u/(1+x*u/2)
132
-
133
-	return x*scale + loc
134
-}
135
-
136
-// NormIsf is the inverse survival function (inverse of sf).
137
-func NormIsf(p float64, loc float64, scale float64) (x float64) {
138
-	if -NormPpf(p, loc, scale) == 0 {
139
-		return 0
140
-	}
141
-	return -NormPpf(p, loc, scale)
142
-}
143
-
144
-// NormMoment approximates the non-central (raw) moment of order n.
145
-// For more information please visit: https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution
146
-func NormMoment(n int, loc float64, scale float64) float64 {
147
-	toReturn := 0.0
148
-	for i := 0; i < n+1; i++ {
149
-		if (n-i)%2 == 0 {
150
-			toReturn += float64(Ncr(n, i)) * (math.Pow(loc, float64(i))) * (math.Pow(scale, float64(n-i))) *
151
-				(float64(factorial(n-i)) / ((math.Pow(2.0, float64((n-i)/2))) *
152
-					float64(factorial((n-i)/2))))
153
-		}
154
-	}
155
-	return toReturn
156
-}
157
-
158
-// NormStats returns the mean, variance, skew, and/or kurtosis.
159
-// Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
160
-// Takes string containing any of 'mvsk'.
161
-// Returns array of m v s k in that order.
162
-func NormStats(loc float64, scale float64, moments string) []float64 {
163
-	var toReturn []float64
164
-	if strings.ContainsAny(moments, "m") {
165
-		toReturn = append(toReturn, loc)
166
-	}
167
-	if strings.ContainsAny(moments, "v") {
168
-		toReturn = append(toReturn, math.Pow(scale, 2))
169
-	}
170
-	if strings.ContainsAny(moments, "s") {
171
-		toReturn = append(toReturn, 0.0)
172
-	}
173
-	if strings.ContainsAny(moments, "k") {
174
-		toReturn = append(toReturn, 0.0)
175
-	}
176
-	return toReturn
177
-}
178
-
179
-// NormEntropy is the differential entropy of the RV.
180
-func NormEntropy(loc float64, scale float64) float64 {
181
-	return math.Log(scale * math.Sqrt(2*math.Pi*math.E))
182
-}
183
-
184
-// NormFit returns the maximum likelihood estimators for the Normal Distribution.
185
-// Takes array of float64 values.
186
-// Returns array of Mean followed by Standard Deviation.
187
-func NormFit(data []float64) [2]float64 {
188
-	sum := 0.00
189
-	for i := 0; i < len(data); i++ {
190
-		sum += data[i]
191
-	}
192
-	mean := sum / float64(len(data))
193
-	stdNumerator := 0.00
194
-	for i := 0; i < len(data); i++ {
195
-		stdNumerator += math.Pow(data[i]-mean, 2)
196
-	}
197
-	return [2]float64{mean, math.Sqrt((stdNumerator) / (float64(len(data))))}
198
-}
199
-
200
-// NormMedian is the median of the distribution.
201
-func NormMedian(loc float64, scale float64) float64 {
202
-	return loc
203
-}
204
-
205
-// NormMean is the mean/expected value of the distribution.
206
-func NormMean(loc float64, scale float64) float64 {
207
-	return loc
208
-}
209
-
210
-// NormVar is the variance of the distribution.
211
-func NormVar(loc float64, scale float64) float64 {
212
-	return math.Pow(scale, 2)
213
-}
214
-
215
-// NormStd is the standard deviation of the distribution.
216
-func NormStd(loc float64, scale float64) float64 {
217
-	return scale
218
-}
219
-
220
-// NormInterval finds endpoints of the range that contains alpha percent of the distribution.
221
-func NormInterval(alpha float64, loc float64, scale float64) [2]float64 {
222
-	q1 := (1.0 - alpha) / 2
223
-	q2 := (1.0 + alpha) / 2
224
-	a := NormPpf(q1, loc, scale)
225
-	b := NormPpf(q2, loc, scale)
226
-	return [2]float64{a, b}
227
-}
228
-
229
-// factorial is the naive factorial algorithm.
230
-func factorial(x int) int {
231
-	if x == 0 {
232
-		return 1
233
-	}
234
-	return x * factorial(x-1)
235
-}
236
-
237
-// Ncr is an N choose R algorithm.
238
-// Aaron Cannon's algorithm.
239
-func Ncr(n, r int) int {
240
-	if n <= 1 || r == 0 || n == r {
241
-		return 1
242
-	}
243
-	if newR := n - r; newR < r {
244
-		r = newR
245
-	}
246
-	if r == 1 {
247
-		return n
248
-	}
249
-	ret := int(n - r + 1)
250
-	for i, j := ret+1, int(2); j <= r; i, j = i+1, j+1 {
251
-		ret = ret * i / j
252
-	}
253
-	return ret
254
-}
255 1
deleted file mode 100644
... ...
@@ -1,44 +0,0 @@
1
-package stats
2
-
3
-// Outliers holds mild and extreme outliers found in data
4
-type Outliers struct {
5
-	Mild    Float64Data
6
-	Extreme Float64Data
7
-}
8
-
9
-// QuartileOutliers finds the mild and extreme outliers
10
-func QuartileOutliers(input Float64Data) (Outliers, error) {
11
-	if input.Len() == 0 {
12
-		return Outliers{}, EmptyInputErr
13
-	}
14
-
15
-	// Start by sorting a copy of the slice
16
-	copy := sortedCopy(input)
17
-
18
-	// Calculate the quartiles and interquartile range
19
-	qs, _ := Quartile(copy)
20
-	iqr, _ := InterQuartileRange(copy)
21
-
22
-	// Calculate the lower and upper inner and outer fences
23
-	lif := qs.Q1 - (1.5 * iqr)
24
-	uif := qs.Q3 + (1.5 * iqr)
25
-	lof := qs.Q1 - (3 * iqr)
26
-	uof := qs.Q3 + (3 * iqr)
27
-
28
-	// Find the data points that are outside of the
29
-	// inner and upper fences and add them to mild
30
-	// and extreme outlier slices
31
-	var mild Float64Data
32
-	var extreme Float64Data
33
-	for _, v := range copy {
34
-
35
-		if v < lof || v > uof {
36
-			extreme = append(extreme, v)
37
-		} else if v < lif || v > uif {
38
-			mild = append(mild, v)
39
-		}
40
-	}
41
-
42
-	// Wrap them into our struct
43
-	return Outliers{mild, extreme}, nil
44
-}
45 1
deleted file mode 100644
... ...
@@ -1,87 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"math"
5
-)
6
-
7
-// Percentile finds the relative standing in a slice of floats.
8
-//
9
-// The function uses the Linear Interpolation Between Closest Ranks method
10
-// as recommended by NIST [1] and used by Excel (PERCENTILE), Google Sheets,
11
-// NumPy (default), and other standard tools.
12
-//
13
-// Algorithm (for percent p and sorted data of length n):
14
-//
15
-//  1. Compute the rank: rank = (p / 100) * (n - 1)
16
-//  2. Split into integer part k and fractional part f
17
-//  3. Result = data[k] + f * (data[k+1] - data[k])
18
-//
19
-// [1] https://www.itl.nist.gov/div898/handbook/prc/section2/prc262.htm
20
-func Percentile(input Float64Data, percent float64) (percentile float64, err error) {
21
-	length := input.Len()
22
-	if length == 0 {
23
-		return math.NaN(), EmptyInputErr
24
-	}
25
-
26
-	if length == 1 {
27
-		return input[0], nil
28
-	}
29
-
30
-	if percent <= 0 || percent > 100 {
31
-		return math.NaN(), BoundsErr
32
-	}
33
-
34
-	// Start by sorting a copy of the slice
35
-	c := sortedCopy(input)
36
-
37
-	// Use the standard linear interpolation method:
38
-	// rank = (percent / 100) * (n - 1)
39
-	// result = c[k] + f * (c[k+1] - c[k])
40
-	rank := (percent / 100) * float64(length-1)
41
-	k := int(rank)
42
-	f := rank - float64(k)
43
-
44
-	if k+1 < length {
45
-		percentile = c[k] + f*(c[k+1]-c[k])
46
-	} else {
47
-		percentile = c[k]
48
-	}
49
-
50
-	return percentile, nil
51
-
52
-}
53
-
54
-// PercentileNearestRank finds the relative standing in a slice of floats using the Nearest Rank method
55
-func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) {
56
-
57
-	// Find the length of items in the slice
58
-	il := input.Len()
59
-
60
-	// Return an error for empty slices
61
-	if il == 0 {
62
-		return math.NaN(), EmptyInputErr
63
-	}
64
-
65
-	// Return error for less than 0 or greater than 100 percentages
66
-	if percent < 0 || percent > 100 {
67
-		return math.NaN(), BoundsErr
68
-	}
69
-
70
-	// Start by sorting a copy of the slice
71
-	c := sortedCopy(input)
72
-
73
-	// Return the last item
74
-	if percent == 100.0 {
75
-		return c[il-1], nil
76
-	}
77
-
78
-	// Find ordinal ranking
79
-	or := int(math.Ceil(float64(il) * percent / 100))
80
-
81
-	// Return the item that is in the place of the ordinal rank
82
-	if or == 0 {
83
-		return c[0], nil
84
-	}
85
-	return c[or-1], nil
86
-
87
-}
88 1
deleted file mode 100644
... ...
@@ -1,74 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Quartiles holds the three quartile points
6
-type Quartiles struct {
7
-	Q1 float64
8
-	Q2 float64
9
-	Q3 float64
10
-}
11
-
12
-// Quartile returns the three quartile points from a slice of data
13
-func Quartile(input Float64Data) (Quartiles, error) {
14
-
15
-	il := input.Len()
16
-	if il == 0 {
17
-		return Quartiles{}, EmptyInputErr
18
-	}
19
-
20
-	// Start by sorting a copy of the slice
21
-	copy := sortedCopy(input)
22
-
23
-	// Find the cutoff places depeding on if
24
-	// the input slice length is even or odd
25
-	var c1 int
26
-	var c2 int
27
-	if il%2 == 0 {
28
-		c1 = il / 2
29
-		c2 = il / 2
30
-	} else {
31
-		c1 = (il - 1) / 2
32
-		c2 = c1 + 1
33
-	}
34
-
35
-	// Find the Medians with the cutoff points
36
-	Q1, _ := Median(copy[:c1])
37
-	Q2, _ := Median(copy)
38
-	Q3, _ := Median(copy[c2:])
39
-
40
-	return Quartiles{Q1, Q2, Q3}, nil
41
-
42
-}
43
-
44
-// InterQuartileRange finds the range between Q1 and Q3
45
-func InterQuartileRange(input Float64Data) (float64, error) {
46
-	if input.Len() == 0 {
47
-		return math.NaN(), EmptyInputErr
48
-	}
49
-	qs, _ := Quartile(input)
50
-	iqr := qs.Q3 - qs.Q1
51
-	return iqr, nil
52
-}
53
-
54
-// Midhinge finds the average of the first and third quartiles
55
-func Midhinge(input Float64Data) (float64, error) {
56
-	if input.Len() == 0 {
57
-		return math.NaN(), EmptyInputErr
58
-	}
59
-	qs, _ := Quartile(input)
60
-	mh := (qs.Q1 + qs.Q3) / 2
61
-	return mh, nil
62
-}
63
-
64
-// Trimean finds the average of the median and the midhinge
65
-func Trimean(input Float64Data) (float64, error) {
66
-	if input.Len() == 0 {
67
-		return math.NaN(), EmptyInputErr
68
-	}
69
-
70
-	c := sortedCopy(input)
71
-	q, _ := Quartile(c)
72
-
73
-	return (q.Q1 + (q.Q2 * 2) + q.Q3) / 4, nil
74
-}
75 1
deleted file mode 100644
... ...
@@ -1,183 +0,0 @@
1
-package stats
2
-
3
-// import "math"
4
-//
5
-// // WilcoxonRankSum tests the null hypothesis that two sets
6
-// // of data are drawn from the same distribution. It does
7
-// // not handle ties between measurements in x and y.
8
-// //
9
-// // Parameters:
10
-// //    data1 Float64Data: First set of data points.
11
-// //    data2 Float64Data: Second set of data points.
12
-// //    Length of both data samples must be equal.
13
-// //
14
-// // Return:
15
-// //    statistic float64: The test statistic under the
16
-// //                       large-sample approximation that the
17
-// //                       rank sum statistic is normally distributed.
18
-// //    pvalue float64: The two-sided p-value of the test
19
-// //    err error: Any error from the input data parameters
20
-// //
21
-// // https://en.wikipedia.org/wiki/Wilcoxon_rank-sum_test
22
-// func WilcoxonRankSum(data1, data2 Float64Data) (float64, float64, error) {
23
-//
24
-// 	l1 := data1.Len()
25
-// 	l2 := data2.Len()
26
-//
27
-// 	if l1 == 0 || l2 == 0 {
28
-// 		return math.NaN(), math.NaN(), EmptyInputErr
29
-// 	}
30
-//
31
-// 	if l1 != l2 {
32
-// 		return math.NaN(), math.NaN(), SizeErr
33
-// 	}
34
-//
35
-// 	alldata := Float64Data{}
36
-// 	alldata = append(alldata, data1...)
37
-// 	alldata = append(alldata, data2...)
38
-//
39
-// 	// ranked :=
40
-//
41
-// 	return 0.0, 0.0, nil
42
-// }
43
-//
44
-// //     x, y = map(np.asarray, (x, y))
45
-// //     n1 = len(x)
46
-// //     n2 = len(y)
47
-// //     alldata = np.concatenate((x, y))
48
-// //     ranked = rankdata(alldata)
49
-// //     x = ranked[:n1]
50
-// //     s = np.sum(x, axis=0)
51
-// //     expected = n1 * (n1+n2+1) / 2.0
52
-// //     z = (s - expected) / np.sqrt(n1*n2*(n1+n2+1)/12.0)
53
-// //     prob = 2 * distributions.norm.sf(abs(z))
54
-// //
55
-// //     return RanksumsResult(z, prob)
56
-//
57
-// // def rankdata(a, method='average'):
58
-// //     """
59
-// //     Assign ranks to data, dealing with ties appropriately.
60
-// //     Ranks begin at 1.  The `method` argument controls how ranks are assigned
61
-// //     to equal values.  See [1]_ for further discussion of ranking methods.
62
-// //     Parameters
63
-// //     ----------
64
-// //     a : array_like
65
-// //         The array of values to be ranked.  The array is first flattened.
66
-// //     method : str, optional
67
-// //         The method used to assign ranks to tied elements.
68
-// //         The options are 'average', 'min', 'max', 'dense' and 'ordinal'.
69
-// //         'average':
70
-// //             The average of the ranks that would have been assigned to
71
-// //             all the tied values is assigned to each value.
72
-// //         'min':
73
-// //             The minimum of the ranks that would have been assigned to all
74
-// //             the tied values is assigned to each value.  (This is also
75
-// //             referred to as "competition" ranking.)
76
-// //         'max':
77
-// //             The maximum of the ranks that would have been assigned to all
78
-// //             the tied values is assigned to each value.
79
-// //         'dense':
80
-// //             Like 'min', but the rank of the next highest element is assigned
81
-// //             the rank immediately after those assigned to the tied elements.
82
-// //         'ordinal':
83
-// //             All values are given a distinct rank, corresponding to the order
84
-// //             that the values occur in `a`.
85
-// //         The default is 'average'.
86
-// //     Returns
87
-// //     -------
88
-// //     ranks : ndarray
89
-// //          An array of length equal to the size of `a`, containing rank
90
-// //          scores.
91
-// //     References
92
-// //     ----------
93
-// //     .. [1] "Ranking", https://en.wikipedia.org/wiki/Ranking
94
-// //     Examples
95
-// //     --------
96
-// //     >>> from scipy.stats import rankdata
97
-// //     >>> rankdata([0, 2, 3, 2])
98
-// //     array([ 1. ,  2.5,  4. ,  2.5])
99
-// //     """
100
-// //
101
-// //     arr = np.ravel(np.asarray(a))
102
-// //     algo = 'quicksort'
103
-// //     sorter = np.argsort(arr, kind=algo)
104
-// //
105
-// //     inv = np.empty(sorter.size, dtype=np.intp)
106
-// //     inv[sorter] = np.arange(sorter.size, dtype=np.intp)
107
-// //
108
-// //
109
-// //     arr = arr[sorter]
110
-// //     obs = np.r_[True, arr[1:] != arr[:-1]]
111
-// //     dense = obs.cumsum()[inv]
112
-// //
113
-// //
114
-// //     # cumulative counts of each unique value
115
-// //     count = np.r_[np.nonzero(obs)[0], len(obs)]
116
-// //
117
-// //     # average method
118
-// //     return .5 * (count[dense] + count[dense - 1] + 1)
119
-//
120
-// type rankable interface {
121
-// 	Len() int
122
-// 	RankEqual(int, int) bool
123
-// }
124
-//
125
-// func StandardRank(d rankable) []float64 {
126
-// 	r := make([]float64, d.Len())
127
-// 	var k int
128
-// 	for i := range r {
129
-// 		if i == 0 || !d.RankEqual(i, i-1) {
130
-// 			k = i + 1
131
-// 		}
132
-// 		r[i] = float64(k)
133
-// 	}
134
-// 	return r
135
-// }
136
-//
137
-// func ModifiedRank(d rankable) []float64 {
138
-// 	r := make([]float64, d.Len())
139
-// 	for i := range r {
140
-// 		k := i + 1
141
-// 		for j := i + 1; j < len(r) && d.RankEqual(i, j); j++ {
142
-// 			k = j + 1
143
-// 		}
144
-// 		r[i] = float64(k)
145
-// 	}
146
-// 	return r
147
-// }
148
-//
149
-// func DenseRank(d rankable) []float64 {
150
-// 	r := make([]float64, d.Len())
151
-// 	var k int
152
-// 	for i := range r {
153
-// 		if i == 0 || !d.RankEqual(i, i-1) {
154
-// 			k++
155
-// 		}
156
-// 		r[i] = float64(k)
157
-// 	}
158
-// 	return r
159
-// }
160
-//
161
-// func OrdinalRank(d rankable) []float64 {
162
-// 	r := make([]float64, d.Len())
163
-// 	for i := range r {
164
-// 		r[i] = float64(i + 1)
165
-// 	}
166
-// 	return r
167
-// }
168
-//
169
-// func FractionalRank(d rankable) []float64 {
170
-// 	r := make([]float64, d.Len())
171
-// 	for i := 0; i < len(r); {
172
-// 		var j int
173
-// 		f := float64(i + 1)
174
-// 		for j = i + 1; j < len(r) && d.RankEqual(i, j); j++ {
175
-// 			f += float64(j + 1)
176
-// 		}
177
-// 		f /= float64(j - i)
178
-// 		for ; i < j; i++ {
179
-// 			r[i] = f
180
-// 		}
181
-// 	}
182
-// 	return r
183
-// }
184 1
deleted file mode 100644
... ...
@@ -1,112 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Series is a container for a series of data
6
-type Series []Coordinate
7
-
8
-// Coordinate holds the data in a series
9
-type Coordinate struct {
10
-	X, Y float64
11
-}
12
-
13
-// LinearRegression finds the least squares linear regression on data series
14
-func LinearRegression(s Series) (regressions Series, err error) {
15
-
16
-	if len(s) == 0 {
17
-		return nil, EmptyInputErr
18
-	}
19
-
20
-	// Placeholder for the math to be done
21
-	var sum [4]float64
22
-
23
-	// Loop over data keeping index in place
24
-	i := 0
25
-	for ; i < len(s); i++ {
26
-		sum[0] += s[i].X
27
-		sum[1] += s[i].Y
28
-		sum[2] += s[i].X * s[i].X
29
-		sum[3] += s[i].X * s[i].Y
30
-	}
31
-
32
-	// Find gradient and intercept
33
-	f := float64(i)
34
-	gradient := (f*sum[3] - sum[0]*sum[1]) / (f*sum[2] - sum[0]*sum[0])
35
-	intercept := (sum[1] / f) - (gradient * sum[0] / f)
36
-
37
-	// Create the new regression series
38
-	for j := 0; j < len(s); j++ {
39
-		regressions = append(regressions, Coordinate{
40
-			X: s[j].X,
41
-			Y: s[j].X*gradient + intercept,
42
-		})
43
-	}
44
-
45
-	return regressions, nil
46
-}
47
-
48
-// ExponentialRegression returns an exponential regression on data series
49
-func ExponentialRegression(s Series) (regressions Series, err error) {
50
-
51
-	if len(s) == 0 {
52
-		return nil, EmptyInputErr
53
-	}
54
-
55
-	var sum [6]float64
56
-
57
-	for i := 0; i < len(s); i++ {
58
-		if s[i].Y < 0 {
59
-			return nil, YCoordErr
60
-		}
61
-		sum[0] += s[i].X
62
-		sum[1] += s[i].Y
63
-		sum[2] += s[i].X * s[i].X * s[i].Y
64
-		sum[3] += s[i].Y * math.Log(s[i].Y)
65
-		sum[4] += s[i].X * s[i].Y * math.Log(s[i].Y)
66
-		sum[5] += s[i].X * s[i].Y
67
-	}
68
-
69
-	denominator := (sum[1]*sum[2] - sum[5]*sum[5])
70
-	a := math.Pow(math.E, (sum[2]*sum[3]-sum[5]*sum[4])/denominator)
71
-	b := (sum[1]*sum[4] - sum[5]*sum[3]) / denominator
72
-
73
-	for j := 0; j < len(s); j++ {
74
-		regressions = append(regressions, Coordinate{
75
-			X: s[j].X,
76
-			Y: a * math.Exp(b*s[j].X),
77
-		})
78
-	}
79
-
80
-	return regressions, nil
81
-}
82
-
83
-// LogarithmicRegression returns an logarithmic regression on data series
84
-func LogarithmicRegression(s Series) (regressions Series, err error) {
85
-
86
-	if len(s) == 0 {
87
-		return nil, EmptyInputErr
88
-	}
89
-
90
-	var sum [4]float64
91
-
92
-	i := 0
93
-	for ; i < len(s); i++ {
94
-		sum[0] += math.Log(s[i].X)
95
-		sum[1] += s[i].Y * math.Log(s[i].X)
96
-		sum[2] += s[i].Y
97
-		sum[3] += math.Pow(math.Log(s[i].X), 2)
98
-	}
99
-
100
-	f := float64(i)
101
-	a := (f*sum[1] - sum[2]*sum[0]) / (f*sum[3] - sum[0]*sum[0])
102
-	b := (sum[2] - a*sum[0]) / f
103
-
104
-	for j := 0; j < len(s); j++ {
105
-		regressions = append(regressions, Coordinate{
106
-			X: s[j].X,
107
-			Y: b + a*math.Log(s[j].X),
108
-		})
109
-	}
110
-
111
-	return regressions, nil
112
-}
113 1
deleted file mode 100644
... ...
@@ -1,38 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Round a float to a specific decimal place or precision
6
-func Round(input float64, places int) (rounded float64, err error) {
7
-
8
-	// If the float is not a number
9
-	if math.IsNaN(input) {
10
-		return math.NaN(), NaNErr
11
-	}
12
-
13
-	// Find out the actual sign and correct the input for later
14
-	sign := 1.0
15
-	if input < 0 {
16
-		sign = -1
17
-		input *= -1
18
-	}
19
-
20
-	// Use the places arg to get the amount of precision wanted
21
-	precision := math.Pow(10, float64(places))
22
-
23
-	// Find the decimal place we are looking to round
24
-	digit := input * precision
25
-
26
-	// Get the actual decimal number as a fraction to be compared
27
-	_, decimal := math.Modf(digit)
28
-
29
-	// If the decimal is less than .5 we round down otherwise up
30
-	if decimal >= 0.5 {
31
-		rounded = math.Ceil(digit)
32
-	} else {
33
-		rounded = math.Floor(digit)
34
-	}
35
-
36
-	// Finally we do the math to actually create a rounded number
37
-	return rounded / precision * sign, nil
38
-}
39 1
deleted file mode 100644
... ...
@@ -1,76 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"math/rand"
5
-	"sort"
6
-)
7
-
8
-// Sample returns sample from input with replacement or without
9
-func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) {
10
-
11
-	if input.Len() == 0 {
12
-		return nil, EmptyInputErr
13
-	}
14
-
15
-	length := input.Len()
16
-	if replacement {
17
-
18
-		result := Float64Data{}
19
-		rand.Seed(unixnano())
20
-
21
-		// In every step, randomly take the num for
22
-		for i := 0; i < takenum; i++ {
23
-			idx := rand.Intn(length)
24
-			result = append(result, input[idx])
25
-		}
26
-
27
-		return result, nil
28
-
29
-	} else if !replacement && takenum <= length {
30
-
31
-		rand.Seed(unixnano())
32
-
33
-		// Get permutation of number of indexies
34
-		perm := rand.Perm(length)
35
-		result := Float64Data{}
36
-
37
-		// Get element of input by permutated index
38
-		for _, idx := range perm[0:takenum] {
39
-			result = append(result, input[idx])
40
-		}
41
-
42
-		return result, nil
43
-
44
-	}
45
-
46
-	return nil, BoundsErr
47
-}
48
-
49
-// StableSample like stable sort, it returns samples from input while keeps the order of original data.
50
-func StableSample(input Float64Data, takenum int) ([]float64, error) {
51
-	if input.Len() == 0 {
52
-		return nil, EmptyInputErr
53
-	}
54
-
55
-	length := input.Len()
56
-
57
-	if takenum <= length {
58
-
59
-		rand.Seed(unixnano())
60
-
61
-		perm := rand.Perm(length)
62
-		perm = perm[0:takenum]
63
-		// Sort perm before applying
64
-		sort.Ints(perm)
65
-		result := Float64Data{}
66
-
67
-		for _, idx := range perm {
68
-			result = append(result, input[idx])
69
-		}
70
-
71
-		return result, nil
72
-
73
-	}
74
-
75
-	return nil, BoundsErr
76
-}
77 1
deleted file mode 100644
... ...
@@ -1,18 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Sigmoid returns the input values in the range of -1 to 1
6
-// along the sigmoid or s-shaped curve, commonly used in
7
-// machine learning while training neural networks as an
8
-// activation function.
9
-func Sigmoid(input Float64Data) ([]float64, error) {
10
-	if input.Len() == 0 {
11
-		return Float64Data{}, EmptyInput
12
-	}
13
-	s := make([]float64, len(input))
14
-	for i, v := range input {
15
-		s[i] = 1 / (1 + math.Exp(-v))
16
-	}
17
-	return s, nil
18
-}
19 1
deleted file mode 100644
... ...
@@ -1,62 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Skewness computes the population skewness of the dataset
6
-func Skewness(input Float64Data) (float64, error) {
7
-	return PopulationSkewness(input)
8
-}
9
-
10
-// PopulationSkewness computes the population skewness using the third
11
-// central moment normalized by the cube of the standard deviation.
12
-func PopulationSkewness(input Float64Data) (float64, error) {
13
-	if input.Len() < 2 {
14
-		return math.NaN(), ErrEmptyInput
15
-	}
16
-
17
-	mean, _ := Mean(input)
18
-
19
-	// Compute sum of squared and cubed differences from the mean
20
-	var sumOfSquares, sumOfCubes float64
21
-	for _, v := range input {
22
-		d := v - mean
23
-		sumOfSquares += d * d
24
-		sumOfCubes += d * d * d
25
-	}
26
-
27
-	if sumOfSquares == 0 {
28
-		return math.NaN(), ErrEmptyInput
29
-	}
30
-
31
-	if sumOfCubes == 0 {
32
-		return 0.0, nil
33
-	}
34
-
35
-	n := float64(input.Len())
36
-	variance := sumOfSquares / n
37
-	stdDevCubed := math.Pow(variance, 3.0/2.0)
38
-
39
-	return (sumOfCubes / n) / stdDevCubed, nil
40
-}
41
-
42
-// SampleSkewness computes the adjusted Fisher-Pearson standardized moment
43
-// coefficient, correcting for bias in small samples.
44
-func SampleSkewness(input Float64Data) (float64, error) {
45
-	n := input.Len()
46
-	if n < 3 {
47
-		return math.NaN(), ErrEmptyInput
48
-	}
49
-
50
-	g1, err := PopulationSkewness(input)
51
-	if err != nil {
52
-		return math.NaN(), err
53
-	}
54
-
55
-	if g1 == 0 {
56
-		return 0.0, nil
57
-	}
58
-
59
-	// Adjusted Fisher-Pearson: G1 = g1 * sqrt(n*(n-1)) / (n-2)
60
-	nf := float64(n)
61
-	return g1 * math.Sqrt(nf*(nf-1)) / (nf - 2), nil
62
-}
63 1
deleted file mode 100644
... ...
@@ -1,25 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// SoftMax returns the input values in the range of 0 to 1
6
-// with sum of all the probabilities being equal to one. It
7
-// is commonly used in machine learning neural networks.
8
-func SoftMax(input Float64Data) ([]float64, error) {
9
-	if input.Len() == 0 {
10
-		return Float64Data{}, EmptyInput
11
-	}
12
-
13
-	s := 0.0
14
-	c, _ := Max(input)
15
-	for _, e := range input {
16
-		s += math.Exp(e - c)
17
-	}
18
-
19
-	sm := make([]float64, len(input))
20
-	for i, v := range input {
21
-		sm[i] = math.Exp(v-c) / s
22
-	}
23
-
24
-	return sm, nil
25
-}
26 1
deleted file mode 100644
... ...
@@ -1,18 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// Sum adds all the numbers of a slice together
6
-func Sum(input Float64Data) (sum float64, err error) {
7
-
8
-	if input.Len() == 0 {
9
-		return math.NaN(), EmptyInputErr
10
-	}
11
-
12
-	// Add em up
13
-	for _, n := range input {
14
-		sum += n
15
-	}
16
-
17
-	return sum, nil
18
-}
19 1
deleted file mode 100644
... ...
@@ -1,43 +0,0 @@
1
-package stats
2
-
3
-import (
4
-	"sort"
5
-	"time"
6
-)
7
-
8
-// float64ToInt rounds a float64 to an int
9
-func float64ToInt(input float64) (output int) {
10
-	r, _ := Round(input, 0)
11
-	return int(r)
12
-}
13
-
14
-// unixnano returns nanoseconds from UTC epoch
15
-func unixnano() int64 {
16
-	return time.Now().UTC().UnixNano()
17
-}
18
-
19
-// copyslice copies a slice of float64s
20
-func copyslice(input Float64Data) Float64Data {
21
-	s := make(Float64Data, input.Len())
22
-	copy(s, input)
23
-	return s
24
-}
25
-
26
-// sortedCopy returns a sorted copy of float64s
27
-func sortedCopy(input Float64Data) (copy Float64Data) {
28
-	copy = copyslice(input)
29
-	sort.Float64s(copy)
30
-	return
31
-}
32
-
33
-// sortedCopyDif returns a sorted copy of float64s
34
-// only if the original data isn't sorted.
35
-// Only use this if returned slice won't be manipulated!
36
-func sortedCopyDif(input Float64Data) (copy Float64Data) {
37
-	if sort.Float64sAreSorted(input) {
38
-		return input
39
-	}
40
-	copy = copyslice(input)
41
-	sort.Float64s(copy)
42
-	return
43
-}
44 1
deleted file mode 100644
... ...
@@ -1,105 +0,0 @@
1
-package stats
2
-
3
-import "math"
4
-
5
-// _variance finds the variance for both population and sample data
6
-func _variance(input Float64Data, sample int) (variance float64, err error) {
7
-
8
-	if input.Len() == 0 {
9
-		return math.NaN(), EmptyInputErr
10
-	}
11
-
12
-	// Sum the square of the mean subtracted from each number
13
-	m, _ := Mean(input)
14
-
15
-	for _, n := range input {
16
-		variance += (n - m) * (n - m)
17
-	}
18
-
19
-	// When getting the mean of the squared differences
20
-	// "sample" will allow us to know if it's a sample
21
-	// or population and wether to subtract by one or not
22
-	return variance / float64((input.Len() - (1 * sample))), nil
23
-}
24
-
25
-// Variance the amount of variation in the dataset
26
-func Variance(input Float64Data) (sdev float64, err error) {
27
-	return PopulationVariance(input)
28
-}
29
-
30
-// PopulationVariance finds the amount of variance within a population
31
-func PopulationVariance(input Float64Data) (pvar float64, err error) {
32
-
33
-	v, err := _variance(input, 0)
34
-	if err != nil {
35
-		return math.NaN(), err
36
-	}
37
-
38
-	return v, nil
39
-}
40
-
41
-// SampleVariance finds the amount of variance within a sample
42
-func SampleVariance(input Float64Data) (svar float64, err error) {
43
-
44
-	v, err := _variance(input, 1)
45
-	if err != nil {
46
-		return math.NaN(), err
47
-	}
48
-
49
-	return v, nil
50
-}
51
-
52
-// Covariance is a measure of how much two sets of data change
53
-func Covariance(data1, data2 Float64Data) (float64, error) {
54
-
55
-	l1 := data1.Len()
56
-	l2 := data2.Len()
57
-
58
-	if l1 == 0 || l2 == 0 {
59
-		return math.NaN(), EmptyInputErr
60
-	}
61
-
62
-	if l1 != l2 {
63
-		return math.NaN(), SizeErr
64
-	}
65
-
66
-	m1, _ := Mean(data1)
67
-	m2, _ := Mean(data2)
68
-
69
-	// Calculate sum of squares
70
-	var ss float64
71
-	for i := 0; i < l1; i++ {
72
-		delta1 := (data1.Get(i) - m1)
73
-		delta2 := (data2.Get(i) - m2)
74
-		ss += (delta1*delta2 - ss) / float64(i+1)
75
-	}
76
-
77
-	return ss * float64(l1) / float64(l1-1), nil
78
-}
79
-
80
-// CovariancePopulation computes covariance for entire population between two variables.
81
-func CovariancePopulation(data1, data2 Float64Data) (float64, error) {
82
-
83
-	l1 := data1.Len()
84
-	l2 := data2.Len()
85
-
86
-	if l1 == 0 || l2 == 0 {
87
-		return math.NaN(), EmptyInputErr
88
-	}
89
-
90
-	if l1 != l2 {
91
-		return math.NaN(), SizeErr
92
-	}
93
-
94
-	m1, _ := Mean(data1)
95
-	m2, _ := Mean(data2)
96
-
97
-	var s float64
98
-	for i := 0; i < l1; i++ {
99
-		delta1 := (data1.Get(i) - m1)
100
-		delta2 := (data2.Get(i) - m2)
101
-		s += delta1 * delta2
102
-	}
103
-
104
-	return s / float64(l1), nil
105
-}
... ...
@@ -1326,9 +1326,6 @@ github.com/moby/sys/userns
1326 1326
 ## explicit; go 1.18
1327 1327
 github.com/moby/term
1328 1328
 github.com/moby/term/windows
1329
-# github.com/montanaflynn/stats v0.9.0
1330
-## explicit; go 1.13
1331
-github.com/montanaflynn/stats
1332 1329
 # github.com/morikuni/aec v1.1.0
1333 1330
 ## explicit; go 1.21
1334 1331
 github.com/morikuni/aec