From 837bbf491d861837cb885a9345c05253f08ca9ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:48:51 +0000 Subject: [PATCH] Bump github.com/montanaflynn/stats Bumps [github.com/montanaflynn/stats](https://github.com/montanaflynn/stats) from 0.0.0-20171201202039-1bf9dbcd8cbe to 0.7.1. - [Release notes](https://github.com/montanaflynn/stats/releases) - [Changelog](https://github.com/montanaflynn/stats/blob/master/CHANGELOG.md) - [Commits](https://github.com/montanaflynn/stats/commits/v0.7.1) --- updated-dependencies: - dependency-name: github.com/montanaflynn/stats dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../github.com/montanaflynn/stats/.gitignore | 7 +- .../github.com/montanaflynn/stats/.travis.yml | 20 - .../montanaflynn/stats/CHANGELOG.md | 550 ++++++- .../montanaflynn/stats/DOCUMENTATION.md | 1271 +++++++++++++++++ vendor/github.com/montanaflynn/stats/LICENSE | 2 +- vendor/github.com/montanaflynn/stats/Makefile | 25 +- .../github.com/montanaflynn/stats/README.md | 234 ++- .../montanaflynn/stats/correlation.go | 33 +- .../montanaflynn/stats/cumulative_sum.go | 21 + vendor/github.com/montanaflynn/stats/data.go | 31 +- .../github.com/montanaflynn/stats/describe.go | 81 ++ .../montanaflynn/stats/deviation.go | 10 +- .../{data_set_distances.go => distances.go} | 51 +- vendor/github.com/montanaflynn/stats/doc.go | 23 + .../github.com/montanaflynn/stats/entropy.go | 31 + .../github.com/montanaflynn/stats/errors.go | 33 +- .../stats/geometric_distribution.go | 42 + .../github.com/montanaflynn/stats/legacy.go | 13 + vendor/github.com/montanaflynn/stats/load.go | 21 +- vendor/github.com/montanaflynn/stats/max.go | 6 +- vendor/github.com/montanaflynn/stats/mean.go | 6 +- .../github.com/montanaflynn/stats/median.go | 4 +- vendor/github.com/montanaflynn/stats/min.go | 2 +- vendor/github.com/montanaflynn/stats/mode.go | 4 +- vendor/github.com/montanaflynn/stats/norm.go | 254 ++++ .../github.com/montanaflynn/stats/outlier.go | 2 +- .../montanaflynn/stats/percentile.go | 14 +- .../github.com/montanaflynn/stats/quartile.go | 8 +- .../github.com/montanaflynn/stats/ranksum.go | 183 +++ .../montanaflynn/stats/regression.go | 12 +- .../github.com/montanaflynn/stats/sample.go | 36 +- .../github.com/montanaflynn/stats/sigmoid.go | 18 + .../github.com/montanaflynn/stats/softmax.go | 25 + vendor/github.com/montanaflynn/stats/sum.go | 2 +- .../github.com/montanaflynn/stats/variance.go | 8 +- vendor/modules.txt | 4 +- 38 files changed, 2885 insertions(+), 208 deletions(-) delete mode 100644 vendor/github.com/montanaflynn/stats/.travis.yml create mode 100644 vendor/github.com/montanaflynn/stats/DOCUMENTATION.md create mode 100644 vendor/github.com/montanaflynn/stats/cumulative_sum.go create mode 100644 vendor/github.com/montanaflynn/stats/describe.go rename vendor/github.com/montanaflynn/stats/{data_set_distances.go => distances.go} (50%) create mode 100644 vendor/github.com/montanaflynn/stats/doc.go create mode 100644 vendor/github.com/montanaflynn/stats/entropy.go create mode 100644 vendor/github.com/montanaflynn/stats/geometric_distribution.go create mode 100644 vendor/github.com/montanaflynn/stats/norm.go create mode 100644 vendor/github.com/montanaflynn/stats/ranksum.go create mode 100644 vendor/github.com/montanaflynn/stats/sigmoid.go create mode 100644 vendor/github.com/montanaflynn/stats/softmax.go diff --git a/go.mod b/go.mod index 344054b558..287f040478 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/golang/snappy v0.0.1 github.com/google/go-cmp v0.5.2 github.com/klauspost/compress v1.13.6 - github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe + github.com/montanaflynn/stats v0.7.1 github.com/xdg-go/scram v1.1.2 github.com/xdg-go/stringprep v1.0.4 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d diff --git a/go.sum b/go.sum index b3354cf3f7..157af87324 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= diff --git a/vendor/github.com/montanaflynn/stats/.gitignore b/vendor/github.com/montanaflynn/stats/.gitignore index 96b11286e5..75a2a3a3bd 100644 --- a/vendor/github.com/montanaflynn/stats/.gitignore +++ b/vendor/github.com/montanaflynn/stats/.gitignore @@ -1,2 +1,7 @@ coverage.out -.directory \ No newline at end of file +coverage.txt +release-notes.txt +.directory +.chglog +.vscode +.DS_Store \ No newline at end of file diff --git a/vendor/github.com/montanaflynn/stats/.travis.yml b/vendor/github.com/montanaflynn/stats/.travis.yml deleted file mode 100644 index 697dcb7591..0000000000 --- a/vendor/github.com/montanaflynn/stats/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: go -go: - - 1.1 - - 1.2 - - 1.3 - - 1.4 - - 1.5 - - tip -before_install: - - sudo pip install codecov -script: - - go test -after_success: - - codecov -notifications: - email: - recipients: - - montana@montanaflynn.me - on_success: change - on_failure: always diff --git a/vendor/github.com/montanaflynn/stats/CHANGELOG.md b/vendor/github.com/montanaflynn/stats/CHANGELOG.md index 532f6ed3fd..73c3b782b6 100644 --- a/vendor/github.com/montanaflynn/stats/CHANGELOG.md +++ b/vendor/github.com/montanaflynn/stats/CHANGELOG.md @@ -1,64 +1,534 @@ -# Change Log + +## [Unreleased] -## [0.2.0](https://github.com/montanaflynn/stats/tree/0.2.0) -### Merged pull requests: + +## [v0.7.1] - 2023-05-11 +### Add +- Add describe functions ([#77](https://github.com/montanaflynn/stats/issues/77)) -- Fixed typographical error, changed accomdate to accommodate in README. [\#5](https://github.com/montanaflynn/stats/pull/5) ([saromanov](https://github.com/orthographic-pedant)) +### Update +- Update .gitignore +- Update README.md, LICENSE and DOCUMENTATION.md files +- Update github action go workflow to run on push -### Package changes: -- Add `Correlation` function -- Add `Covariance` function -- Add `StandardDeviation` function to be the same as `StandardDeviationPopulation` -- Change `Variance` function to be the same as `PopulationVariation` -- Add helper methods to `Float64Data` -- Add `Float64Data` type to use instead of `[]float64` -- Add `Series` type which references to `[]Coordinate` + +## [v0.7.0] - 2023-01-08 +### Add +- Add geometric distribution functions ([#75](https://github.com/montanaflynn/stats/issues/75)) +- Add GitHub action go workflow -## [0.1.0](https://github.com/montanaflynn/stats/tree/0.1.0) +### Remove +- Remove travis CI config -Several functions were renamed in this release. They will still function but may be deprecated in the future. +### Update +- Update changelog with v0.7.0 changes +- Update changelog with v0.7.0 changes +- Update github action go workflow +- Update geometric distribution tests -### Package changes: -- Rename `VarP` to `PopulationVariance` -- Rename `VarS` to `SampleVariance` -- Rename `LinReg` to `LinearRegression` -- Rename `ExpReg` to `ExponentialRegression` -- Rename `LogReg` to `LogarithmicRegression` -- Rename `StdDevP` to `StandardDeviationPopulation` -- Rename `StdDevS` to `StandardDeviationSample` + +## [v0.6.6] - 2021-04-26 +### Add +- Add support for string and io.Reader in LoadRawData (pr [#68](https://github.com/montanaflynn/stats/issues/68)) +- Add latest versions of Go to test against -## [0.0.9](https://github.com/montanaflynn/stats/tree/0.0.9) +### Update +- Update changelog with v0.6.6 changes -### Closed issues: +### Use +- Use math.Sqrt in StandardDeviation (PR [#64](https://github.com/montanaflynn/stats/issues/64)) -- Functions have unexpected side effects [\#3](https://github.com/montanaflynn/stats/issues/3) -- Percentile is not calculated correctly [\#2](https://github.com/montanaflynn/stats/issues/2) -### Merged pull requests: + +## [v0.6.5] - 2021-02-21 +### Add +- Add Float64Data.Quartiles documentation +- Add Quartiles method to Float64Data type (issue [#60](https://github.com/montanaflynn/stats/issues/60)) -- Sample [\#4](https://github.com/montanaflynn/stats/pull/4) ([saromanov](https://github.com/saromanov)) +### Fix +- Fix make release changelog command and add changelog history -### Package changes: +### Update +- Update changelog with v0.6.5 changes +- Update changelog with v0.6.4 changes +- Update README.md links to CHANGELOG.md and DOCUMENTATION.md +- Update README.md and Makefile with new release commands + + +## [v0.6.4] - 2021-01-13 +### Fix +- Fix failing tests due to precision errors on arm64 ([#58](https://github.com/montanaflynn/stats/issues/58)) + +### Update +- Update changelog with v0.6.4 changes +- Update examples directory to include a README.md used for synopsis +- Update go.mod to include go version where modules are enabled by default +- Update changelog with v0.6.3 changes + + + +## [v0.6.3] - 2020-02-18 +### Add +- Add creating and committing changelog to Makefile release directive +- Add release-notes.txt and .chglog directory to .gitignore + +### Update +- Update exported tests to use import for better example documentation +- Update documentation using godoc2md +- Update changelog with v0.6.2 release + + + +## [v0.6.2] - 2020-02-18 +### Fix +- Fix linting errcheck warnings in go benchmarks + +### Update +- Update Makefile release directive to use correct release name + + + +## [v0.6.1] - 2020-02-18 +### Add +- Add StableSample function signature to readme + +### Fix +- Fix linting warnings for normal distribution functions formatting and tests + +### Update +- Update documentation links and rename DOC.md to DOCUMENTATION.md +- Update README with link to pkg.go.dev reference and release section +- Update Makefile with new changelog, docs, and release directives +- Update DOC.md links to GitHub source code +- Update doc.go comment and add DOC.md package reference file +- Update changelog using git-chglog + + + +## [v0.6.0] - 2020-02-17 +### Add +- Add Normal Distribution Functions ([#56](https://github.com/montanaflynn/stats/issues/56)) +- Add previous versions of Go to travis CI config +- Add check for distinct values in Mode function ([#51](https://github.com/montanaflynn/stats/issues/51)) +- Add StableSample function ([#48](https://github.com/montanaflynn/stats/issues/48)) +- Add doc.go file to show description and usage on godoc.org +- Add comments to new error and legacy error variables +- Add ExampleRound function to tests +- Add go.mod file for module support +- Add Sigmoid, SoftMax and Entropy methods and tests +- Add Entropy documentation, example and benchmarks +- Add Entropy function ([#44](https://github.com/montanaflynn/stats/issues/44)) + +### Fix +- Fix percentile when only one element ([#47](https://github.com/montanaflynn/stats/issues/47)) +- Fix AutoCorrelation name in comments and remove unneeded Sprintf + +### Improve +- Improve documentation section with command comments + +### Remove +- Remove very old versions of Go in travis CI config +- Remove boolean comparison to get rid of gometalinter warning + +### Update +- Update license dates +- Update Distance functions signatures to use Float64Data +- Update Sigmoid examples +- Update error names with backward compatibility + +### Use +- Use relative link to examples/main.go +- Use a single var block for exported errors + + + +## [v0.5.0] - 2019-01-16 +### Add +- Add Sigmoid and Softmax functions + +### Fix +- Fix syntax highlighting and add CumulativeSum func + + + +## [v0.4.0] - 2019-01-14 +### Add +- Add goreport badge and documentation section to README.md +- Add Examples to test files +- Add AutoCorrelation and nist tests +- Add String method to statsErr type +- Add Y coordinate error for ExponentialRegression +- Add syntax highlighting ([#43](https://github.com/montanaflynn/stats/issues/43)) +- Add CumulativeSum ([#40](https://github.com/montanaflynn/stats/issues/40)) +- Add more tests and rename distance files +- Add coverage and benchmarks to azure pipeline +- Add go tests to azure pipeline + +### Change +- Change travis tip alias to master +- Change codecov to coveralls for code coverage + +### Fix +- Fix a few lint warnings +- Fix example error + +### Improve +- Improve test coverage of distance functions + +### Only +- Only run travis on stable and tip versions +- Only check code coverage on tip + +### Remove +- Remove azure CI pipeline +- Remove unnecessary type conversions + +### Return +- Return EmptyInputErr instead of EmptyInput + +### Set +- Set up CI with Azure Pipelines + + + +## [0.3.0] - 2017-12-02 +### Add +- Add Chebyshev, Manhattan, Euclidean and Minkowski distance functions ([#35](https://github.com/montanaflynn/stats/issues/35)) +- Add function for computing chebyshev distance. ([#34](https://github.com/montanaflynn/stats/issues/34)) +- Add support for time.Duration +- Add LoadRawData to docs and examples +- Add unit test for edge case that wasn't covered +- Add unit tests for edge cases that weren't covered +- Add pearson alias delegating to correlation +- Add CovariancePopulation to Float64Data +- Add pearson product-moment correlation coefficient +- Add population covariance +- Add random slice benchmarks +- Add all applicable functions as methods to Float64Data type +- Add MIT license badge +- Add link to examples/methods.go +- Add Protips for usage and documentation sections +- Add tests for rounding up +- Add webdoc target and remove linting from test target +- Add example usage and consolidate contributing information + +### Added +- Added MedianAbsoluteDeviation + +### Annotation +- Annotation spelling error + +### Auto +- auto commit +- auto commit + +### Calculate +- Calculate correlation with sdev and covp + +### Clean +- Clean up README.md and add info for offline docs + +### Consolidated +- Consolidated all error values. + +### Fix +- Fix Percentile logic +- Fix InterQuartileRange method test +- Fix zero percent bug and add test +- Fix usage example output typos + +### Improve +- Improve bounds checking in Percentile +- Improve error log messaging + +### Imput +- Imput -> Input + +### Include +- Include alternative way to set Float64Data in example + +### Make +- Make various changes to README.md + +### Merge +- Merge branch 'master' of github.com:montanaflynn/stats +- Merge master + +### Mode +- Mode calculation fix and tests + +### Realized +- Realized the obvious efficiency gains of ignoring the unique numbers at the beginning of the slice. Benchmark joy ensued. + +### Refactor +- Refactor testing of Round() +- Refactor setting Coordinate y field using Exp in place of Pow +- Refactor Makefile and add docs target + +### Remove +- Remove deep links to types and functions + +### Rename +- Rename file from types to data + +### Retrieve +- Retrieve InterQuartileRange for the Float64Data. + +### Split +- Split up stats.go into separate files + +### Support +- Support more types on LoadRawData() ([#36](https://github.com/montanaflynn/stats/issues/36)) + +### Switch +- Switch default and check targets + +### Update +- Update Readme +- Update example methods and some text +- Update README and include Float64Data type method examples + +### Pull Requests +- Merge pull request [#32](https://github.com/montanaflynn/stats/issues/32) from a-robinson/percentile +- Merge pull request [#30](https://github.com/montanaflynn/stats/issues/30) from montanaflynn/fix-test +- Merge pull request [#29](https://github.com/montanaflynn/stats/issues/29) from edupsousa/master +- Merge pull request [#27](https://github.com/montanaflynn/stats/issues/27) from andrey-yantsen/fix-percentile-out-of-bounds +- Merge pull request [#25](https://github.com/montanaflynn/stats/issues/25) from kazhuravlev/patch-1 +- Merge pull request [#22](https://github.com/montanaflynn/stats/issues/22) from JanBerktold/time-duration +- Merge pull request [#24](https://github.com/montanaflynn/stats/issues/24) from alouche/master +- Merge pull request [#21](https://github.com/montanaflynn/stats/issues/21) from brydavis/master +- Merge pull request [#19](https://github.com/montanaflynn/stats/issues/19) from ginodeis/mode-bug +- Merge pull request [#17](https://github.com/montanaflynn/stats/issues/17) from Kunde21/master +- Merge pull request [#3](https://github.com/montanaflynn/stats/issues/3) from montanaflynn/master +- Merge pull request [#2](https://github.com/montanaflynn/stats/issues/2) from montanaflynn/master +- Merge pull request [#13](https://github.com/montanaflynn/stats/issues/13) from toashd/pearson +- Merge pull request [#12](https://github.com/montanaflynn/stats/issues/12) from alixaxel/MAD +- Merge pull request [#1](https://github.com/montanaflynn/stats/issues/1) from montanaflynn/master +- Merge pull request [#11](https://github.com/montanaflynn/stats/issues/11) from Kunde21/modeMemReduce +- Merge pull request [#10](https://github.com/montanaflynn/stats/issues/10) from Kunde21/ModeRewrite + + + +## [0.2.0] - 2015-10-14 +### Add +- Add Makefile with gometalinter, testing, benchmarking and coverage report targets +- Add comments describing functions and structs +- Add Correlation func +- Add Covariance func +- Add tests for new function shortcuts +- Add StandardDeviation function as a shortcut to StandardDeviationPopulation +- Add Float64Data and Series types + +### Change +- Change Sample to return a standard []float64 type + +### Fix +- Fix broken link to Makefile +- Fix broken link and simplify code coverage reporting command +- Fix go vet warning about printf type placeholder +- Fix failing codecov test coverage reporting +- Fix link to CHANGELOG.md + +### Fixed +- Fixed typographical error, changed accomdate to accommodate in README. + +### Include +- Include Variance and StandardDeviation shortcuts + +### Pass +- Pass gometalinter + +### Refactor +- Refactor Variance function to be the same as population variance + +### Release +- Release version 0.2.0 + +### Remove +- Remove unneeded do packages and update cover URL +- Remove sudo from pip install + +### Reorder +- Reorder functions and sections + +### Revert +- Revert to legacy containers to preserve go1.1 testing + +### Switch +- Switch from legacy to container-based CI infrastructure + +### Update +- Update contributing instructions and mention Makefile + +### Pull Requests +- Merge pull request [#5](https://github.com/montanaflynn/stats/issues/5) from orthographic-pedant/spell_check/accommodate + + + +## [0.1.0] - 2015-08-19 +### Add +- Add CONTRIBUTING.md + +### Rename +- Rename functions while preserving backwards compatibility + + + +## 0.0.9 - 2015-08-18 +### Add - Add HarmonicMean func - Add GeometricMean func +- Add .gitignore to avoid commiting test coverage report - Add Outliers stuct and QuantileOutliers func - Add Interquartile Range, Midhinge and Trimean examples - Add Trimean - Add Midhinge - Add Inter Quartile Range +- Add a unit test to check for an empty slice error - Add Quantiles struct and Quantile func -- Add Nearest Rank method of calculating percentiles -- Add errors for all functions -- Add sample -- Add Linear, Exponential and Logarithmic Regression -- Add sample and population variance and deviation -- Add Percentile and Float64ToInt -- Add Round -- Add Standard deviation -- Add Sum -- Add Min and Ma- x -- Add Mean, Median and Mode +- Add more tests and fix a typo +- Add Golang 1.5 to build tests +- Add a standard MIT license file +- Add basic benchmarking +- Add regression models +- Add codecov token +- Add codecov +- Add check for slices with a single item +- Add coverage tests +- Add back previous Go versions to Travis CI +- Add Travis CI +- Add GoDoc badge +- Add Percentile and Float64ToInt functions +- Add another rounding test for whole numbers +- Add build status badge +- Add code coverage badge +- Add test for NaN, achieving 100% code coverage +- Add round function +- Add standard deviation function +- Add sum function + +### Add +- add tests for sample +- add sample + +### Added +- Added sample and population variance and deviation functions +- Added README + +### Adjust +- Adjust API ordering + +### Avoid +- Avoid unintended consequence of using sort + +### Better +- Better performing min/max +- Better description + +### Change +- Change package path to potentially fix a bug in earlier versions of Go + +### Clean +- Clean up README and add some more information +- Clean up test error + +### Consistent +- Consistent empty slice error messages +- Consistent var naming +- Consistent func declaration + +### Convert +- Convert ints to floats + +### Duplicate +- Duplicate packages for all versions + +### Export +- Export Coordinate struct fields + +### First +- First commit + +### Fix +- Fix copy pasta mistake testing the wrong function +- Fix error message +- Fix usage output and edit API doc section +- Fix testing edgecase where map was in wrong order +- Fix usage example +- Fix usage examples + +### Include +- Include the Nearest Rank method of calculating percentiles + +### More +- More commenting + +### Move +- Move GoDoc link to top + +### Redirect +- Redirect kills newer versions of Go + +### Refactor +- Refactor code and error checking + +### Remove +- Remove unnecassary typecasting in sum func +- Remove cover since it doesn't work for later versions of go +- Remove golint and gocoveralls + +### Rename +- Rename StandardDev to StdDev +- Rename StandardDev to StdDev + +### Return +- Return errors for all functions + +### Run +- Run go fmt to clean up formatting + +### Simplify +- Simplify min/max function + +### Start +- Start with minimal tests + +### Switch +- Switch wercker to travis and update todos + +### Table +- table testing style + +### Update +- Update README and move the example main.go into it's own file +- Update TODO list +- Update README +- Update usage examples and todos + +### Use +- Use codecov the recommended way +- Use correct string formatting types + +### Pull Requests +- Merge pull request [#4](https://github.com/montanaflynn/stats/issues/4) from saromanov/sample + + +[Unreleased]: https://github.com/montanaflynn/stats/compare/v0.7.1...HEAD +[v0.7.1]: https://github.com/montanaflynn/stats/compare/v0.7.0...v0.7.1 +[v0.7.0]: https://github.com/montanaflynn/stats/compare/v0.6.6...v0.7.0 +[v0.6.6]: https://github.com/montanaflynn/stats/compare/v0.6.5...v0.6.6 +[v0.6.5]: https://github.com/montanaflynn/stats/compare/v0.6.4...v0.6.5 +[v0.6.4]: https://github.com/montanaflynn/stats/compare/v0.6.3...v0.6.4 +[v0.6.3]: https://github.com/montanaflynn/stats/compare/v0.6.2...v0.6.3 +[v0.6.2]: https://github.com/montanaflynn/stats/compare/v0.6.1...v0.6.2 +[v0.6.1]: https://github.com/montanaflynn/stats/compare/v0.6.0...v0.6.1 +[v0.6.0]: https://github.com/montanaflynn/stats/compare/v0.5.0...v0.6.0 +[v0.5.0]: https://github.com/montanaflynn/stats/compare/v0.4.0...v0.5.0 +[v0.4.0]: https://github.com/montanaflynn/stats/compare/0.3.0...v0.4.0 +[0.3.0]: https://github.com/montanaflynn/stats/compare/0.2.0...0.3.0 +[0.2.0]: https://github.com/montanaflynn/stats/compare/0.1.0...0.2.0 +[0.1.0]: https://github.com/montanaflynn/stats/compare/0.0.9...0.1.0 diff --git a/vendor/github.com/montanaflynn/stats/DOCUMENTATION.md b/vendor/github.com/montanaflynn/stats/DOCUMENTATION.md new file mode 100644 index 0000000000..978df2ffc0 --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/DOCUMENTATION.md @@ -0,0 +1,1271 @@ + + +# stats +`import "github.com/montanaflynn/stats"` + +* [Overview](#pkg-overview) +* [Index](#pkg-index) +* [Examples](#pkg-examples) +* [Subdirectories](#pkg-subdirectories) + +## Overview +Package stats is a well tested and comprehensive +statistics library package with no dependencies. + +Example Usage: + + + // start with some source data to use + data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8} + + // you could also use different types like this + // data := stats.LoadRawData([]int{1, 2, 3, 4, 5}) + // data := stats.LoadRawData([]interface{}{1.1, "2", 3}) + // etc... + + median, _ := stats.Median(data) + fmt.Println(median) // 3.65 + + roundedMedian, _ := stats.Round(median, 0) + fmt.Println(roundedMedian) // 4 + +MIT License Copyright (c) 2014-2020 Montana Flynn (https://montanaflynn.com) + + + + +## Index +* [Variables](#pkg-variables) +* [func AutoCorrelation(data Float64Data, lags int) (float64, error)](#AutoCorrelation) +* [func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)](#ChebyshevDistance) +* [func Correlation(data1, data2 Float64Data) (float64, error)](#Correlation) +* [func Covariance(data1, data2 Float64Data) (float64, error)](#Covariance) +* [func CovariancePopulation(data1, data2 Float64Data) (float64, error)](#CovariancePopulation) +* [func CumulativeSum(input Float64Data) ([]float64, error)](#CumulativeSum) +* [func Entropy(input Float64Data) (float64, error)](#Entropy) +* [func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)](#EuclideanDistance) +* [func ExpGeom(p float64) (exp float64, err error)](#ExpGeom) +* [func GeometricMean(input Float64Data) (float64, error)](#GeometricMean) +* [func HarmonicMean(input Float64Data) (float64, error)](#HarmonicMean) +* [func InterQuartileRange(input Float64Data) (float64, error)](#InterQuartileRange) +* [func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)](#ManhattanDistance) +* [func Max(input Float64Data) (max float64, err error)](#Max) +* [func Mean(input Float64Data) (float64, error)](#Mean) +* [func Median(input Float64Data) (median float64, err error)](#Median) +* [func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error)](#MedianAbsoluteDeviation) +* [func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error)](#MedianAbsoluteDeviationPopulation) +* [func Midhinge(input Float64Data) (float64, error)](#Midhinge) +* [func Min(input Float64Data) (min float64, err error)](#Min) +* [func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error)](#MinkowskiDistance) +* [func Mode(input Float64Data) (mode []float64, err error)](#Mode) +* [func Ncr(n, r int) int](#Ncr) +* [func NormBoxMullerRvs(loc float64, scale float64, size int) []float64](#NormBoxMullerRvs) +* [func NormCdf(x float64, loc float64, scale float64) float64](#NormCdf) +* [func NormEntropy(loc float64, scale float64) float64](#NormEntropy) +* [func NormFit(data []float64) [2]float64](#NormFit) +* [func NormInterval(alpha float64, loc float64, scale float64) [2]float64](#NormInterval) +* [func NormIsf(p float64, loc float64, scale float64) (x float64)](#NormIsf) +* [func NormLogCdf(x float64, loc float64, scale float64) float64](#NormLogCdf) +* [func NormLogPdf(x float64, loc float64, scale float64) float64](#NormLogPdf) +* [func NormLogSf(x float64, loc float64, scale float64) float64](#NormLogSf) +* [func NormMean(loc float64, scale float64) float64](#NormMean) +* [func NormMedian(loc float64, scale float64) float64](#NormMedian) +* [func NormMoment(n int, loc float64, scale float64) float64](#NormMoment) +* [func NormPdf(x float64, loc float64, scale float64) float64](#NormPdf) +* [func NormPpf(p float64, loc float64, scale float64) (x float64)](#NormPpf) +* [func NormPpfRvs(loc float64, scale float64, size int) []float64](#NormPpfRvs) +* [func NormSf(x float64, loc float64, scale float64) float64](#NormSf) +* [func NormStats(loc float64, scale float64, moments string) []float64](#NormStats) +* [func NormStd(loc float64, scale float64) float64](#NormStd) +* [func NormVar(loc float64, scale float64) float64](#NormVar) +* [func Pearson(data1, data2 Float64Data) (float64, error)](#Pearson) +* [func Percentile(input Float64Data, percent float64) (percentile float64, err error)](#Percentile) +* [func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error)](#PercentileNearestRank) +* [func PopulationVariance(input Float64Data) (pvar float64, err error)](#PopulationVariance) +* [func ProbGeom(a int, b int, p float64) (prob float64, err error)](#ProbGeom) +* [func Round(input float64, places int) (rounded float64, err error)](#Round) +* [func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error)](#Sample) +* [func SampleVariance(input Float64Data) (svar float64, err error)](#SampleVariance) +* [func Sigmoid(input Float64Data) ([]float64, error)](#Sigmoid) +* [func SoftMax(input Float64Data) ([]float64, error)](#SoftMax) +* [func StableSample(input Float64Data, takenum int) ([]float64, error)](#StableSample) +* [func StandardDeviation(input Float64Data) (sdev float64, err error)](#StandardDeviation) +* [func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)](#StandardDeviationPopulation) +* [func StandardDeviationSample(input Float64Data) (sdev float64, err error)](#StandardDeviationSample) +* [func StdDevP(input Float64Data) (sdev float64, err error)](#StdDevP) +* [func StdDevS(input Float64Data) (sdev float64, err error)](#StdDevS) +* [func Sum(input Float64Data) (sum float64, err error)](#Sum) +* [func Trimean(input Float64Data) (float64, error)](#Trimean) +* [func VarGeom(p float64) (exp float64, err error)](#VarGeom) +* [func VarP(input Float64Data) (sdev float64, err error)](#VarP) +* [func VarS(input Float64Data) (sdev float64, err error)](#VarS) +* [func Variance(input Float64Data) (sdev float64, err error)](#Variance) +* [type Coordinate](#Coordinate) + * [func ExpReg(s []Coordinate) (regressions []Coordinate, err error)](#ExpReg) + * [func LinReg(s []Coordinate) (regressions []Coordinate, err error)](#LinReg) + * [func LogReg(s []Coordinate) (regressions []Coordinate, err error)](#LogReg) +* [type Float64Data](#Float64Data) + * [func LoadRawData(raw interface{}) (f Float64Data)](#LoadRawData) + * [func (f Float64Data) AutoCorrelation(lags int) (float64, error)](#Float64Data.AutoCorrelation) + * [func (f Float64Data) Correlation(d Float64Data) (float64, error)](#Float64Data.Correlation) + * [func (f Float64Data) Covariance(d Float64Data) (float64, error)](#Float64Data.Covariance) + * [func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error)](#Float64Data.CovariancePopulation) + * [func (f Float64Data) CumulativeSum() ([]float64, error)](#Float64Data.CumulativeSum) + * [func (f Float64Data) Entropy() (float64, error)](#Float64Data.Entropy) + * [func (f Float64Data) GeometricMean() (float64, error)](#Float64Data.GeometricMean) + * [func (f Float64Data) Get(i int) float64](#Float64Data.Get) + * [func (f Float64Data) HarmonicMean() (float64, error)](#Float64Data.HarmonicMean) + * [func (f Float64Data) InterQuartileRange() (float64, error)](#Float64Data.InterQuartileRange) + * [func (f Float64Data) Len() int](#Float64Data.Len) + * [func (f Float64Data) Less(i, j int) bool](#Float64Data.Less) + * [func (f Float64Data) Max() (float64, error)](#Float64Data.Max) + * [func (f Float64Data) Mean() (float64, error)](#Float64Data.Mean) + * [func (f Float64Data) Median() (float64, error)](#Float64Data.Median) + * [func (f Float64Data) MedianAbsoluteDeviation() (float64, error)](#Float64Data.MedianAbsoluteDeviation) + * [func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error)](#Float64Data.MedianAbsoluteDeviationPopulation) + * [func (f Float64Data) Midhinge(d Float64Data) (float64, error)](#Float64Data.Midhinge) + * [func (f Float64Data) Min() (float64, error)](#Float64Data.Min) + * [func (f Float64Data) Mode() ([]float64, error)](#Float64Data.Mode) + * [func (f Float64Data) Pearson(d Float64Data) (float64, error)](#Float64Data.Pearson) + * [func (f Float64Data) Percentile(p float64) (float64, error)](#Float64Data.Percentile) + * [func (f Float64Data) PercentileNearestRank(p float64) (float64, error)](#Float64Data.PercentileNearestRank) + * [func (f Float64Data) PopulationVariance() (float64, error)](#Float64Data.PopulationVariance) + * [func (f Float64Data) Quartile(d Float64Data) (Quartiles, error)](#Float64Data.Quartile) + * [func (f Float64Data) QuartileOutliers() (Outliers, error)](#Float64Data.QuartileOutliers) + * [func (f Float64Data) Quartiles() (Quartiles, error)](#Float64Data.Quartiles) + * [func (f Float64Data) Sample(n int, r bool) ([]float64, error)](#Float64Data.Sample) + * [func (f Float64Data) SampleVariance() (float64, error)](#Float64Data.SampleVariance) + * [func (f Float64Data) Sigmoid() ([]float64, error)](#Float64Data.Sigmoid) + * [func (f Float64Data) SoftMax() ([]float64, error)](#Float64Data.SoftMax) + * [func (f Float64Data) StandardDeviation() (float64, error)](#Float64Data.StandardDeviation) + * [func (f Float64Data) StandardDeviationPopulation() (float64, error)](#Float64Data.StandardDeviationPopulation) + * [func (f Float64Data) StandardDeviationSample() (float64, error)](#Float64Data.StandardDeviationSample) + * [func (f Float64Data) Sum() (float64, error)](#Float64Data.Sum) + * [func (f Float64Data) Swap(i, j int)](#Float64Data.Swap) + * [func (f Float64Data) Trimean(d Float64Data) (float64, error)](#Float64Data.Trimean) + * [func (f Float64Data) Variance() (float64, error)](#Float64Data.Variance) +* [type Outliers](#Outliers) + * [func QuartileOutliers(input Float64Data) (Outliers, error)](#QuartileOutliers) +* [type Quartiles](#Quartiles) + * [func Quartile(input Float64Data) (Quartiles, error)](#Quartile) +* [type Series](#Series) + * [func ExponentialRegression(s Series) (regressions Series, err error)](#ExponentialRegression) + * [func LinearRegression(s Series) (regressions Series, err error)](#LinearRegression) + * [func LogarithmicRegression(s Series) (regressions Series, err error)](#LogarithmicRegression) + +#### Examples +* [AutoCorrelation](#example_AutoCorrelation) +* [ChebyshevDistance](#example_ChebyshevDistance) +* [Correlation](#example_Correlation) +* [CumulativeSum](#example_CumulativeSum) +* [Entropy](#example_Entropy) +* [ExpGeom](#example_ExpGeom) +* [LinearRegression](#example_LinearRegression) +* [LoadRawData](#example_LoadRawData) +* [Max](#example_Max) +* [Median](#example_Median) +* [Min](#example_Min) +* [ProbGeom](#example_ProbGeom) +* [Round](#example_Round) +* [Sigmoid](#example_Sigmoid) +* [SoftMax](#example_SoftMax) +* [Sum](#example_Sum) +* [VarGeom](#example_VarGeom) + +#### Package files +[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) [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) + + + +## Variables +``` go +var ( + // ErrEmptyInput Input must not be empty + ErrEmptyInput = statsError{"Input must not be empty."} + // ErrNaN Not a number + ErrNaN = statsError{"Not a number."} + // ErrNegative Must not contain negative values + ErrNegative = statsError{"Must not contain negative values."} + // ErrZero Must not contain zero values + ErrZero = statsError{"Must not contain zero values."} + // ErrBounds Input is outside of range + ErrBounds = statsError{"Input is outside of range."} + // ErrSize Must be the same length + ErrSize = statsError{"Must be the same length."} + // ErrInfValue Value is infinite + ErrInfValue = statsError{"Value is infinite."} + // ErrYCoord Y Value must be greater than zero + ErrYCoord = statsError{"Y Value must be greater than zero."} +) +``` +These are the package-wide error values. +All error identification should use these values. +https://github.com/golang/go/wiki/Errors#naming + +``` go +var ( + EmptyInputErr = ErrEmptyInput + NaNErr = ErrNaN + NegativeErr = ErrNegative + ZeroErr = ErrZero + BoundsErr = ErrBounds + SizeErr = ErrSize + InfValue = ErrInfValue + YCoordErr = ErrYCoord + EmptyInput = ErrEmptyInput +) +``` +Legacy error names that didn't start with Err + + + +## func [AutoCorrelation](/correlation.go?s=853:918#L38) +``` go +func AutoCorrelation(data Float64Data, lags int) (float64, error) +``` +AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay + + + +## func [ChebyshevDistance](/distances.go?s=368:456#L20) +``` go +func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) +``` +ChebyshevDistance computes the Chebyshev distance between two data sets + + + +## func [Correlation](/correlation.go?s=112:171#L8) +``` go +func Correlation(data1, data2 Float64Data) (float64, error) +``` +Correlation describes the degree of relationship between two sets of data + + + +## func [Covariance](/variance.go?s=1284:1342#L53) +``` go +func Covariance(data1, data2 Float64Data) (float64, error) +``` +Covariance is a measure of how much two sets of data change + + + +## func [CovariancePopulation](/variance.go?s=1864:1932#L81) +``` go +func CovariancePopulation(data1, data2 Float64Data) (float64, error) +``` +CovariancePopulation computes covariance for entire population between two variables. + + + +## func [CumulativeSum](/cumulative_sum.go?s=81:137#L4) +``` go +func CumulativeSum(input Float64Data) ([]float64, error) +``` +CumulativeSum calculates the cumulative sum of the input slice + + + +## func [Entropy](/entropy.go?s=77:125#L6) +``` go +func Entropy(input Float64Data) (float64, error) +``` +Entropy provides calculation of the entropy + + + +## func [EuclideanDistance](/distances.go?s=836:924#L36) +``` go +func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) +``` +EuclideanDistance computes the Euclidean distance between two data sets + + + +## func [ExpGeom](/geometric_distribution.go?s=652:700#L27) +``` go +func ExpGeom(p float64) (exp float64, err error) +``` +ProbGeom generates the expectation or average number of trials +for a geometric random variable with parameter p + + + +## func [GeometricMean](/mean.go?s=319:373#L18) +``` go +func GeometricMean(input Float64Data) (float64, error) +``` +GeometricMean gets the geometric mean for a slice of numbers + + + +## func [HarmonicMean](/mean.go?s=717:770#L40) +``` go +func HarmonicMean(input Float64Data) (float64, error) +``` +HarmonicMean gets the harmonic mean for a slice of numbers + + + +## func [InterQuartileRange](/quartile.go?s=821:880#L45) +``` go +func InterQuartileRange(input Float64Data) (float64, error) +``` +InterQuartileRange finds the range between Q1 and Q3 + + + +## func [ManhattanDistance](/distances.go?s=1277:1365#L50) +``` go +func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) +``` +ManhattanDistance computes the Manhattan distance between two data sets + + + +## func [Max](/max.go?s=78:130#L8) +``` go +func Max(input Float64Data) (max float64, err error) +``` +Max finds the highest number in a slice + + + +## func [Mean](/mean.go?s=77:122#L6) +``` go +func Mean(input Float64Data) (float64, error) +``` +Mean gets the average of a slice of numbers + + + +## func [Median](/median.go?s=85:143#L6) +``` go +func Median(input Float64Data) (median float64, err error) +``` +Median gets the median number in a slice of numbers + + + +## func [MedianAbsoluteDeviation](/deviation.go?s=125:197#L6) +``` go +func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error) +``` +MedianAbsoluteDeviation finds the median of the absolute deviations from the dataset median + + + +## func [MedianAbsoluteDeviationPopulation](/deviation.go?s=360:442#L11) +``` go +func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) +``` +MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median + + + +## func [Midhinge](/quartile.go?s=1075:1124#L55) +``` go +func Midhinge(input Float64Data) (float64, error) +``` +Midhinge finds the average of the first and third quartiles + + + +## func [Min](/min.go?s=78:130#L6) +``` go +func Min(input Float64Data) (min float64, err error) +``` +Min finds the lowest number in a set of data + + + +## func [MinkowskiDistance](/distances.go?s=2152:2256#L75) +``` go +func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error) +``` +MinkowskiDistance computes the Minkowski distance between two data sets + +Arguments: + + + dataPointX: First set of data points + dataPointY: Second set of data points. Length of both data + sets must be equal. + lambda: aka p or city blocks; With lambda = 1 + returned distance is manhattan distance and + lambda = 2; it is euclidean distance. Lambda + reaching to infinite - distance would be chebysev + distance. + +Return: + + + Distance or error + + + +## func [Mode](/mode.go?s=85:141#L4) +``` go +func Mode(input Float64Data) (mode []float64, err error) +``` +Mode gets the mode [most frequent value(s)] of a slice of float64s + + + +## func [Ncr](/norm.go?s=7384:7406#L239) +``` go +func Ncr(n, r int) int +``` +Ncr is an N choose R algorithm. +Aaron Cannon's algorithm. + + + +## func [NormBoxMullerRvs](/norm.go?s=667:736#L23) +``` go +func NormBoxMullerRvs(loc float64, scale float64, size int) []float64 +``` +NormBoxMullerRvs generates random variates using the Box–Muller transform. +For more information please visit: http://mathworld.wolfram.com/Box-MullerTransformation.html + + + +## func [NormCdf](/norm.go?s=1826:1885#L52) +``` go +func NormCdf(x float64, loc float64, scale float64) float64 +``` +NormCdf is the cumulative distribution function. + + + +## func [NormEntropy](/norm.go?s=5773:5825#L180) +``` go +func NormEntropy(loc float64, scale float64) float64 +``` +NormEntropy is the differential entropy of the RV. + + + +## func [NormFit](/norm.go?s=6058:6097#L187) +``` go +func NormFit(data []float64) [2]float64 +``` +NormFit returns the maximum likelihood estimators for the Normal Distribution. +Takes array of float64 values. +Returns array of Mean followed by Standard Deviation. + + + +## func [NormInterval](/norm.go?s=6976:7047#L221) +``` go +func NormInterval(alpha float64, loc float64, scale float64) [2]float64 +``` +NormInterval finds endpoints of the range that contains alpha percent of the distribution. + + + +## func [NormIsf](/norm.go?s=4330:4393#L137) +``` go +func NormIsf(p float64, loc float64, scale float64) (x float64) +``` +NormIsf is the inverse survival function (inverse of sf). + + + +## func [NormLogCdf](/norm.go?s=2016:2078#L57) +``` go +func NormLogCdf(x float64, loc float64, scale float64) float64 +``` +NormLogCdf is the log of the cumulative distribution function. + + + +## func [NormLogPdf](/norm.go?s=1590:1652#L47) +``` go +func NormLogPdf(x float64, loc float64, scale float64) float64 +``` +NormLogPdf is the log of the probability density function. + + + +## func [NormLogSf](/norm.go?s=2423:2484#L67) +``` go +func NormLogSf(x float64, loc float64, scale float64) float64 +``` +NormLogSf is the log of the survival function. + + + +## func [NormMean](/norm.go?s=6560:6609#L206) +``` go +func NormMean(loc float64, scale float64) float64 +``` +NormMean is the mean/expected value of the distribution. + + + +## func [NormMedian](/norm.go?s=6431:6482#L201) +``` go +func NormMedian(loc float64, scale float64) float64 +``` +NormMedian is the median of the distribution. + + + +## func [NormMoment](/norm.go?s=4694:4752#L146) +``` go +func NormMoment(n int, loc float64, scale float64) float64 +``` +NormMoment approximates the non-central (raw) moment of order n. +For more information please visit: https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution + + + +## func [NormPdf](/norm.go?s=1357:1416#L42) +``` go +func NormPdf(x float64, loc float64, scale float64) float64 +``` +NormPdf is the probability density function. + + + +## func [NormPpf](/norm.go?s=2854:2917#L75) +``` go +func NormPpf(p float64, loc float64, scale float64) (x float64) +``` +NormPpf is the point percentile function. +This is based on Peter John Acklam's inverse normal CDF. +algorithm: http://home.online.no/~pjacklam/notes/invnorm/ (no longer visible). +For more information please visit: https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/ + + + +## func [NormPpfRvs](/norm.go?s=247:310#L12) +``` go +func NormPpfRvs(loc float64, scale float64, size int) []float64 +``` +NormPpfRvs generates random variates using the Point Percentile Function. +For more information please visit: https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/ + + + +## func [NormSf](/norm.go?s=2250:2308#L62) +``` go +func NormSf(x float64, loc float64, scale float64) float64 +``` +NormSf is the survival function (also defined as 1 - cdf, but sf is sometimes more accurate). + + + +## func [NormStats](/norm.go?s=5277:5345#L162) +``` go +func NormStats(loc float64, scale float64, moments string) []float64 +``` +NormStats returns the mean, variance, skew, and/or kurtosis. +Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’). +Takes string containing any of 'mvsk'. +Returns array of m v s k in that order. + + + +## func [NormStd](/norm.go?s=6814:6862#L216) +``` go +func NormStd(loc float64, scale float64) float64 +``` +NormStd is the standard deviation of the distribution. + + + +## func [NormVar](/norm.go?s=6675:6723#L211) +``` go +func NormVar(loc float64, scale float64) float64 +``` +NormVar is the variance of the distribution. + + + +## func [Pearson](/correlation.go?s=655:710#L33) +``` go +func Pearson(data1, data2 Float64Data) (float64, error) +``` +Pearson calculates the Pearson product-moment correlation coefficient between two variables + + + +## func [Percentile](/percentile.go?s=98:181#L8) +``` go +func Percentile(input Float64Data, percent float64) (percentile float64, err error) +``` +Percentile finds the relative standing in a slice of floats + + + +## func [PercentileNearestRank](/percentile.go?s=1079:1173#L54) +``` go +func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) +``` +PercentileNearestRank finds the relative standing in a slice of floats using the Nearest Rank method + + + +## func [PopulationVariance](/variance.go?s=828:896#L31) +``` go +func PopulationVariance(input Float64Data) (pvar float64, err error) +``` +PopulationVariance finds the amount of variance within a population + + + +## func [ProbGeom](/geometric_distribution.go?s=258:322#L10) +``` go +func ProbGeom(a int, b int, p float64) (prob float64, err error) +``` +ProbGeom generates the probability for a geometric random variable +with parameter p to achieve success in the interval of [a, b] trials +See https://en.wikipedia.org/wiki/Geometric_distribution for more information + + + +## func [Round](/round.go?s=88:154#L6) +``` go +func Round(input float64, places int) (rounded float64, err error) +``` +Round a float to a specific decimal place or precision + + + +## func [Sample](/sample.go?s=112:192#L9) +``` go +func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) +``` +Sample returns sample from input with replacement or without + + + +## func [SampleVariance](/variance.go?s=1058:1122#L42) +``` go +func SampleVariance(input Float64Data) (svar float64, err error) +``` +SampleVariance finds the amount of variance within a sample + + + +## func [Sigmoid](/sigmoid.go?s=228:278#L9) +``` go +func Sigmoid(input Float64Data) ([]float64, error) +``` +Sigmoid returns the input values in the range of -1 to 1 +along the sigmoid or s-shaped curve, commonly used in +machine learning while training neural networks as an +activation function. + + + +## func [SoftMax](/softmax.go?s=206:256#L8) +``` go +func SoftMax(input Float64Data) ([]float64, error) +``` +SoftMax returns the input values in the range of 0 to 1 +with sum of all the probabilities being equal to one. It +is commonly used in machine learning neural networks. + + + +## func [StableSample](/sample.go?s=974:1042#L50) +``` go +func StableSample(input Float64Data, takenum int) ([]float64, error) +``` +StableSample like stable sort, it returns samples from input while keeps the order of original data. + + + +## func [StandardDeviation](/deviation.go?s=695:762#L27) +``` go +func StandardDeviation(input Float64Data) (sdev float64, err error) +``` +StandardDeviation the amount of variation in the dataset + + + +## func [StandardDeviationPopulation](/deviation.go?s=892:969#L32) +``` go +func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) +``` +StandardDeviationPopulation finds the amount of variation from the population + + + +## func [StandardDeviationSample](/deviation.go?s=1250:1323#L46) +``` go +func StandardDeviationSample(input Float64Data) (sdev float64, err error) +``` +StandardDeviationSample finds the amount of variation from a sample + + + +## func [StdDevP](/legacy.go?s=339:396#L14) +``` go +func StdDevP(input Float64Data) (sdev float64, err error) +``` +StdDevP is a shortcut to StandardDeviationPopulation + + + +## func [StdDevS](/legacy.go?s=497:554#L19) +``` go +func StdDevS(input Float64Data) (sdev float64, err error) +``` +StdDevS is a shortcut to StandardDeviationSample + + + +## func [Sum](/sum.go?s=78:130#L6) +``` go +func Sum(input Float64Data) (sum float64, err error) +``` +Sum adds all the numbers of a slice together + + + +## func [Trimean](/quartile.go?s=1320:1368#L65) +``` go +func Trimean(input Float64Data) (float64, error) +``` +Trimean finds the average of the median and the midhinge + + + +## func [VarGeom](/geometric_distribution.go?s=885:933#L37) +``` go +func VarGeom(p float64) (exp float64, err error) +``` +ProbGeom generates the variance for number for a +geometric random variable with parameter p + + + +## func [VarP](/legacy.go?s=59:113#L4) +``` go +func VarP(input Float64Data) (sdev float64, err error) +``` +VarP is a shortcut to PopulationVariance + + + +## func [VarS](/legacy.go?s=193:247#L9) +``` go +func VarS(input Float64Data) (sdev float64, err error) +``` +VarS is a shortcut to SampleVariance + + + +## func [Variance](/variance.go?s=659:717#L26) +``` go +func Variance(input Float64Data) (sdev float64, err error) +``` +Variance the amount of variation in the dataset + + + + +## type [Coordinate](/regression.go?s=143:183#L9) +``` go +type Coordinate struct { + X, Y float64 +} + +``` +Coordinate holds the data in a series + + + + + + + +### func [ExpReg](/legacy.go?s=791:856#L29) +``` go +func ExpReg(s []Coordinate) (regressions []Coordinate, err error) +``` +ExpReg is a shortcut to ExponentialRegression + + +### func [LinReg](/legacy.go?s=643:708#L24) +``` go +func LinReg(s []Coordinate) (regressions []Coordinate, err error) +``` +LinReg is a shortcut to LinearRegression + + +### func [LogReg](/legacy.go?s=944:1009#L34) +``` go +func LogReg(s []Coordinate) (regressions []Coordinate, err error) +``` +LogReg is a shortcut to LogarithmicRegression + + + + + +## type [Float64Data](/data.go?s=80:106#L4) +``` go +type Float64Data []float64 +``` +Float64Data is a named type for []float64 with helper methods + + + + + + + +### func [LoadRawData](/load.go?s=145:194#L12) +``` go +func LoadRawData(raw interface{}) (f Float64Data) +``` +LoadRawData parses and converts a slice of mixed data types to floats + + + + + +### func (Float64Data) [AutoCorrelation](/data.go?s=3257:3320#L91) +``` go +func (f Float64Data) AutoCorrelation(lags int) (float64, error) +``` +AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay + + + + +### func (Float64Data) [Correlation](/data.go?s=3058:3122#L86) +``` go +func (f Float64Data) Correlation(d Float64Data) (float64, error) +``` +Correlation describes the degree of relationship between two sets of data + + + + +### func (Float64Data) [Covariance](/data.go?s=4801:4864#L141) +``` go +func (f Float64Data) Covariance(d Float64Data) (float64, error) +``` +Covariance is a measure of how much two sets of data change + + + + +### func (Float64Data) [CovariancePopulation](/data.go?s=4983:5056#L146) +``` go +func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error) +``` +CovariancePopulation computes covariance for entire population between two variables + + + + +### func (Float64Data) [CumulativeSum](/data.go?s=883:938#L28) +``` go +func (f Float64Data) CumulativeSum() ([]float64, error) +``` +CumulativeSum returns the cumulative sum of the data + + + + +### func (Float64Data) [Entropy](/data.go?s=5480:5527#L162) +``` go +func (f Float64Data) Entropy() (float64, error) +``` +Entropy provides calculation of the entropy + + + + +### func (Float64Data) [GeometricMean](/data.go?s=1332:1385#L40) +``` go +func (f Float64Data) GeometricMean() (float64, error) +``` +GeometricMean returns the median of the data + + + + +### func (Float64Data) [Get](/data.go?s=129:168#L7) +``` go +func (f Float64Data) Get(i int) float64 +``` +Get item in slice + + + + +### func (Float64Data) [HarmonicMean](/data.go?s=1460:1512#L43) +``` go +func (f Float64Data) HarmonicMean() (float64, error) +``` +HarmonicMean returns the mode of the data + + + + +### func (Float64Data) [InterQuartileRange](/data.go?s=3755:3813#L106) +``` go +func (f Float64Data) InterQuartileRange() (float64, error) +``` +InterQuartileRange finds the range between Q1 and Q3 + + + + +### func (Float64Data) [Len](/data.go?s=217:247#L10) +``` go +func (f Float64Data) Len() int +``` +Len returns length of slice + + + + +### func (Float64Data) [Less](/data.go?s=318:358#L13) +``` go +func (f Float64Data) Less(i, j int) bool +``` +Less returns if one number is less than another + + + + +### func (Float64Data) [Max](/data.go?s=645:688#L22) +``` go +func (f Float64Data) Max() (float64, error) +``` +Max returns the maximum number in the data + + + + +### func (Float64Data) [Mean](/data.go?s=1005:1049#L31) +``` go +func (f Float64Data) Mean() (float64, error) +``` +Mean returns the mean of the data + + + + +### func (Float64Data) [Median](/data.go?s=1111:1157#L34) +``` go +func (f Float64Data) Median() (float64, error) +``` +Median returns the median of the data + + + + +### func (Float64Data) [MedianAbsoluteDeviation](/data.go?s=1630:1693#L46) +``` go +func (f Float64Data) MedianAbsoluteDeviation() (float64, error) +``` +MedianAbsoluteDeviation the median of the absolute deviations from the dataset median + + + + +### func (Float64Data) [MedianAbsoluteDeviationPopulation](/data.go?s=1842:1915#L51) +``` go +func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error) +``` +MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median + + + + +### func (Float64Data) [Midhinge](/data.go?s=3912:3973#L111) +``` go +func (f Float64Data) Midhinge(d Float64Data) (float64, error) +``` +Midhinge finds the average of the first and third quartiles + + + + +### func (Float64Data) [Min](/data.go?s=536:579#L19) +``` go +func (f Float64Data) Min() (float64, error) +``` +Min returns the minimum number in the data + + + + +### func (Float64Data) [Mode](/data.go?s=1217:1263#L37) +``` go +func (f Float64Data) Mode() ([]float64, error) +``` +Mode returns the mode of the data + + + + +### func (Float64Data) [Pearson](/data.go?s=3455:3515#L96) +``` go +func (f Float64Data) Pearson(d Float64Data) (float64, error) +``` +Pearson calculates the Pearson product-moment correlation coefficient between two variables. + + + + +### func (Float64Data) [Percentile](/data.go?s=2696:2755#L76) +``` go +func (f Float64Data) Percentile(p float64) (float64, error) +``` +Percentile finds the relative standing in a slice of floats + + + + +### func (Float64Data) [PercentileNearestRank](/data.go?s=2869:2939#L81) +``` go +func (f Float64Data) PercentileNearestRank(p float64) (float64, error) +``` +PercentileNearestRank finds the relative standing using the Nearest Rank method + + + + +### func (Float64Data) [PopulationVariance](/data.go?s=4495:4553#L131) +``` go +func (f Float64Data) PopulationVariance() (float64, error) +``` +PopulationVariance finds the amount of variance within a population + + + + +### func (Float64Data) [Quartile](/data.go?s=3610:3673#L101) +``` go +func (f Float64Data) Quartile(d Float64Data) (Quartiles, error) +``` +Quartile returns the three quartile points from a slice of data + + + + +### func (Float64Data) [QuartileOutliers](/data.go?s=2542:2599#L71) +``` go +func (f Float64Data) QuartileOutliers() (Outliers, error) +``` +QuartileOutliers finds the mild and extreme outliers + + + + +### func (Float64Data) [Quartiles](/data.go?s=5628:5679#L167) +``` go +func (f Float64Data) Quartiles() (Quartiles, error) +``` +Quartiles returns the three quartile points from instance of Float64Data + + + + +### func (Float64Data) [Sample](/data.go?s=4208:4269#L121) +``` go +func (f Float64Data) Sample(n int, r bool) ([]float64, error) +``` +Sample returns sample from input with replacement or without + + + + +### func (Float64Data) [SampleVariance](/data.go?s=4652:4706#L136) +``` go +func (f Float64Data) SampleVariance() (float64, error) +``` +SampleVariance finds the amount of variance within a sample + + + + +### func (Float64Data) [Sigmoid](/data.go?s=5169:5218#L151) +``` go +func (f Float64Data) Sigmoid() ([]float64, error) +``` +Sigmoid returns the input values along the sigmoid or s-shaped curve + + + + +### func (Float64Data) [SoftMax](/data.go?s=5359:5408#L157) +``` go +func (f Float64Data) SoftMax() ([]float64, error) +``` +SoftMax returns the input values in the range of 0 to 1 +with sum of all the probabilities being equal to one. + + + + +### func (Float64Data) [StandardDeviation](/data.go?s=2026:2083#L56) +``` go +func (f Float64Data) StandardDeviation() (float64, error) +``` +StandardDeviation the amount of variation in the dataset + + + + +### func (Float64Data) [StandardDeviationPopulation](/data.go?s=2199:2266#L61) +``` go +func (f Float64Data) StandardDeviationPopulation() (float64, error) +``` +StandardDeviationPopulation finds the amount of variation from the population + + + + +### func (Float64Data) [StandardDeviationSample](/data.go?s=2382:2445#L66) +``` go +func (f Float64Data) StandardDeviationSample() (float64, error) +``` +StandardDeviationSample finds the amount of variation from a sample + + + + +### func (Float64Data) [Sum](/data.go?s=764:807#L25) +``` go +func (f Float64Data) Sum() (float64, error) +``` +Sum returns the total of all the numbers in the data + + + + +### func (Float64Data) [Swap](/data.go?s=425:460#L16) +``` go +func (f Float64Data) Swap(i, j int) +``` +Swap switches out two numbers in slice + + + + +### func (Float64Data) [Trimean](/data.go?s=4059:4119#L116) +``` go +func (f Float64Data) Trimean(d Float64Data) (float64, error) +``` +Trimean finds the average of the median and the midhinge + + + + +### func (Float64Data) [Variance](/data.go?s=4350:4398#L126) +``` go +func (f Float64Data) Variance() (float64, error) +``` +Variance the amount of variation in the dataset + + + + +## type [Outliers](/outlier.go?s=73:139#L4) +``` go +type Outliers struct { + Mild Float64Data + Extreme Float64Data +} + +``` +Outliers holds mild and extreme outliers found in data + + + + + + + +### func [QuartileOutliers](/outlier.go?s=197:255#L10) +``` go +func QuartileOutliers(input Float64Data) (Outliers, error) +``` +QuartileOutliers finds the mild and extreme outliers + + + + + +## type [Quartiles](/quartile.go?s=75:136#L6) +``` go +type Quartiles struct { + Q1 float64 + Q2 float64 + Q3 float64 +} + +``` +Quartiles holds the three quartile points + + + + + + + +### func [Quartile](/quartile.go?s=205:256#L13) +``` go +func Quartile(input Float64Data) (Quartiles, error) +``` +Quartile returns the three quartile points from a slice of data + + + + + +## type [Series](/regression.go?s=76:100#L6) +``` go +type Series []Coordinate +``` +Series is a container for a series of data + + + + + + + +### func [ExponentialRegression](/regression.go?s=1089:1157#L50) +``` go +func ExponentialRegression(s Series) (regressions Series, err error) +``` +ExponentialRegression returns an exponential regression on data series + + +### func [LinearRegression](/regression.go?s=262:325#L14) +``` go +func LinearRegression(s Series) (regressions Series, err error) +``` +LinearRegression finds the least squares linear regression on data series + + +### func [LogarithmicRegression](/regression.go?s=1903:1971#L85) +``` go +func LogarithmicRegression(s Series) (regressions Series, err error) +``` +LogarithmicRegression returns an logarithmic regression on data series + + + + + + + + + +- - - +Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md) diff --git a/vendor/github.com/montanaflynn/stats/LICENSE b/vendor/github.com/montanaflynn/stats/LICENSE index 6648181765..3162cb1a58 100644 --- a/vendor/github.com/montanaflynn/stats/LICENSE +++ b/vendor/github.com/montanaflynn/stats/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2015 Montana Flynn (https://anonfunction.com) +Copyright (c) 2014-2023 Montana Flynn (https://montanaflynn.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/github.com/montanaflynn/stats/Makefile b/vendor/github.com/montanaflynn/stats/Makefile index 87844f485d..969df12808 100644 --- a/vendor/github.com/montanaflynn/stats/Makefile +++ b/vendor/github.com/montanaflynn/stats/Makefile @@ -1,13 +1,9 @@ .PHONY: all -doc: - godoc `pwd` - -webdoc: - godoc -http=:44444 +default: test lint format: - go fmt + go fmt . test: go test -race @@ -22,8 +18,17 @@ coverage: go tool cover -html="coverage.out" lint: format - go get github.com/alecthomas/gometalinter - gometalinter --install - gometalinter + golangci-lint run . + +docs: + godoc2md github.com/montanaflynn/stats | sed -e s#src/target/##g > DOCUMENTATION.md + +release: + git-chglog --output CHANGELOG.md --next-tag ${TAG} + git add CHANGELOG.md + git commit -m "Update changelog with ${TAG} changes" + git tag ${TAG} + git-chglog $(TAG) | tail -n +4 | gsed '1s/^/$(TAG)\n/gm' > release-notes.txt + git push origin master ${TAG} + hub release create --copy -F release-notes.txt ${TAG} -default: lint test diff --git a/vendor/github.com/montanaflynn/stats/README.md b/vendor/github.com/montanaflynn/stats/README.md index 5f8a9291bf..9c18890737 100644 --- a/vendor/github.com/montanaflynn/stats/README.md +++ b/vendor/github.com/montanaflynn/stats/README.md @@ -1,8 +1,10 @@ -# Stats [![][travis-svg]][travis-url] [![][coveralls-svg]][coveralls-url] [![][godoc-svg]][godoc-url] [![][license-svg]][license-url] +# Stats - Golang Statistics Package -A statistics package with many functions missing from the Golang standard library. See the [CHANGELOG.md](https://github.com/montanaflynn/stats/blob/master/CHANGELOG.md) for API changes and tagged releases you can vendor into your projects. +[![][action-svg]][action-url] [![][codecov-svg]][codecov-url] [![][goreport-svg]][goreport-url] [![][godoc-svg]][godoc-url] [![][pkggodev-svg]][pkggodev-url] [![][license-svg]][license-url] -> Statistics are used much like a drunk uses a lamppost: for support, not illumination. **- Vin Scully** +A well tested and comprehensive Golang statistics library / package / module with no dependencies. + +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! ## Installation @@ -10,79 +12,205 @@ A statistics package with many functions missing from the Golang standard librar go get github.com/montanaflynn/stats ``` -**Protip:** `go get -u github.com/montanaflynn/stats` updates stats to the latest version. - -## Usage - -The [entire API documentation](http://godoc.org/github.com/montanaflynn/stats) is available on GoDoc.org - -You can view docs offline with the following commands: - -``` -godoc ./ -godoc ./ Median -godoc ./ Float64Data -``` - -**Protip:** Generate HTML docs with `godoc -http=:4444` +## Example Usage -## Example - -All the functions can be seen in [examples/main.go](https://github.com/montanaflynn/stats/blob/master/examples/main.go) but here's a little taste: +All the functions can be seen in [examples/main.go](examples/main.go) but here's a little taste: ```go -// start with the some source data to use -var data = []float64{1, 2, 3, 4, 4, 5} +// start with some source data to use +data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8} + +// you could also use different types like this +// data := stats.LoadRawData([]int{1, 2, 3, 4, 5}) +// data := stats.LoadRawData([]interface{}{1.1, "2", 3}) +// etc... median, _ := stats.Median(data) -fmt.Println(median) // 3.5 +fmt.Println(median) // 3.65 roundedMedian, _ := stats.Round(median, 0) fmt.Println(roundedMedian) // 4 ``` -**Protip:** You can [call methods](https://github.com/montanaflynn/stats/blob/master/examples/methods.go) on the data if using the Float64Data type: +## Documentation -``` -var d stats.Float64Data = data +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). + +You can also view docs offline with the following commands: -max, _ := d.Max() -fmt.Println(max) // 5 +``` +# Command line +godoc . # show all exported apis +godoc . Median # show a single function +godoc -ex . Round # show function with example +godoc . Float64Data # show the type and methods + +# Local website +godoc -http=:4444 # start the godoc server on port 4444 +open http://localhost:4444/pkg/github.com/montanaflynn/stats/ ``` -## Contributing +The exported API is as follows: -If you have any suggestions, criticism 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! +```go +var ( + ErrEmptyInput = statsError{"Input must not be empty."} + ErrNaN = statsError{"Not a number."} + ErrNegative = statsError{"Must not contain negative values."} + ErrZero = statsError{"Must not contain zero values."} + ErrBounds = statsError{"Input is outside of range."} + ErrSize = statsError{"Must be the same length."} + ErrInfValue = statsError{"Value is infinite."} + ErrYCoord = statsError{"Y Value must be greater than zero."} +) + +func Round(input float64, places int) (rounded float64, err error) {} + +type Float64Data []float64 + +func LoadRawData(raw interface{}) (f Float64Data) {} + +func AutoCorrelation(data Float64Data, lags int) (float64, error) {} +func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {} +func Correlation(data1, data2 Float64Data) (float64, error) {} +func Covariance(data1, data2 Float64Data) (float64, error) {} +func CovariancePopulation(data1, data2 Float64Data) (float64, error) {} +func CumulativeSum(input Float64Data) ([]float64, error) {} +func Describe(input Float64Data, allowNaN bool, percentiles *[]float64) (*Description, error) {} +func DescribePercentileFunc(input Float64Data, allowNaN bool, percentiles *[]float64, percentileFunc func(Float64Data, float64) (float64, error)) (*Description, error) {} +func Entropy(input Float64Data) (float64, error) {} +func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {} +func GeometricMean(input Float64Data) (float64, error) {} +func HarmonicMean(input Float64Data) (float64, error) {} +func InterQuartileRange(input Float64Data) (float64, error) {} +func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {} +func Max(input Float64Data) (max float64, err error) {} +func Mean(input Float64Data) (float64, error) {} +func Median(input Float64Data) (median float64, err error) {} +func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error) {} +func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) {} +func Midhinge(input Float64Data) (float64, error) {} +func Min(input Float64Data) (min float64, err error) {} +func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error) {} +func Mode(input Float64Data) (mode []float64, err error) {} +func NormBoxMullerRvs(loc float64, scale float64, size int) []float64 {} +func NormCdf(x float64, loc float64, scale float64) float64 {} +func NormEntropy(loc float64, scale float64) float64 {} +func NormFit(data []float64) [2]float64{} +func NormInterval(alpha float64, loc float64, scale float64 ) [2]float64 {} +func NormIsf(p float64, loc float64, scale float64) (x float64) {} +func NormLogCdf(x float64, loc float64, scale float64) float64 {} +func NormLogPdf(x float64, loc float64, scale float64) float64 {} +func NormLogSf(x float64, loc float64, scale float64) float64 {} +func NormMean(loc float64, scale float64) float64 {} +func NormMedian(loc float64, scale float64) float64 {} +func NormMoment(n int, loc float64, scale float64) float64 {} +func NormPdf(x float64, loc float64, scale float64) float64 {} +func NormPpf(p float64, loc float64, scale float64) (x float64) {} +func NormPpfRvs(loc float64, scale float64, size int) []float64 {} +func NormSf(x float64, loc float64, scale float64) float64 {} +func NormStats(loc float64, scale float64, moments string) []float64 {} +func NormStd(loc float64, scale float64) float64 {} +func NormVar(loc float64, scale float64) float64 {} +func Pearson(data1, data2 Float64Data) (float64, error) {} +func Percentile(input Float64Data, percent float64) (percentile float64, err error) {} +func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) {} +func PopulationVariance(input Float64Data) (pvar float64, err error) {} +func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) {} +func SampleVariance(input Float64Data) (svar float64, err error) {} +func Sigmoid(input Float64Data) ([]float64, error) {} +func SoftMax(input Float64Data) ([]float64, error) {} +func StableSample(input Float64Data, takenum int) ([]float64, error) {} +func StandardDeviation(input Float64Data) (sdev float64, err error) {} +func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) {} +func StandardDeviationSample(input Float64Data) (sdev float64, err error) {} +func StdDevP(input Float64Data) (sdev float64, err error) {} +func StdDevS(input Float64Data) (sdev float64, err error) {} +func Sum(input Float64Data) (sum float64, err error) {} +func Trimean(input Float64Data) (float64, error) {} +func VarP(input Float64Data) (sdev float64, err error) {} +func VarS(input Float64Data) (sdev float64, err error) {} +func Variance(input Float64Data) (sdev float64, err error) {} +func ProbGeom(a int, b int, p float64) (prob float64, err error) {} +func ExpGeom(p float64) (exp float64, err error) {} +func VarGeom(p float64) (exp float64, err error) {} + +type Coordinate struct { + X, Y float64 +} + +type Series []Coordinate + +func ExponentialRegression(s Series) (regressions Series, err error) {} +func LinearRegression(s Series) (regressions Series, err error) {} +func LogarithmicRegression(s Series) (regressions Series, err error) {} + +type Outliers struct { + Mild Float64Data + Extreme Float64Data +} + +type Quartiles struct { + Q1 float64 + Q2 float64 + Q3 float64 +} + +func Quartile(input Float64Data) (Quartiles, error) {} +func QuartileOutliers(input Float64Data) (Outliers, error) {} +``` -### Pull Requests +## Contributing -Pull request are always welcome no matter how big or small. Here's an easy way to do it: +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. -1. Fork it and clone your fork +1. Fork the repo and clone your fork 2. Create new branch (`git checkout -b some-thing`) 3. Make the desired changes 4. Ensure tests pass (`go test -cover` or `make test`) -5. Commit changes (`git commit -am 'Did something'`) -6. Push branch (`git push origin some-thing`) -7. Submit pull request +5. Run lint and fix problems (`go vet .` or `make lint`) +6. Commit changes (`git commit -am 'Did something'`) +7. Push branch (`git push origin some-thing`) +8. Submit pull request To make things as seamless as possible please also consider the following steps: -- Update `README.md` to include new public types or functions in the documentation section. -- Update `examples/main.go` with a simple example of the new feature. -- Keep 100% code coverage (you can check with `make coverage`). -- Run [`gometalinter`](https://github.com/alecthomas/gometalinter) and make your code pass. -- Squash needless commits into single units of work with `git rebase -i new-feature`. +- Update `examples/main.go` with a simple example of the new feature +- Update `README.md` documentation section with any new exported API +- Keep 100% code coverage (you can check with `make coverage`) +- Squash commits into single units of work with `git rebase -i new-feature` + +## Releasing + +This is not required by contributors and mostly here as a reminder to myself as the maintainer of this repo. To release a new version we should update the [CHANGELOG.md](/CHANGELOG.md) and [DOCUMENTATION.md](/DOCUMENTATION.md). + +First install the tools used to generate the markdown files and release: -#### Makefile +``` +go install github.com/davecheney/godoc2md@latest +go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest +brew tap git-chglog/git-chglog +brew install gnu-sed hub git-chglog +``` -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. +Then you can run these `make` directives: -**Protip:** `watch -n 1 make check` will continuously format and test your code. +``` +# Generate DOCUMENTATION.md +make docs +``` + +Then we can create a [CHANGELOG.md](/CHANGELOG.md) a new git tag and a github release: + +``` +make release TAG=v0.x.x +``` + +To authenticate `hub` for the release you will need to create a personal access token and use it as the password when it's requested. ## MIT License -Copyright (c) 2014-2015 Montana Flynn +Copyright (c) 2014-2023 Montana Flynn (https://montanaflynn.com) 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: @@ -90,14 +218,20 @@ The above copyright notice and this permission notice shall be included in all c 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. -[travis-url]: https://travis-ci.org/montanaflynn/stats -[travis-svg]: https://img.shields.io/travis/montanaflynn/stats.svg +[action-url]: https://github.com/montanaflynn/stats/actions +[action-svg]: https://img.shields.io/github/actions/workflow/status/montanaflynn/stats/go.yml + +[codecov-url]: https://app.codecov.io/gh/montanaflynn/stats +[codecov-svg]: https://img.shields.io/codecov/c/github/montanaflynn/stats?token=wnw8dActnH -[coveralls-url]: https://coveralls.io/r/montanaflynn/stats?branch=master -[coveralls-svg]: https://img.shields.io/coveralls/montanaflynn/stats.svg +[goreport-url]: https://goreportcard.com/report/github.com/montanaflynn/stats +[goreport-svg]: https://goreportcard.com/badge/github.com/montanaflynn/stats [godoc-url]: https://godoc.org/github.com/montanaflynn/stats [godoc-svg]: https://godoc.org/github.com/montanaflynn/stats?status.svg +[pkggodev-url]: https://pkg.go.dev/github.com/montanaflynn/stats +[pkggodev-svg]: https://gistcdn.githack.com/montanaflynn/b02f1d78d8c0de8435895d7e7cd0d473/raw/17f2a5a69f1323ecd42c00e0683655da96d9ecc8/badge.svg + [license-url]: https://github.com/montanaflynn/stats/blob/master/LICENSE [license-svg]: https://img.shields.io/badge/license-MIT-blue.svg diff --git a/vendor/github.com/montanaflynn/stats/correlation.go b/vendor/github.com/montanaflynn/stats/correlation.go index d759bf8c42..4acab94dc9 100644 --- a/vendor/github.com/montanaflynn/stats/correlation.go +++ b/vendor/github.com/montanaflynn/stats/correlation.go @@ -1,6 +1,8 @@ package stats -import "math" +import ( + "math" +) // Correlation describes the degree of relationship between two sets of data func Correlation(data1, data2 Float64Data) (float64, error) { @@ -9,7 +11,7 @@ func Correlation(data1, data2 Float64Data) (float64, error) { l2 := data2.Len() if l1 == 0 || l2 == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } if l1 != l2 { @@ -27,7 +29,32 @@ func Correlation(data1, data2 Float64Data) (float64, error) { return covp / (sdev1 * sdev2), nil } -// Pearson calculates the Pearson product-moment correlation coefficient between two variables. +// Pearson calculates the Pearson product-moment correlation coefficient between two variables func Pearson(data1, data2 Float64Data) (float64, error) { return Correlation(data1, data2) } + +// AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay +func AutoCorrelation(data Float64Data, lags int) (float64, error) { + if len(data) < 1 { + return 0, EmptyInputErr + } + + mean, _ := Mean(data) + + var result, q float64 + + for i := 0; i < lags; i++ { + v := (data[0] - mean) * (data[0] - mean) + for i := 1; i < len(data); i++ { + delta0 := data[i-1] - mean + delta1 := data[i] - mean + q += (delta0*delta1 - q) / float64(i+1) + v += (delta1*delta1 - v) / float64(i+1) + } + + result = q / v + } + + return result, nil +} diff --git a/vendor/github.com/montanaflynn/stats/cumulative_sum.go b/vendor/github.com/montanaflynn/stats/cumulative_sum.go new file mode 100644 index 0000000000..e5305daf39 --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/cumulative_sum.go @@ -0,0 +1,21 @@ +package stats + +// CumulativeSum calculates the cumulative sum of the input slice +func CumulativeSum(input Float64Data) ([]float64, error) { + + if input.Len() == 0 { + return Float64Data{}, EmptyInput + } + + cumSum := make([]float64, input.Len()) + + for i, val := range input { + if i == 0 { + cumSum[i] = val + } else { + cumSum[i] = cumSum[i-1] + val + } + } + + return cumSum, nil +} diff --git a/vendor/github.com/montanaflynn/stats/data.go b/vendor/github.com/montanaflynn/stats/data.go index a087f457a0..b86f0d84dd 100644 --- a/vendor/github.com/montanaflynn/stats/data.go +++ b/vendor/github.com/montanaflynn/stats/data.go @@ -24,6 +24,9 @@ func (f Float64Data) Max() (float64, error) { return Max(f) } // Sum returns the total of all the numbers in the data func (f Float64Data) Sum() (float64, error) { return Sum(f) } +// CumulativeSum returns the cumulative sum of the data +func (f Float64Data) CumulativeSum() ([]float64, error) { return CumulativeSum(f) } + // Mean returns the mean of the data func (f Float64Data) Mean() (float64, error) { return Mean(f) } @@ -84,6 +87,11 @@ func (f Float64Data) Correlation(d Float64Data) (float64, error) { return Correlation(f, d) } +// AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay +func (f Float64Data) AutoCorrelation(lags int) (float64, error) { + return AutoCorrelation(f, lags) +} + // Pearson calculates the Pearson product-moment correlation coefficient between two variables. func (f Float64Data) Pearson(d Float64Data) (float64, error) { return Pearson(f, d) @@ -134,7 +142,28 @@ func (f Float64Data) Covariance(d Float64Data) (float64, error) { return Covariance(f, d) } -// CovariancePopulation computes covariance for entire population between two variables. +// CovariancePopulation computes covariance for entire population between two variables func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error) { return CovariancePopulation(f, d) } + +// Sigmoid returns the input values along the sigmoid or s-shaped curve +func (f Float64Data) Sigmoid() ([]float64, error) { + return Sigmoid(f) +} + +// SoftMax returns the input values in the range of 0 to 1 +// with sum of all the probabilities being equal to one. +func (f Float64Data) SoftMax() ([]float64, error) { + return SoftMax(f) +} + +// Entropy provides calculation of the entropy +func (f Float64Data) Entropy() (float64, error) { + return Entropy(f) +} + +// Quartiles returns the three quartile points from instance of Float64Data +func (f Float64Data) Quartiles() (Quartiles, error) { + return Quartile(f) +} diff --git a/vendor/github.com/montanaflynn/stats/describe.go b/vendor/github.com/montanaflynn/stats/describe.go new file mode 100644 index 0000000000..86b72425c6 --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/describe.go @@ -0,0 +1,81 @@ +package stats + +import "fmt" + +// Holds information about the dataset provided to Describe +type Description struct { + Count int + Mean float64 + Std float64 + Max float64 + Min float64 + DescriptionPercentiles []descriptionPercentile + AllowedNaN bool +} + +// Specifies percentiles to be computed +type descriptionPercentile struct { + Percentile float64 + Value float64 +} + +// Describe generates descriptive statistics about a provided dataset, similar to python's pandas.describe() +func Describe(input Float64Data, allowNaN bool, percentiles *[]float64) (*Description, error) { + return DescribePercentileFunc(input, allowNaN, percentiles, Percentile) +} + +// Describe generates descriptive statistics about a provided dataset, similar to python's pandas.describe() +// Takes in a function to use for percentile calculation +func DescribePercentileFunc(input Float64Data, allowNaN bool, percentiles *[]float64, percentileFunc func(Float64Data, float64) (float64, error)) (*Description, error) { + var description Description + description.AllowedNaN = allowNaN + description.Count = input.Len() + + if description.Count == 0 && !allowNaN { + return &description, ErrEmptyInput + } + + // Disregard error, since it cannot be thrown if Count is > 0 and allowNaN is false, else NaN is accepted + description.Std, _ = StandardDeviation(input) + description.Max, _ = Max(input) + description.Min, _ = Min(input) + description.Mean, _ = Mean(input) + + if percentiles != nil { + for _, percentile := range *percentiles { + if value, err := percentileFunc(input, percentile); err == nil || allowNaN { + description.DescriptionPercentiles = append(description.DescriptionPercentiles, descriptionPercentile{Percentile: percentile, Value: value}) + } + } + } + + return &description, nil +} + +/* +Represents the Description instance in a string format with specified number of decimals + + count 3 + mean 2.00 + std 0.82 + max 3.00 + min 1.00 + 25.00% NaN + 50.00% 1.50 + 75.00% 2.50 + NaN OK true +*/ +func (d *Description) String(decimals int) string { + var str string + + str += fmt.Sprintf("count\t%d\n", d.Count) + str += fmt.Sprintf("mean\t%.*f\n", decimals, d.Mean) + str += fmt.Sprintf("std\t%.*f\n", decimals, d.Std) + str += fmt.Sprintf("max\t%.*f\n", decimals, d.Max) + str += fmt.Sprintf("min\t%.*f\n", decimals, d.Min) + for _, percentile := range d.DescriptionPercentiles { + str += fmt.Sprintf("%.2f%%\t%.*f\n", percentile.Percentile, decimals, percentile.Value) + } + str += fmt.Sprintf("NaN OK\t%t", d.AllowedNaN) + return str +} diff --git a/vendor/github.com/montanaflynn/stats/deviation.go b/vendor/github.com/montanaflynn/stats/deviation.go index 539c02bcfd..e69a19f60d 100644 --- a/vendor/github.com/montanaflynn/stats/deviation.go +++ b/vendor/github.com/montanaflynn/stats/deviation.go @@ -10,7 +10,7 @@ func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error) { // MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } i := copyslice(input) @@ -32,26 +32,26 @@ func StandardDeviation(input Float64Data) (sdev float64, err error) { func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Get the population variance vp, _ := PopulationVariance(input) // Return the population standard deviation - return math.Pow(vp, 0.5), nil + return math.Sqrt(vp), nil } // StandardDeviationSample finds the amount of variation from a sample func StandardDeviationSample(input Float64Data) (sdev float64, err error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Get the sample variance vs, _ := SampleVariance(input) // Return the sample standard deviation - return math.Pow(vs, 0.5), nil + return math.Sqrt(vs), nil } diff --git a/vendor/github.com/montanaflynn/stats/data_set_distances.go b/vendor/github.com/montanaflynn/stats/distances.go similarity index 50% rename from vendor/github.com/montanaflynn/stats/data_set_distances.go rename to vendor/github.com/montanaflynn/stats/distances.go index 2e549c8d49..8a6330e388 100644 --- a/vendor/github.com/montanaflynn/stats/data_set_distances.go +++ b/vendor/github.com/montanaflynn/stats/distances.go @@ -5,9 +5,9 @@ import ( ) // Validate data for distance calculation -func validateData(dataPointX, dataPointY []float64) error { +func validateData(dataPointX, dataPointY Float64Data) error { if len(dataPointX) == 0 || len(dataPointY) == 0 { - return EmptyInput + return EmptyInputErr } if len(dataPointX) != len(dataPointY) { @@ -16,8 +16,8 @@ func validateData(dataPointX, dataPointY []float64) error { return nil } -// Computes Chebyshev distance between two data sets -func ChebyshevDistance(dataPointX, dataPointY []float64) (distance float64, err error) { +// ChebyshevDistance computes the Chebyshev distance between two data sets +func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { return math.NaN(), err @@ -32,10 +32,8 @@ func ChebyshevDistance(dataPointX, dataPointY []float64) (distance float64, err return distance, nil } -// -// Computes Euclidean distance between two data sets -// -func EuclideanDistance(dataPointX, dataPointY []float64) (distance float64, err error) { +// EuclideanDistance computes the Euclidean distance between two data sets +func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { @@ -48,10 +46,8 @@ func EuclideanDistance(dataPointX, dataPointY []float64) (distance float64, err return math.Sqrt(distance), nil } -// -// Computes Manhattan distance between two data sets -// -func ManhattanDistance(dataPointX, dataPointY []float64) (distance float64, err error) { +// ManhattanDistance computes the Manhattan distance between two data sets +func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { return math.NaN(), err @@ -63,22 +59,23 @@ func ManhattanDistance(dataPointX, dataPointY []float64) (distance float64, err return distance, nil } +// MinkowskiDistance computes the Minkowski distance between two data sets +// +// Arguments: // -// Computes minkowski distance between two data sets. +// dataPointX: First set of data points +// dataPointY: Second set of data points. Length of both data +// sets must be equal. +// lambda: aka p or city blocks; With lambda = 1 +// returned distance is manhattan distance and +// lambda = 2; it is euclidean distance. Lambda +// reaching to infinite - distance would be chebysev +// distance. // -// Input: -// dataPointX: First set of data points -// dataPointY: Second set of data points. Length of both data -// sets must be equal. -// lambda: aka p or city blocks; With lambda = 1 -// returned distance is manhattan distance and -// lambda = 2; it is euclidean distance. Lambda -// reaching to infinite - distance would be chebysev -// distance. -// Output: -// Distance or error +// Return: // -func MinkowskiDistance(dataPointX, dataPointY []float64, lambda float64) (distance float64, err error) { +// Distance or error +func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { return math.NaN(), err @@ -86,8 +83,8 @@ func MinkowskiDistance(dataPointX, dataPointY []float64, lambda float64) (distan for i := 0; i < len(dataPointY); i++ { distance = distance + math.Pow(math.Abs(dataPointX[i]-dataPointY[i]), lambda) } - distance = math.Pow(distance, float64(1/lambda)) - if math.IsInf(distance, 1) == true { + distance = math.Pow(distance, 1/lambda) + if math.IsInf(distance, 1) { return math.NaN(), InfValue } return distance, nil diff --git a/vendor/github.com/montanaflynn/stats/doc.go b/vendor/github.com/montanaflynn/stats/doc.go new file mode 100644 index 0000000000..facb8d57bf --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/doc.go @@ -0,0 +1,23 @@ +/* +Package stats is a well tested and comprehensive +statistics library package with no dependencies. + +Example Usage: + + // start with some source data to use + data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8} + + // you could also use different types like this + // data := stats.LoadRawData([]int{1, 2, 3, 4, 5}) + // data := stats.LoadRawData([]interface{}{1.1, "2", 3}) + // etc... + + median, _ := stats.Median(data) + fmt.Println(median) // 3.65 + + roundedMedian, _ := stats.Round(median, 0) + fmt.Println(roundedMedian) // 4 + +MIT License Copyright (c) 2014-2020 Montana Flynn (https://montanaflynn.com) +*/ +package stats diff --git a/vendor/github.com/montanaflynn/stats/entropy.go b/vendor/github.com/montanaflynn/stats/entropy.go new file mode 100644 index 0000000000..95263b0fce --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/entropy.go @@ -0,0 +1,31 @@ +package stats + +import "math" + +// Entropy provides calculation of the entropy +func Entropy(input Float64Data) (float64, error) { + input, err := normalize(input) + if err != nil { + return math.NaN(), err + } + var result float64 + for i := 0; i < input.Len(); i++ { + v := input.Get(i) + if v == 0 { + continue + } + result += (v * math.Log(v)) + } + return -result, nil +} + +func normalize(input Float64Data) (Float64Data, error) { + sum, err := input.Sum() + if err != nil { + return Float64Data{}, err + } + for i := 0; i < input.Len(); i++ { + input[i] = input[i] / sum + } + return input, nil +} diff --git a/vendor/github.com/montanaflynn/stats/errors.go b/vendor/github.com/montanaflynn/stats/errors.go index 0bb32f0dd6..95f82ff7b7 100644 --- a/vendor/github.com/montanaflynn/stats/errors.go +++ b/vendor/github.com/montanaflynn/stats/errors.go @@ -1,22 +1,35 @@ package stats -type statsErr struct { +type statsError struct { err string } -func (s statsErr) Error() string { +func (s statsError) Error() string { + return s.err +} + +func (s statsError) String() string { return s.err } // These are the package-wide error values. // All error identification should use these values. +// https://github.com/golang/go/wiki/Errors#naming var ( - EmptyInput = statsErr{"Input must not be empty."} - SampleSize = statsErr{"Samples number must be less than input length."} - NaNErr = statsErr{"Not a number"} - NegativeErr = statsErr{"Slice must not contain negative values."} - ZeroErr = statsErr{"Slice must not contain zero values."} - BoundsErr = statsErr{"Input is outside of range."} - SizeErr = statsErr{"Slices must be the same length."} - InfValue = statsErr{"Value is infinite."} + // ErrEmptyInput Input must not be empty + ErrEmptyInput = statsError{"Input must not be empty."} + // ErrNaN Not a number + ErrNaN = statsError{"Not a number."} + // ErrNegative Must not contain negative values + ErrNegative = statsError{"Must not contain negative values."} + // ErrZero Must not contain zero values + ErrZero = statsError{"Must not contain zero values."} + // ErrBounds Input is outside of range + ErrBounds = statsError{"Input is outside of range."} + // ErrSize Must be the same length + ErrSize = statsError{"Must be the same length."} + // ErrInfValue Value is infinite + ErrInfValue = statsError{"Value is infinite."} + // ErrYCoord Y Value must be greater than zero + ErrYCoord = statsError{"Y Value must be greater than zero."} ) diff --git a/vendor/github.com/montanaflynn/stats/geometric_distribution.go b/vendor/github.com/montanaflynn/stats/geometric_distribution.go new file mode 100644 index 0000000000..db785dda24 --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/geometric_distribution.go @@ -0,0 +1,42 @@ +package stats + +import ( + "math" +) + +// ProbGeom generates the probability for a geometric random variable +// with parameter p to achieve success in the interval of [a, b] trials +// See https://en.wikipedia.org/wiki/Geometric_distribution for more information +func ProbGeom(a int, b int, p float64) (prob float64, err error) { + if (a > b) || (a < 1) { + return math.NaN(), ErrBounds + } + + prob = 0 + q := 1 - p // probability of failure + + for k := a + 1; k <= b; k++ { + prob = prob + p*math.Pow(q, float64(k-1)) + } + + return prob, nil +} + +// ProbGeom generates the expectation or average number of trials +// for a geometric random variable with parameter p +func ExpGeom(p float64) (exp float64, err error) { + if (p > 1) || (p < 0) { + return math.NaN(), ErrNegative + } + + return 1 / p, nil +} + +// ProbGeom generates the variance for number for a +// geometric random variable with parameter p +func VarGeom(p float64) (exp float64, err error) { + if (p > 1) || (p < 0) { + return math.NaN(), ErrNegative + } + return (1 - p) / math.Pow(p, 2), nil +} diff --git a/vendor/github.com/montanaflynn/stats/legacy.go b/vendor/github.com/montanaflynn/stats/legacy.go index 17557abd99..0f3d1e8bb2 100644 --- a/vendor/github.com/montanaflynn/stats/legacy.go +++ b/vendor/github.com/montanaflynn/stats/legacy.go @@ -34,3 +34,16 @@ func ExpReg(s []Coordinate) (regressions []Coordinate, err error) { func LogReg(s []Coordinate) (regressions []Coordinate, err error) { return LogarithmicRegression(s) } + +// Legacy error names that didn't start with Err +var ( + EmptyInputErr = ErrEmptyInput + NaNErr = ErrNaN + NegativeErr = ErrNegative + ZeroErr = ErrZero + BoundsErr = ErrBounds + SizeErr = ErrSize + InfValue = ErrInfValue + YCoordErr = ErrYCoord + EmptyInput = ErrEmptyInput +) diff --git a/vendor/github.com/montanaflynn/stats/load.go b/vendor/github.com/montanaflynn/stats/load.go index 1012d0bb54..0eb0e27290 100644 --- a/vendor/github.com/montanaflynn/stats/load.go +++ b/vendor/github.com/montanaflynn/stats/load.go @@ -1,7 +1,10 @@ package stats import ( + "bufio" + "io" "strconv" + "strings" "time" ) @@ -40,7 +43,7 @@ func LoadRawData(raw interface{}) (f Float64Data) { return s case []bool: for _, v := range t { - if v == true { + if v { s = append(s, 1.0) } else { s = append(s, 0.0) @@ -138,7 +141,7 @@ func LoadRawData(raw interface{}) (f Float64Data) { return s case map[int]bool: for i := 0; i < len(t); i++ { - if t[i] == true { + if t[i] { s = append(s, 1.0) } else { s = append(s, 0.0) @@ -154,6 +157,18 @@ func LoadRawData(raw interface{}) (f Float64Data) { for i := 0; i < len(t); i++ { r = append(r, t[i]) } + case string: + for _, v := range strings.Fields(t) { + r = append(r, v) + } + case io.Reader: + scanner := bufio.NewScanner(t) + for scanner.Scan() { + l := scanner.Text() + for _, v := range strings.Fields(l) { + r = append(r, v) + } + } } for _, v := range r { @@ -171,7 +186,7 @@ func LoadRawData(raw interface{}) (f Float64Data) { f = append(f, fl) } case bool: - if t == true { + if t { f = append(f, 1.0) } else { f = append(f, 0.0) diff --git a/vendor/github.com/montanaflynn/stats/max.go b/vendor/github.com/montanaflynn/stats/max.go index d0fdd42b48..bb8c83c325 100644 --- a/vendor/github.com/montanaflynn/stats/max.go +++ b/vendor/github.com/montanaflynn/stats/max.go @@ -1,13 +1,15 @@ package stats -import "math" +import ( + "math" +) // Max finds the highest number in a slice func Max(input Float64Data) (max float64, err error) { // Return an error if there are no numbers if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Get the first value as the starting point diff --git a/vendor/github.com/montanaflynn/stats/mean.go b/vendor/github.com/montanaflynn/stats/mean.go index 944bb65721..a78d299aec 100644 --- a/vendor/github.com/montanaflynn/stats/mean.go +++ b/vendor/github.com/montanaflynn/stats/mean.go @@ -6,7 +6,7 @@ import "math" func Mean(input Float64Data) (float64, error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } sum, _ := input.Sum() @@ -19,7 +19,7 @@ func GeometricMean(input Float64Data) (float64, error) { l := input.Len() if l == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Get the product of all the numbers @@ -41,7 +41,7 @@ func HarmonicMean(input Float64Data) (float64, error) { l := input.Len() if l == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Get the sum of all the numbers reciprocals and return an diff --git a/vendor/github.com/montanaflynn/stats/median.go b/vendor/github.com/montanaflynn/stats/median.go index b13d8394bb..a678c36532 100644 --- a/vendor/github.com/montanaflynn/stats/median.go +++ b/vendor/github.com/montanaflynn/stats/median.go @@ -14,11 +14,11 @@ func Median(input Float64Data) (median float64, err error) { // For odd numbers we just use the middle number l := len(c) if l == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } else if l%2 == 0 { median, _ = Mean(c[l/2-1 : l/2+1]) } else { - median = float64(c[l/2]) + median = c[l/2] } return median, nil diff --git a/vendor/github.com/montanaflynn/stats/min.go b/vendor/github.com/montanaflynn/stats/min.go index 4383852e15..bf7e70acff 100644 --- a/vendor/github.com/montanaflynn/stats/min.go +++ b/vendor/github.com/montanaflynn/stats/min.go @@ -10,7 +10,7 @@ func Min(input Float64Data) (min float64, err error) { // Return an error if there are no numbers if l == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Get the first value as the starting point diff --git a/vendor/github.com/montanaflynn/stats/mode.go b/vendor/github.com/montanaflynn/stats/mode.go index 1160faf285..a7cf9f7a4b 100644 --- a/vendor/github.com/montanaflynn/stats/mode.go +++ b/vendor/github.com/montanaflynn/stats/mode.go @@ -7,7 +7,7 @@ func Mode(input Float64Data) (mode []float64, err error) { if l == 1 { return input, nil } else if l == 0 { - return nil, EmptyInput + return nil, EmptyInputErr } c := sortedCopyDif(input) @@ -39,7 +39,7 @@ func Mode(input Float64Data) (mode []float64, err error) { // Since length must be greater than 1, // check for slices of distinct values - if maxCnt == 1 { + if maxCnt == 1 || len(mode)*maxCnt == l && maxCnt != l { return Float64Data{}, nil } diff --git a/vendor/github.com/montanaflynn/stats/norm.go b/vendor/github.com/montanaflynn/stats/norm.go new file mode 100644 index 0000000000..4eb8eb8b99 --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/norm.go @@ -0,0 +1,254 @@ +package stats + +import ( + "math" + "math/rand" + "strings" + "time" +) + +// NormPpfRvs generates random variates using the Point Percentile Function. +// For more information please visit: https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/ +func NormPpfRvs(loc float64, scale float64, size int) []float64 { + rand.Seed(time.Now().UnixNano()) + var toReturn []float64 + for i := 0; i < size; i++ { + toReturn = append(toReturn, NormPpf(rand.Float64(), loc, scale)) + } + return toReturn +} + +// NormBoxMullerRvs generates random variates using the Box–Muller transform. +// For more information please visit: http://mathworld.wolfram.com/Box-MullerTransformation.html +func NormBoxMullerRvs(loc float64, scale float64, size int) []float64 { + rand.Seed(time.Now().UnixNano()) + var toReturn []float64 + for i := 0; i < int(float64(size/2)+float64(size%2)); i++ { + // u1 and u2 are uniformly distributed random numbers between 0 and 1. + u1 := rand.Float64() + u2 := rand.Float64() + // x1 and x2 are normally distributed random numbers. + x1 := loc + (scale * (math.Sqrt(-2*math.Log(u1)) * math.Cos(2*math.Pi*u2))) + toReturn = append(toReturn, x1) + if (i+1)*2 <= size { + x2 := loc + (scale * (math.Sqrt(-2*math.Log(u1)) * math.Sin(2*math.Pi*u2))) + toReturn = append(toReturn, x2) + } + } + return toReturn +} + +// NormPdf is the probability density function. +func NormPdf(x float64, loc float64, scale float64) float64 { + return (math.Pow(math.E, -(math.Pow(x-loc, 2))/(2*math.Pow(scale, 2)))) / (scale * math.Sqrt(2*math.Pi)) +} + +// NormLogPdf is the log of the probability density function. +func NormLogPdf(x float64, loc float64, scale float64) float64 { + return math.Log((math.Pow(math.E, -(math.Pow(x-loc, 2))/(2*math.Pow(scale, 2)))) / (scale * math.Sqrt(2*math.Pi))) +} + +// NormCdf is the cumulative distribution function. +func NormCdf(x float64, loc float64, scale float64) float64 { + return 0.5 * (1 + math.Erf((x-loc)/(scale*math.Sqrt(2)))) +} + +// NormLogCdf is the log of the cumulative distribution function. +func NormLogCdf(x float64, loc float64, scale float64) float64 { + return math.Log(0.5 * (1 + math.Erf((x-loc)/(scale*math.Sqrt(2))))) +} + +// NormSf is the survival function (also defined as 1 - cdf, but sf is sometimes more accurate). +func NormSf(x float64, loc float64, scale float64) float64 { + return 1 - 0.5*(1+math.Erf((x-loc)/(scale*math.Sqrt(2)))) +} + +// NormLogSf is the log of the survival function. +func NormLogSf(x float64, loc float64, scale float64) float64 { + return math.Log(1 - 0.5*(1+math.Erf((x-loc)/(scale*math.Sqrt(2))))) +} + +// NormPpf is the point percentile function. +// This is based on Peter John Acklam's inverse normal CDF. +// algorithm: http://home.online.no/~pjacklam/notes/invnorm/ (no longer visible). +// For more information please visit: https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/ +func NormPpf(p float64, loc float64, scale float64) (x float64) { + const ( + a1 = -3.969683028665376e+01 + a2 = 2.209460984245205e+02 + a3 = -2.759285104469687e+02 + a4 = 1.383577518672690e+02 + a5 = -3.066479806614716e+01 + a6 = 2.506628277459239e+00 + + b1 = -5.447609879822406e+01 + b2 = 1.615858368580409e+02 + b3 = -1.556989798598866e+02 + b4 = 6.680131188771972e+01 + b5 = -1.328068155288572e+01 + + c1 = -7.784894002430293e-03 + c2 = -3.223964580411365e-01 + c3 = -2.400758277161838e+00 + c4 = -2.549732539343734e+00 + c5 = 4.374664141464968e+00 + c6 = 2.938163982698783e+00 + + d1 = 7.784695709041462e-03 + d2 = 3.224671290700398e-01 + d3 = 2.445134137142996e+00 + d4 = 3.754408661907416e+00 + + plow = 0.02425 + phigh = 1 - plow + ) + + if p < 0 || p > 1 { + return math.NaN() + } else if p == 0 { + return -math.Inf(0) + } else if p == 1 { + return math.Inf(0) + } + + if p < plow { + q := math.Sqrt(-2 * math.Log(p)) + x = (((((c1*q+c2)*q+c3)*q+c4)*q+c5)*q + c6) / + ((((d1*q+d2)*q+d3)*q+d4)*q + 1) + } else if phigh < p { + q := math.Sqrt(-2 * math.Log(1-p)) + x = -(((((c1*q+c2)*q+c3)*q+c4)*q+c5)*q + c6) / + ((((d1*q+d2)*q+d3)*q+d4)*q + 1) + } else { + q := p - 0.5 + r := q * q + x = (((((a1*r+a2)*r+a3)*r+a4)*r+a5)*r + a6) * q / + (((((b1*r+b2)*r+b3)*r+b4)*r+b5)*r + 1) + } + + e := 0.5*math.Erfc(-x/math.Sqrt2) - p + u := e * math.Sqrt(2*math.Pi) * math.Exp(x*x/2) + x = x - u/(1+x*u/2) + + return x*scale + loc +} + +// NormIsf is the inverse survival function (inverse of sf). +func NormIsf(p float64, loc float64, scale float64) (x float64) { + if -NormPpf(p, loc, scale) == 0 { + return 0 + } + return -NormPpf(p, loc, scale) +} + +// NormMoment approximates the non-central (raw) moment of order n. +// For more information please visit: https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution +func NormMoment(n int, loc float64, scale float64) float64 { + toReturn := 0.0 + for i := 0; i < n+1; i++ { + if (n-i)%2 == 0 { + toReturn += float64(Ncr(n, i)) * (math.Pow(loc, float64(i))) * (math.Pow(scale, float64(n-i))) * + (float64(factorial(n-i)) / ((math.Pow(2.0, float64((n-i)/2))) * + float64(factorial((n-i)/2)))) + } + } + return toReturn +} + +// NormStats returns the mean, variance, skew, and/or kurtosis. +// Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’). +// Takes string containing any of 'mvsk'. +// Returns array of m v s k in that order. +func NormStats(loc float64, scale float64, moments string) []float64 { + var toReturn []float64 + if strings.ContainsAny(moments, "m") { + toReturn = append(toReturn, loc) + } + if strings.ContainsAny(moments, "v") { + toReturn = append(toReturn, math.Pow(scale, 2)) + } + if strings.ContainsAny(moments, "s") { + toReturn = append(toReturn, 0.0) + } + if strings.ContainsAny(moments, "k") { + toReturn = append(toReturn, 0.0) + } + return toReturn +} + +// NormEntropy is the differential entropy of the RV. +func NormEntropy(loc float64, scale float64) float64 { + return math.Log(scale * math.Sqrt(2*math.Pi*math.E)) +} + +// NormFit returns the maximum likelihood estimators for the Normal Distribution. +// Takes array of float64 values. +// Returns array of Mean followed by Standard Deviation. +func NormFit(data []float64) [2]float64 { + sum := 0.00 + for i := 0; i < len(data); i++ { + sum += data[i] + } + mean := sum / float64(len(data)) + stdNumerator := 0.00 + for i := 0; i < len(data); i++ { + stdNumerator += math.Pow(data[i]-mean, 2) + } + return [2]float64{mean, math.Sqrt((stdNumerator) / (float64(len(data))))} +} + +// NormMedian is the median of the distribution. +func NormMedian(loc float64, scale float64) float64 { + return loc +} + +// NormMean is the mean/expected value of the distribution. +func NormMean(loc float64, scale float64) float64 { + return loc +} + +// NormVar is the variance of the distribution. +func NormVar(loc float64, scale float64) float64 { + return math.Pow(scale, 2) +} + +// NormStd is the standard deviation of the distribution. +func NormStd(loc float64, scale float64) float64 { + return scale +} + +// NormInterval finds endpoints of the range that contains alpha percent of the distribution. +func NormInterval(alpha float64, loc float64, scale float64) [2]float64 { + q1 := (1.0 - alpha) / 2 + q2 := (1.0 + alpha) / 2 + a := NormPpf(q1, loc, scale) + b := NormPpf(q2, loc, scale) + return [2]float64{a, b} +} + +// factorial is the naive factorial algorithm. +func factorial(x int) int { + if x == 0 { + return 1 + } + return x * factorial(x-1) +} + +// Ncr is an N choose R algorithm. +// Aaron Cannon's algorithm. +func Ncr(n, r int) int { + if n <= 1 || r == 0 || n == r { + return 1 + } + if newR := n - r; newR < r { + r = newR + } + if r == 1 { + return n + } + ret := int(n - r + 1) + for i, j := ret+1, int(2); j <= r; i, j = i+1, j+1 { + ret = ret * i / j + } + return ret +} diff --git a/vendor/github.com/montanaflynn/stats/outlier.go b/vendor/github.com/montanaflynn/stats/outlier.go index e969180ea7..7c9795bd35 100644 --- a/vendor/github.com/montanaflynn/stats/outlier.go +++ b/vendor/github.com/montanaflynn/stats/outlier.go @@ -9,7 +9,7 @@ type Outliers struct { // QuartileOutliers finds the mild and extreme outliers func QuartileOutliers(input Float64Data) (Outliers, error) { if input.Len() == 0 { - return Outliers{}, EmptyInput + return Outliers{}, EmptyInputErr } // Start by sorting a copy of the slice diff --git a/vendor/github.com/montanaflynn/stats/percentile.go b/vendor/github.com/montanaflynn/stats/percentile.go index baf24d8e36..f5641783ed 100644 --- a/vendor/github.com/montanaflynn/stats/percentile.go +++ b/vendor/github.com/montanaflynn/stats/percentile.go @@ -1,12 +1,18 @@ package stats -import "math" +import ( + "math" +) // Percentile finds the relative standing in a slice of floats func Percentile(input Float64Data, percent float64) (percentile float64, err error) { + length := input.Len() + if length == 0 { + return math.NaN(), EmptyInputErr + } - if input.Len() == 0 { - return math.NaN(), EmptyInput + if length == 1 { + return input[0], nil } if percent <= 0 || percent > 100 { @@ -52,7 +58,7 @@ func PercentileNearestRank(input Float64Data, percent float64) (percentile float // Return an error for empty slices if il == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Return error for less than 0 or greater than 100 percentages diff --git a/vendor/github.com/montanaflynn/stats/quartile.go b/vendor/github.com/montanaflynn/stats/quartile.go index 29bb3a37a3..40bbf6e57b 100644 --- a/vendor/github.com/montanaflynn/stats/quartile.go +++ b/vendor/github.com/montanaflynn/stats/quartile.go @@ -14,7 +14,7 @@ func Quartile(input Float64Data) (Quartiles, error) { il := input.Len() if il == 0 { - return Quartiles{}, EmptyInput + return Quartiles{}, EmptyInputErr } // Start by sorting a copy of the slice @@ -44,7 +44,7 @@ func Quartile(input Float64Data) (Quartiles, error) { // InterQuartileRange finds the range between Q1 and Q3 func InterQuartileRange(input Float64Data) (float64, error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } qs, _ := Quartile(input) iqr := qs.Q3 - qs.Q1 @@ -54,7 +54,7 @@ func InterQuartileRange(input Float64Data) (float64, error) { // Midhinge finds the average of the first and third quartiles func Midhinge(input Float64Data) (float64, error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } qs, _ := Quartile(input) mh := (qs.Q1 + qs.Q3) / 2 @@ -64,7 +64,7 @@ func Midhinge(input Float64Data) (float64, error) { // Trimean finds the average of the median and the midhinge func Trimean(input Float64Data) (float64, error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } c := sortedCopy(input) diff --git a/vendor/github.com/montanaflynn/stats/ranksum.go b/vendor/github.com/montanaflynn/stats/ranksum.go new file mode 100644 index 0000000000..fc424ef4e2 --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/ranksum.go @@ -0,0 +1,183 @@ +package stats + +// import "math" +// +// // WilcoxonRankSum tests the null hypothesis that two sets +// // of data are drawn from the same distribution. It does +// // not handle ties between measurements in x and y. +// // +// // Parameters: +// // data1 Float64Data: First set of data points. +// // data2 Float64Data: Second set of data points. +// // Length of both data samples must be equal. +// // +// // Return: +// // statistic float64: The test statistic under the +// // large-sample approximation that the +// // rank sum statistic is normally distributed. +// // pvalue float64: The two-sided p-value of the test +// // err error: Any error from the input data parameters +// // +// // https://en.wikipedia.org/wiki/Wilcoxon_rank-sum_test +// func WilcoxonRankSum(data1, data2 Float64Data) (float64, float64, error) { +// +// l1 := data1.Len() +// l2 := data2.Len() +// +// if l1 == 0 || l2 == 0 { +// return math.NaN(), math.NaN(), EmptyInputErr +// } +// +// if l1 != l2 { +// return math.NaN(), math.NaN(), SizeErr +// } +// +// alldata := Float64Data{} +// alldata = append(alldata, data1...) +// alldata = append(alldata, data2...) +// +// // ranked := +// +// return 0.0, 0.0, nil +// } +// +// // x, y = map(np.asarray, (x, y)) +// // n1 = len(x) +// // n2 = len(y) +// // alldata = np.concatenate((x, y)) +// // ranked = rankdata(alldata) +// // x = ranked[:n1] +// // s = np.sum(x, axis=0) +// // expected = n1 * (n1+n2+1) / 2.0 +// // z = (s - expected) / np.sqrt(n1*n2*(n1+n2+1)/12.0) +// // prob = 2 * distributions.norm.sf(abs(z)) +// // +// // return RanksumsResult(z, prob) +// +// // def rankdata(a, method='average'): +// // """ +// // Assign ranks to data, dealing with ties appropriately. +// // Ranks begin at 1. The `method` argument controls how ranks are assigned +// // to equal values. See [1]_ for further discussion of ranking methods. +// // Parameters +// // ---------- +// // a : array_like +// // The array of values to be ranked. The array is first flattened. +// // method : str, optional +// // The method used to assign ranks to tied elements. +// // The options are 'average', 'min', 'max', 'dense' and 'ordinal'. +// // 'average': +// // The average of the ranks that would have been assigned to +// // all the tied values is assigned to each value. +// // 'min': +// // The minimum of the ranks that would have been assigned to all +// // the tied values is assigned to each value. (This is also +// // referred to as "competition" ranking.) +// // 'max': +// // The maximum of the ranks that would have been assigned to all +// // the tied values is assigned to each value. +// // 'dense': +// // Like 'min', but the rank of the next highest element is assigned +// // the rank immediately after those assigned to the tied elements. +// // 'ordinal': +// // All values are given a distinct rank, corresponding to the order +// // that the values occur in `a`. +// // The default is 'average'. +// // Returns +// // ------- +// // ranks : ndarray +// // An array of length equal to the size of `a`, containing rank +// // scores. +// // References +// // ---------- +// // .. [1] "Ranking", https://en.wikipedia.org/wiki/Ranking +// // Examples +// // -------- +// // >>> from scipy.stats import rankdata +// // >>> rankdata([0, 2, 3, 2]) +// // array([ 1. , 2.5, 4. , 2.5]) +// // """ +// // +// // arr = np.ravel(np.asarray(a)) +// // algo = 'quicksort' +// // sorter = np.argsort(arr, kind=algo) +// // +// // inv = np.empty(sorter.size, dtype=np.intp) +// // inv[sorter] = np.arange(sorter.size, dtype=np.intp) +// // +// // +// // arr = arr[sorter] +// // obs = np.r_[True, arr[1:] != arr[:-1]] +// // dense = obs.cumsum()[inv] +// // +// // +// // # cumulative counts of each unique value +// // count = np.r_[np.nonzero(obs)[0], len(obs)] +// // +// // # average method +// // return .5 * (count[dense] + count[dense - 1] + 1) +// +// type rankable interface { +// Len() int +// RankEqual(int, int) bool +// } +// +// func StandardRank(d rankable) []float64 { +// r := make([]float64, d.Len()) +// var k int +// for i := range r { +// if i == 0 || !d.RankEqual(i, i-1) { +// k = i + 1 +// } +// r[i] = float64(k) +// } +// return r +// } +// +// func ModifiedRank(d rankable) []float64 { +// r := make([]float64, d.Len()) +// for i := range r { +// k := i + 1 +// for j := i + 1; j < len(r) && d.RankEqual(i, j); j++ { +// k = j + 1 +// } +// r[i] = float64(k) +// } +// return r +// } +// +// func DenseRank(d rankable) []float64 { +// r := make([]float64, d.Len()) +// var k int +// for i := range r { +// if i == 0 || !d.RankEqual(i, i-1) { +// k++ +// } +// r[i] = float64(k) +// } +// return r +// } +// +// func OrdinalRank(d rankable) []float64 { +// r := make([]float64, d.Len()) +// for i := range r { +// r[i] = float64(i + 1) +// } +// return r +// } +// +// func FractionalRank(d rankable) []float64 { +// r := make([]float64, d.Len()) +// for i := 0; i < len(r); { +// var j int +// f := float64(i + 1) +// for j = i + 1; j < len(r) && d.RankEqual(i, j); j++ { +// f += float64(j + 1) +// } +// f /= float64(j - i) +// for ; i < j; i++ { +// r[i] = f +// } +// } +// return r +// } diff --git a/vendor/github.com/montanaflynn/stats/regression.go b/vendor/github.com/montanaflynn/stats/regression.go index a37a740609..401d951201 100644 --- a/vendor/github.com/montanaflynn/stats/regression.go +++ b/vendor/github.com/montanaflynn/stats/regression.go @@ -14,7 +14,7 @@ type Coordinate struct { func LinearRegression(s Series) (regressions Series, err error) { if len(s) == 0 { - return nil, EmptyInput + return nil, EmptyInputErr } // Placeholder for the math to be done @@ -44,19 +44,21 @@ func LinearRegression(s Series) (regressions Series, err error) { } return regressions, nil - } // ExponentialRegression returns an exponential regression on data series func ExponentialRegression(s Series) (regressions Series, err error) { if len(s) == 0 { - return nil, EmptyInput + return nil, EmptyInputErr } var sum [6]float64 for i := 0; i < len(s); i++ { + if s[i].Y < 0 { + return nil, YCoordErr + } sum[0] += s[i].X sum[1] += s[i].Y sum[2] += s[i].X * s[i].X * s[i].Y @@ -77,14 +79,13 @@ func ExponentialRegression(s Series) (regressions Series, err error) { } return regressions, nil - } // LogarithmicRegression returns an logarithmic regression on data series func LogarithmicRegression(s Series) (regressions Series, err error) { if len(s) == 0 { - return nil, EmptyInput + return nil, EmptyInputErr } var sum [4]float64 @@ -109,5 +110,4 @@ func LogarithmicRegression(s Series) (regressions Series, err error) { } return regressions, nil - } diff --git a/vendor/github.com/montanaflynn/stats/sample.go b/vendor/github.com/montanaflynn/stats/sample.go index a52f6dcaaf..40166af6ac 100644 --- a/vendor/github.com/montanaflynn/stats/sample.go +++ b/vendor/github.com/montanaflynn/stats/sample.go @@ -1,12 +1,15 @@ package stats -import "math/rand" +import ( + "math/rand" + "sort" +) // Sample returns sample from input with replacement or without func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) { if input.Len() == 0 { - return nil, EmptyInput + return nil, EmptyInputErr } length := input.Len() @@ -42,3 +45,32 @@ func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) return nil, BoundsErr } + +// StableSample like stable sort, it returns samples from input while keeps the order of original data. +func StableSample(input Float64Data, takenum int) ([]float64, error) { + if input.Len() == 0 { + return nil, EmptyInputErr + } + + length := input.Len() + + if takenum <= length { + + rand.Seed(unixnano()) + + perm := rand.Perm(length) + perm = perm[0:takenum] + // Sort perm before applying + sort.Ints(perm) + result := Float64Data{} + + for _, idx := range perm { + result = append(result, input[idx]) + } + + return result, nil + + } + + return nil, BoundsErr +} diff --git a/vendor/github.com/montanaflynn/stats/sigmoid.go b/vendor/github.com/montanaflynn/stats/sigmoid.go new file mode 100644 index 0000000000..5f2559d81c --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/sigmoid.go @@ -0,0 +1,18 @@ +package stats + +import "math" + +// Sigmoid returns the input values in the range of -1 to 1 +// along the sigmoid or s-shaped curve, commonly used in +// machine learning while training neural networks as an +// activation function. +func Sigmoid(input Float64Data) ([]float64, error) { + if input.Len() == 0 { + return Float64Data{}, EmptyInput + } + s := make([]float64, len(input)) + for i, v := range input { + s[i] = 1 / (1 + math.Exp(-v)) + } + return s, nil +} diff --git a/vendor/github.com/montanaflynn/stats/softmax.go b/vendor/github.com/montanaflynn/stats/softmax.go new file mode 100644 index 0000000000..85072642bc --- /dev/null +++ b/vendor/github.com/montanaflynn/stats/softmax.go @@ -0,0 +1,25 @@ +package stats + +import "math" + +// SoftMax returns the input values in the range of 0 to 1 +// with sum of all the probabilities being equal to one. It +// is commonly used in machine learning neural networks. +func SoftMax(input Float64Data) ([]float64, error) { + if input.Len() == 0 { + return Float64Data{}, EmptyInput + } + + s := 0.0 + c, _ := Max(input) + for _, e := range input { + s += math.Exp(e - c) + } + + sm := make([]float64, len(input)) + for i, v := range input { + sm[i] = math.Exp(v-c) / s + } + + return sm, nil +} diff --git a/vendor/github.com/montanaflynn/stats/sum.go b/vendor/github.com/montanaflynn/stats/sum.go index 53485f17c2..15b611d17a 100644 --- a/vendor/github.com/montanaflynn/stats/sum.go +++ b/vendor/github.com/montanaflynn/stats/sum.go @@ -6,7 +6,7 @@ import "math" func Sum(input Float64Data) (sum float64, err error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Add em up diff --git a/vendor/github.com/montanaflynn/stats/variance.go b/vendor/github.com/montanaflynn/stats/variance.go index 66e60c941f..a6445690d1 100644 --- a/vendor/github.com/montanaflynn/stats/variance.go +++ b/vendor/github.com/montanaflynn/stats/variance.go @@ -6,14 +6,14 @@ import "math" func _variance(input Float64Data, sample int) (variance float64, err error) { if input.Len() == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } // Sum the square of the mean subtracted from each number m, _ := Mean(input) for _, n := range input { - variance += (float64(n) - m) * (float64(n) - m) + variance += (n - m) * (n - m) } // When getting the mean of the squared differences @@ -56,7 +56,7 @@ func Covariance(data1, data2 Float64Data) (float64, error) { l2 := data2.Len() if l1 == 0 || l2 == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } if l1 != l2 { @@ -84,7 +84,7 @@ func CovariancePopulation(data1, data2 Float64Data) (float64, error) { l2 := data2.Len() if l1 == 0 || l2 == 0 { - return math.NaN(), EmptyInput + return math.NaN(), EmptyInputErr } if l1 != l2 { diff --git a/vendor/modules.txt b/vendor/modules.txt index 218e21c5cf..a729add439 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -20,8 +20,8 @@ github.com/klauspost/compress/huff0 github.com/klauspost/compress/internal/snapref github.com/klauspost/compress/zstd github.com/klauspost/compress/zstd/internal/xxhash -# github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe -## explicit +# github.com/montanaflynn/stats v0.7.1 +## explicit; go 1.13 github.com/montanaflynn/stats # github.com/xdg-go/pbkdf2 v1.0.0 ## explicit; go 1.9