diff --git a/.gitignore b/.gitignore index 0bbd4a9..82f1ad5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/docs/ /lib/ /bin/ /.shards/ diff --git a/docs/Statistics.html b/docs/Statistics.html new file mode 100644 index 0000000..84c7d60 --- /dev/null +++ b/docs/Statistics.html @@ -0,0 +1,680 @@ + + + + + + + + + + + + + + Statistics - github.com/lbarasti/statistics + + + + + + + +
+

+ + module Statistics + +

+ + + + + +

+ + + + Overview +

+ +

Basic descriptive statistics functionality.

+ +

More flexible than a scientific-calculator, but not as exhaustive, yet.

+ + + + + + + +

+ + + + Extended Modules +

+ + + + + + + + + +

+ + + + Defined in: +

+ + + + lib/distributions.cr + + +
+ + + + statistics.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ VERSION = "0.1.0" +
+ + +
+ + + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ +
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def describe(values) + + # +
+ +
+ +

Computes several descriptive statistics of the passed array.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def frequency(values : Enumerable(T)) forall T + + # +
+ +
+ +

Computes the number of occurrences of each value in the dataset.

+ +

Returns a Hash with each the dataset values as keys and the number of times they appear as value.

+ +

Parameters

+ +
  • values: a one-dimensional dataset
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def kurtosis(values, corrected = false, excess = false) + + # +
+ +
+ +

Computes the kurtosis of a dataset.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
  • corrected: when set to true, then the calculations are corrected for statistical bias. Default is false.
  • excess: when set to true, computes the excess kurtosis. Default is false.
+ +

This implementation is based on the scipy/stats.py.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def mean(values) + + # +
+ +
+ +

Computes the mean of a dataset.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def median(values, sorted = false) + + # +
+ +
+ +

Computes the median of all elements in a dataset.

+ +

For an even number of elements the mean of the two median elements will be computed.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
  • sorted: when true, the computations assume that the provided values are + sorted. Default is false.
+ +

See Julia's Statistics.median.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def middle(a, b) + + # +
+ +
+ +

Computes the middle of two values a and b.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def middle(values) + + # +
+ +
+ +

Computes the middle of an array a, which consists of finding its +extrema and then computing their mean.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
+ +

See Julia's Statistics.middle.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def mode(values : Enumerable) + + # +
+ +
+ +

Computes the modal (most common) value in a dataset.

+ +

Returns a pair with the modal value and the bin-count for the modal bin. +If there is more than one such value, no guarantees are made which one will be picked.

+ +

NOTE computing the mode requires traversing the entire dataset.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def moment(values, mean = nil, n = 1) + + # +
+ +
+ +

Calculates the n-th moment about the mean for a sample.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
  • #mean: a pre-computed mean. If a mean is not provided, then the sample's + mean will be computed. Default is nil.
  • n: Order of central moment that is returned. Default is 1.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def quantile(values, p, sorted = false) + + # +
+ +
+ +

Computes the quantile of a dataset at a specified probability p on the interval [0,1].

+ +

Quantiles are computed via linear interpolation between the points ((k-1)/(n-1), v[k]), +for k = 1:n where n = values.size.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
  • p: probability. Values of p should be in the interval [0, 1].
  • sorted indicates whether values can be assumed to be sorted.
+ +

Implementation based on Julia's Statistics.quantile.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def skew(values, corrected = false) + + # +
+ +
+ +

Computes the skewness of a dataset.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
  • corrected: when set to true, then the calculations are corrected for statistical bias. Default is false.
+ +

This implementation is based on the scipy/stats.py.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def std(values, mean = nil, corrected = false) + + # +
+ +
+ +

Computes the standard deviation of a dataset.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
  • #mean: a pre-computed #mean. This could be a pre-computed sample's mean + or the population's known mean. If a mean is not provided, then the sample's + mean will be computed. Default is nil.
  • corrected: when set to true, then the sum of squares is scaled + with values.size - 1, rather than with values.size. Default is false.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def var(values, mean = nil, corrected = false) + + # +
+ +
+ +

Computes the variance of a dataset.

+ +

Parameters

+ +
  • values: a one-dimensional dataset.
  • #mean: a pre-computed #mean. This could be a pre-computed sample's mean + or the population's known mean. If a mean is not provided, then the sample's + mean will be computed. Default is nil.
  • corrected: when set to true, then the sum of squares is scaled + with values.size - 1, rather than with values.size. Default is false.
+
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Statistics/Distributions.html b/docs/Statistics/Distributions.html new file mode 100644 index 0000000..763ed2c --- /dev/null +++ b/docs/Statistics/Distributions.html @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + Statistics::Distributions - github.com/lbarasti/statistics + + + + + + + +
+

+ + module Statistics::Distributions + +

+ + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + lib/distributions.cr + + +
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+ + + diff --git a/docs/Statistics/Distributions/Constant.html b/docs/Statistics/Distributions/Constant.html new file mode 100644 index 0000000..c34c673 --- /dev/null +++ b/docs/Statistics/Distributions/Constant.html @@ -0,0 +1,291 @@ + + + + + + + + + + + + + + Statistics::Distributions::Constant - github.com/lbarasti/statistics + + + + + + + +
+

+ + class Statistics::Distributions::Constant + +

+ + + + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + lib/distributions.cr + + +
+ + + + + + +

+ + + + Constructors +

+ + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(rand : Float64) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def rand : Float64 + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def rand=(rand) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Statistics/Distributions/Exponential.html b/docs/Statistics/Distributions/Exponential.html new file mode 100644 index 0000000..3227016 --- /dev/null +++ b/docs/Statistics/Distributions/Exponential.html @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + Statistics::Distributions::Exponential - github.com/lbarasti/statistics + + + + + + + +
+

+ + class Statistics::Distributions::Exponential + +

+ + + + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + lib/distributions.cr + + +
+ + + + + + +

+ + + + Constructors +

+ + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(lambda : Float64) + + # +
+ +
+ +

https://en.wikipedia.org/wiki/Inverse_transform_sampling +https://stackoverflow.com/questions/2106503/pseudorandom-number-generator-exponential-distribution/2106564

+
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def rand + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Statistics/Distributions/Normal.html b/docs/Statistics/Distributions/Normal.html new file mode 100644 index 0000000..41bdf9a --- /dev/null +++ b/docs/Statistics/Distributions/Normal.html @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + Statistics::Distributions::Normal - github.com/lbarasti/statistics + + + + + + + +
+

+ + class Statistics::Distributions::Normal + +

+ + + + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + lib/distributions.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ TWO_PI = 2 * Math::PI +
+ +
+

https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform

+
+ + +
+ + + +

+ + + + Constructors +

+ + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(mean : Float64, std : Float64) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def rand + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Statistics/Distributions/Poisson.html b/docs/Statistics/Distributions/Poisson.html new file mode 100644 index 0000000..9f7b97e --- /dev/null +++ b/docs/Statistics/Distributions/Poisson.html @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + Statistics::Distributions::Poisson - github.com/lbarasti/statistics + + + + + + + +
+

+ + class Statistics::Distributions::Poisson + +

+ + + + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + lib/distributions.cr + + +
+ + + + + + +

+ + + + Constructors +

+ + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(lambda : Float64) + + # +
+ +
+ +

see https://en.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables +https://www.johndcook.com/SimpleRNG.cpp +https://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/

+
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def rand + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Statistics/Distributions/Uniform.html b/docs/Statistics/Distributions/Uniform.html new file mode 100644 index 0000000..8358c99 --- /dev/null +++ b/docs/Statistics/Distributions/Uniform.html @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + Statistics::Distributions::Uniform - github.com/lbarasti/statistics + + + + + + + +
+

+ + class Statistics::Distributions::Uniform + +

+ + + + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + lib/distributions.cr + + +
+ + + + + + +

+ + + + Constructors +

+ + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(min : Float64, max : Float64) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def rand + + # +
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/css/style.css b/docs/css/style.css new file mode 100644 index 0000000..a63baf5 --- /dev/null +++ b/docs/css/style.css @@ -0,0 +1,674 @@ +html, body { + background: #FFFFFF; + position: relative; + margin: 0; + padding: 0; + width: 100%; + height: 100%; + overflow: hidden; +} + +body { + font-family: "Avenir", "Tahoma", "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + color: #333; + line-height: 1.5; +} + +a { + color: #263F6C; +} + +a:visited { + color: #112750; +} + +h1, h2, h3, h4, h5, h6 { + margin: 35px 0 25px; + color: #444444; +} + +h1.type-name { + color: #47266E; + margin: 20px 0 30px; + background-color: #F8F8F8; + padding: 10px 12px; + border: 1px solid #EBEBEB; + border-radius: 2px; +} + +h2 { + border-bottom: 1px solid #E6E6E6; + padding-bottom: 5px; +} + +body { + display: flex; +} + +.sidebar, .main-content { + overflow: auto; +} + +.sidebar { + width: 30em; + color: #F8F4FD; + background-color: #2E1052; + padding: 0 0 30px; + box-shadow: inset -3px 0 4px rgba(0,0,0,.35); + line-height: 1.2; +} + +.sidebar .search-box { + padding: 8px 9px; +} + +.sidebar input { + display: block; + box-sizing: border-box; + margin: 0; + padding: 5px; + font: inherit; + font-family: inherit; + line-height: 1.2; + width: 100%; + border: 0; + outline: 0; + border-radius: 2px; + box-shadow: 0px 3px 5px rgba(0,0,0,.25); + transition: box-shadow .12s; +} + +.sidebar input:focus { + box-shadow: 0px 5px 6px rgba(0,0,0,.5); +} + +.sidebar input::-webkit-input-placeholder { /* Chrome/Opera/Safari */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input::-moz-placeholder { /* Firefox 19+ */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input:-ms-input-placeholder { /* IE 10+ */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input:-moz-placeholder { /* Firefox 18- */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar ul { + margin: 0; + padding: 0; + list-style: none outside; +} + +.sidebar li { + display: block; + position: relative; +} + +.types-list li.hide { + display: none; +} + +.sidebar a { + text-decoration: none; + color: inherit; + transition: color .14s; +} +.types-list a { + display: block; + padding: 5px 15px 5px 30px; +} + +.types-list { + display: block; +} + +.sidebar a:focus { + outline: 1px solid #D1B7F1; +} + +.types-list a { + padding: 5px 15px 5px 30px; +} + +.sidebar .current > a, +.sidebar a:hover { + color: #866BA6; +} + +.repository-links { + padding: 5px 15px 5px 30px; +} + +.types-list li ul { + overflow: hidden; + height: 0; + max-height: 0; + transition: 1s ease-in-out; +} + +.types-list li.parent { + padding-left: 30px; +} + +.types-list li.parent::before { + box-sizing: border-box; + content: "▼"; + display: block; + width: 30px; + height: 30px; + position: absolute; + top: 0; + left: 0; + text-align: center; + color: white; + font-size: 8px; + line-height: 30px; + transform: rotateZ(-90deg); + cursor: pointer; + transition: .2s linear; +} + + +.types-list li.parent > a { + padding-left: 0; +} + +.types-list li.parent.open::before { + transform: rotateZ(0); +} + +.types-list li.open > ul { + height: auto; + max-height: 1000em; +} + +.main-content { + padding: 0 30px 30px 30px; + width: 100%; +} + +.kind { + font-size: 60%; + color: #866BA6; +} + +.superclass-hierarchy { + margin: -15px 0 30px 0; + padding: 0; + list-style: none outside; + font-size: 80%; +} + +.superclass-hierarchy .superclass { + display: inline-block; + margin: 0 7px 0 0; + padding: 0; +} + +.superclass-hierarchy .superclass + .superclass::before { + content: "<"; + margin-right: 7px; +} + +.other-types-list li { + display: inline-block; +} + +.other-types-list, +.list-summary { + margin: 0 0 30px 0; + padding: 0; + list-style: none outside; +} + +.entry-const { + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; +} + +.entry-const code { + white-space: pre-wrap; +} + +.entry-summary { + padding-bottom: 4px; +} + +.superclass-hierarchy .superclass a, +.other-type a, +.entry-summary .signature { + padding: 4px 8px; + margin-bottom: 4px; + display: inline-block; + background-color: #f8f8f8; + color: #47266E; + border: 1px solid #f0f0f0; + text-decoration: none; + border-radius: 3px; + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; + transition: background .15s, border-color .15s; +} + +.superclass-hierarchy .superclass a:hover, +.other-type a:hover, +.entry-summary .signature:hover { + background: #D5CAE3; + border-color: #624288; +} + +.entry-summary .summary { + padding-left: 32px; +} + +.entry-summary .summary p { + margin: 12px 0 16px; +} + +.entry-summary a { + text-decoration: none; +} + +.entry-detail { + padding: 30px 0; +} + +.entry-detail .signature { + position: relative; + padding: 5px 15px; + margin-bottom: 10px; + display: block; + border-radius: 5px; + background-color: #f8f8f8; + color: #47266E; + border: 1px solid #f0f0f0; + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; + transition: .2s ease-in-out; +} + +.entry-detail:target .signature { + background-color: #D5CAE3; + border: 1px solid #624288; +} + +.entry-detail .signature .method-permalink { + position: absolute; + top: 0; + left: -35px; + padding: 5px 15px; + text-decoration: none; + font-weight: bold; + color: #624288; + opacity: .4; + transition: opacity .2s; +} + +.entry-detail .signature .method-permalink:hover { + opacity: 1; +} + +.entry-detail:target .signature .method-permalink { + opacity: 1; +} + +.methods-inherited { + padding-right: 10%; + line-height: 1.5em; +} + +.methods-inherited h3 { + margin-bottom: 4px; +} + +.methods-inherited a { + display: inline-block; + text-decoration: none; + color: #47266E; +} + +.methods-inherited a:hover { + text-decoration: underline; + color: #6C518B; +} + +.methods-inherited .tooltip>span { + background: #D5CAE3; + padding: 4px 8px; + border-radius: 3px; + margin: -4px -8px; +} + +.methods-inherited .tooltip * { + color: #47266E; +} + +pre { + padding: 10px 20px; + margin-top: 4px; + border-radius: 3px; + line-height: 1.45; + overflow: auto; + color: #333; + background: #fdfdfd; + font-size: 14px; + border: 1px solid #eee; +} + +code { + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; +} + +:not(pre) > code { + background-color: rgba(40,35,30,0.05); + padding: 0.2em 0.4em; + font-size: 85%; + border-radius: 3px; +} + +span.flag { + padding: 2px 4px 1px; + border-radius: 3px; + margin-right: 3px; + font-size: 11px; + border: 1px solid transparent; +} + +span.flag.orange { + background-color: #EE8737; + color: #FCEBDD; + border-color: #EB7317; +} + +span.flag.yellow { + background-color: #E4B91C; + color: #FCF8E8; + border-color: #B69115; +} + +span.flag.green { + background-color: #469C14; + color: #E2F9D3; + border-color: #34700E; +} + +span.flag.red { + background-color: #BF1919; + color: #F9ECEC; + border-color: #822C2C; +} + +span.flag.purple { + background-color: #2E1052; + color: #ECE1F9; + border-color: #1F0B37; +} + +.tooltip>span { + position: absolute; + opacity: 0; + display: none; + pointer-events: none; +} + +.tooltip:hover>span { + display: inline-block; + opacity: 1; +} + +.c { + color: #969896; +} + +.n { + color: #0086b3; +} + +.t { + color: #0086b3; +} + +.s { + color: #183691; +} + +.i { + color: #7f5030; +} + +.k { + color: #a71d5d; +} + +.o { + color: #a71d5d; +} + +.m { + color: #795da3; +} + +.hidden { + display: none; +} +.search-results { + font-size: 90%; + line-height: 1.3; +} + +.search-results mark { + color: inherit; + background: transparent; + font-weight: bold; +} +.search-result { + padding: 5px 8px 5px 5px; + cursor: pointer; + border-left: 5px solid transparent; + transform: translateX(-3px); + transition: all .2s, background-color 0s, border .02s; + min-height: 3.2em; +} +.search-result.current { + border-left-color: #ddd; + background-color: rgba(200,200,200,0.4); + transform: translateX(0); + transition: all .2s, background-color .5s, border 0s; +} +.search-result.current:hover, +.search-result.current:focus { + border-left-color: #866BA6; +} +.search-result:not(.current):nth-child(2n) { + background-color: rgba(255,255,255,.06); +} +.search-result__title { + font-size: 105%; + word-break: break-all; + line-height: 1.1; + padding: 3px 0; +} +.search-result__title strong { + font-weight: normal; +} +.search-results .search-result__title > a { + padding: 0; + display: block; +} +.search-result__title > a > .args { + color: #dddddd; + font-weight: 300; + transition: inherit; + font-size: 88%; + line-height: 1.2; + letter-spacing: -.02em; +} +.search-result__title > a > .args * { + color: inherit; +} + +.search-result a, +.search-result a:hover { + color: inherit; +} +.search-result:not(.current):hover .search-result__title > a, +.search-result:not(.current):focus .search-result__title > a, +.search-result__title > a:focus { + color: #866BA6; +} +.search-result:not(.current):hover .args, +.search-result:not(.current):focus .args { + color: #6a5a7d; +} + +.search-result__type { + color: #e8e8e8; + font-weight: 300; +} +.search-result__doc { + color: #bbbbbb; + font-size: 90%; +} +.search-result__doc p { + margin: 0; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + line-height: 1.2em; + max-height: 2.4em; +} + +.js-modal-visible .modal-background { + display: flex; +} +.main-content { + position: relative; +} +.modal-background { + position: absolute; + display: none; + height: 100%; + width: 100%; + background: rgba(120,120,120,.4); + z-index: 100; + align-items: center; + justify-content: center; +} +.usage-modal { + max-width: 90%; + background: #fff; + border: 2px solid #ccc; + border-radius: 9px; + padding: 5px 15px 20px; + min-width: 50%; + color: #555; + position: relative; + transform: scale(.5); + transition: transform 200ms; +} +.js-modal-visible .usage-modal { + transform: scale(1); +} +.usage-modal > .close-button { + position: absolute; + right: 15px; + top: 8px; + color: #aaa; + font-size: 27px; + cursor: pointer; +} +.usage-modal > .close-button:hover { + text-shadow: 2px 2px 2px #ccc; + color: #999; +} +.modal-title { + margin: 0; + text-align: center; + font-weight: normal; + color: #666; + border-bottom: 2px solid #ddd; + padding: 10px; +} +.usage-list { + padding: 0; + margin: 13px; +} +.usage-list > li { + padding: 5px 2px; + overflow: auto; + padding-left: 100px; + min-width: 12em; +} +.usage-modal kbd { + background: #eee; + border: 1px solid #ccc; + border-bottom-width: 2px; + border-radius: 3px; + padding: 3px 8px; + font-family: monospace; + margin-right: 2px; + display: inline-block; +} +.usage-key { + float: left; + clear: left; + margin-left: -100px; + margin-right: 12px; +} +.doc-inherited { + font-weight: bold; +} + +.anchor { + float: left; + padding-right: 4px; + margin-left: -20px; +} + +.main-content .anchor .octicon-link { + width: 16px; + height: 16px; +} + +.main-content .anchor:focus { + outline: none +} + +.main-content h1:hover .anchor, +.main-content h2:hover .anchor, +.main-content h3:hover .anchor, +.main-content h4:hover .anchor, +.main-content h5:hover .anchor, +.main-content h6:hover .anchor { + text-decoration: none +} + +.main-content h1 .octicon-link, +.main-content h2 .octicon-link, +.main-content h3 .octicon-link, +.main-content h4 .octicon-link, +.main-content h5 .octicon-link, +.main-content h6 .octicon-link { + visibility: hidden +} + +.main-content h1:hover .anchor .octicon-link, +.main-content h2:hover .anchor .octicon-link, +.main-content h3:hover .anchor .octicon-link, +.main-content h4:hover .anchor .octicon-link, +.main-content h5:hover .anchor .octicon-link, +.main-content h6:hover .anchor .octicon-link { + visibility: visible +} diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..260313f --- /dev/null +++ b/docs/index.html @@ -0,0 +1,215 @@ + + + + + + + + + + + + + + README - github.com/lbarasti/statistics + + + + + + + +
+

Build Status +License

+ +

+ +statistics

+ +

A statistical library to perform descriptive statistics and generate random values based on popular probability distributions.

+ +

+ +Installation

+ +
  1. Add the dependency to your shard.yml:
+ +
dependencies:
+  statistics:
+    github: lbarasti/statistics
+ +
  1. Run shards install
+ +

+ +Usage

+ +
require "statistics"
+ +

+ +Descriptive statistics

+ +

You can compute mean, variance and standard deviation of a collection as follows.

+ +
include Statistics
+
+x = [1, 10, 7]
+mean(x) # 6
+var(x) # 14
+var(x, corrected: true) # 21
+var(x, mean: 8) # 18.0
+std(x) # 3.7416...
+ +

+ +Sampling

+ +

To work with distributions, import the Distributions namespace as follows.

+ +
include Statistics::Distributions
+ +

Now, here is how we sample values from a normal distribution with mean = 1.5 and std = 0.2.

+ +
Normal.new(1.5, 0.2).rand
+ +

We can generate an iterable of normally distributed random values as follows.

+ +
gen = Normal.new(1.5, 0.2)
+1000.times.map { gen.rand }
+ +

+ +Supported distributions

+ +

The following distributions are supported:

+ + + +

Don't see your favourite one on the list? Just fork the repo, add your distribution to the distributions.cr file, and open a PR.

+ +

+ +Development

+ +

This shard is a work in progress. Everyone's contribution is welcome.

+ +

The guiding principle at this stage is

+ +
make it work before you make it right
+ +

Which in this context means: let's not focus on benchmarks and performance, but rather on usability and correctness.

+ +

+ +References

+ + + +

+ +Contributing

+ +
  1. Fork it (<https://github.com/lbarasti/statistics/fork>)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
+ +

+ +Contributors

+ + +
+ + diff --git a/docs/index.json b/docs/index.json new file mode 100644 index 0000000..c282c0a --- /dev/null +++ b/docs/index.json @@ -0,0 +1 @@ +{"repository_name":"github.com/lbarasti/statistics","body":"![Build Status](https://github.com/lbarasti/statistics/workflows/build/badge.svg)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n# statistics\n\nA statistical library to perform descriptive statistics and generate random values based on popular probability distributions.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n statistics:\n github: lbarasti/statistics\n```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"statistics\"\n```\n\n### Descriptive statistics\nYou can compute mean, variance and standard deviation of a collection as follows.\n```crystal\ninclude Statistics\n\nx = [1, 10, 7]\nmean(x) # 6\nvar(x) # 14\nvar(x, corrected: true) # 21\nvar(x, mean: 8) # 18.0\nstd(x) # 3.7416...\n```\n\n### Sampling\nTo work with distributions, import the `Distributions` namespace as follows.\n```crystal\ninclude Statistics::Distributions\n```\n\nNow, here is how we sample values from a normal distribution with `mean = 1.5` and `std = 0.2`.\n```crystal\nNormal.new(1.5, 0.2).rand\n```\n\nWe can generate an iterable of normally distributed random values as follows.\n```crystal\ngen = Normal.new(1.5, 0.2)\n1000.times.map { gen.rand }\n```\n\n#### Supported distributions\nThe following distributions are supported:\n* Constant\n* Exponential\n* Normal\n* Poisson\n* Uniform\n\nDon't see your favourite one on the list? Just fork the repo, add your distribution to the `distributions.cr` file, and open a PR.\n\n## Development\n\nThis shard is a work in progress. Everyone's contribution is welcome.\n\nThe guiding principle at this stage is\n> make it work before you make it right\n\nWhich in this context means: let's not focus on benchmarks and performance, but rather on usability and correctness.\n\n## References\n* [numpy.random](https://numpy.org/devdocs/reference/random/generator.html): distributions and random sampling\n* [numpy statistics](https://numpy.org/devdocs/reference/routines.statistics.html#averages-and-variances): order statistics, averages and variances\n* [scipy stats](https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py) module and related [tests](https://github.com/scipy/scipy/blob/1150c4c033899a5a4556b7d34d6b137352b36b9e/scipy/stats/tests/test_stats.py) tests\n* [julia random](https://docs.julialang.org/en/v1/stdlib/Random/) module\n* [julia statistics](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.std) module\n* [julia distributions](https://juliastats.org/Distributions.jl/latest/starting/) package.\n* on [skewness and kurtosis](https://brownmath.com/stat/shape.htm), by Stan Brown\n* more on [skewness and kurtosis](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm), from NIST.\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [lbarasti](https://github.com/lbarasti) - creator and maintainer\n","program":{"html_id":"github.com/lbarasti/statistics/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"github.com/lbarasti/statistics","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/lbarasti/statistics/Statistics","path":"Statistics.html","kind":"module","full_name":"Statistics","name":"Statistics","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"lib/distributions.cr","line_number":1,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"},{"filename":"statistics.cr","line_number":6,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"\"0.1.0\"","doc":null,"summary":null}],"included_modules":[],"extended_modules":[{"html_id":"github.com/lbarasti/statistics/Statistics","kind":"module","full_name":"Statistics","name":"Statistics"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Basic descriptive statistics functionality.\n\nMore flexible than a scientific-calculator, but not as exhaustive, yet.","summary":"

Basic descriptive statistics functionality.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"describe(values)-instance-method","html_id":"describe(values)-instance-method","name":"describe","doc":"Computes several descriptive statistics of the passed array.\n\nParameters\n- `values`: a one-dimensional dataset.","summary":"

Computes several descriptive statistics of the passed array.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"args_string":"(values)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L14","def":{"name":"describe","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = values.size\nsorted = values.sort\n{mean: mean(values), var: var(values), std: std(values), skewness: skew(values), kurtosis: kurtosis(values), min: sorted.first, max: sorted.last, q1: quantile(sorted, 0.25, sorted: true), median: median(sorted, sorted: true), middle: middle(sorted), q3: quantile(sorted, 0.75, sorted: true)}\n"}},{"id":"frequency(values:Enumerable(T))forallT-instance-method","html_id":"frequency(values:Enumerable(T))forallT-instance-method","name":"frequency","doc":"Computes the number of occurrences of each value in the dataset.\n\nReturns a Hash with each the dataset values as keys and the number of times they appear as value.\n\nParameters\n- `values`: a one-dimensional dataset","summary":"

Computes the number of occurrences of each value in the dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable(T)"}],"args_string":"(values : Enumerable(T)) forall T","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L38","def":{"name":"frequency","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable(T)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"values.reduce(Hash(T, Int32).new(0)) do |freq, v|\n __temp_24 = v\n freq[__temp_24] = freq[__temp_24] + 1\n freq\nend"}},{"id":"kurtosis(values,corrected=false,excess=false)-instance-method","html_id":"kurtosis(values,corrected=false,excess=false)-instance-method","name":"kurtosis","doc":"Computes the kurtosis of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `corrected`: when set to `true`, then the calculations are corrected for statistical bias. Default is `false`.\n- `excess`: when set to `true`, computes the [excess kurtosis](https://en.wikipedia.org/wiki/Kurtosis#Excess_kurtosis). Default is `false`.\n\nThis implementation is based on the [scipy/stats.py](https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py#L1142).","summary":"

Computes the kurtosis of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""},{"name":"excess","doc":null,"default_value":"false","external_name":"excess","restriction":""}],"args_string":"(values, corrected = false, excess = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L53","def":{"name":"kurtosis","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""},{"name":"excess","doc":null,"default_value":"false","external_name":"excess","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = values.size\nm = mean(values)\nm4 = moment(values, m, 4)\nm2 = moment(values, m, 2)\nkurt = if corrected\n (((1 / (n - 2)) / (n - 3)) * (((((n ** 2) - 1) * m4) / (m2 ** 2)) - (3 * ((n - 1) ** 2)))) + 3\nelse\n m4 / (m2 ** 2)\nend\nexcess ? kurt - 3 : kurt\n"}},{"id":"mean(values)-instance-method","html_id":"mean(values)-instance-method","name":"mean","doc":"Computes the mean of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.","summary":"

Computes the mean of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"args_string":"(values)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L72","def":{"name":"mean","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(values.reduce(0) do |acc, v|\n acc + v\nend) / values.size"}},{"id":"median(values,sorted=false)-instance-method","html_id":"median(values,sorted=false)-instance-method","name":"median","doc":"Computes the median of all elements in a dataset.\n\nFor an even number of elements the mean of the two median elements will be computed.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `sorted`: when `true`, the computations assume that the provided values are\n sorted. Default is `false`.\n\nSee Julia's [Statistics.median](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.median).","summary":"

Computes the median of all elements in a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"args_string":"(values, sorted = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L86","def":{"name":"median","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = values.size\nmid = size // 2\nsorted_values = sorted ? values : values.sort\nif size.odd?\n sorted_values[mid]\nelse\n middle([sorted_values[mid - 1], sorted_values[mid]])\nend\n"}},{"id":"middle(a,b)-instance-method","html_id":"middle(a,b)-instance-method","name":"middle","doc":"Computes the middle of two values `a` and `b`.","summary":"

Computes the middle of two values a and b.

","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L111","def":{"name":"middle","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"0.5 * (a + b)"}},{"id":"middle(values)-instance-method","html_id":"middle(values)-instance-method","name":"middle","doc":"Computes the middle of an array `a`, which consists of finding its\nextrema and then computing their mean.\n\nParameters\n- `values`: a one-dimensional dataset.\n\nSee Julia's [Statistics.middle](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.middle).","summary":"

Computes the middle of an array a, which consists of finding its extrema and then computing their mean.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"args_string":"(values)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L105","def":{"name":"middle","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"min, max = values.minmax\nmiddle(min, max)\n"}},{"id":"mode(values:Enumerable)-instance-method","html_id":"mode(values:Enumerable)-instance-method","name":"mode","doc":"Computes the modal (most common) value in a dataset.\n\nReturns a pair with the modal value and the bin-count for the modal bin.\nIf there is more than one such value, no guarantees are made which one will be picked.\nNOTE: computing the mode requires traversing the entire dataset.\n\nParameters\n- `values`: a one-dimensional dataset.","summary":"

Computes the modal (most common) value in a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable"}],"args_string":"(values : Enumerable)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L123","def":{"name":"mode","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(frequency(values)).max_by(&.last)"}},{"id":"moment(values,mean=nil,n=1)-instance-method","html_id":"moment(values,mean=nil,n=1)-instance-method","name":"moment","doc":"Calculates the n-th moment about the mean for a sample.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `mean`: a pre-computed mean. If a mean is not provided, then the sample's\n mean will be computed. Default is `nil`.\n- `n`: Order of central moment that is returned. Default is `1`.","summary":"

Calculates the n-th moment about the mean for a sample.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"n","doc":null,"default_value":"1","external_name":"n","restriction":""}],"args_string":"(values, mean = nil, n = 1)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L134","def":{"name":"moment","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"n","doc":null,"default_value":"1","external_name":"n","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m = mean || (Statistics.mean(values))\n(values.reduce(0) do |a, b|\n a + ((b - m) ** n)\nend) / values.size\n"}},{"id":"quantile(values,p,sorted=false)-instance-method","html_id":"quantile(values,p,sorted=false)-instance-method","name":"quantile","doc":"Computes the quantile of a dataset at a specified probability `p` on the interval [0,1].\n\nQuantiles are computed via linear interpolation between the points `((k-1)/(n-1), v[k])`,\nfor `k = 1:n` where `n = values.size`.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `p`: probability. Values of `p` should be in the interval `[0, 1]`.\n- `sorted` indicates whether `values` can be assumed to be sorted.\n\nImplementation based on Julia's [Statistics.quantile](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.quantile).","summary":"

Computes the quantile of a dataset at a specified probability p on the interval [0,1].

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"args_string":"(values, p, sorted = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L150","def":{"name":"quantile","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sorted_values = sorted ? values : values.sort\nn = values.size\naleph = (n - 1) * p\nj = (clamp(aleph.floor, 0, n - 2)).to_i\ngamma = clamp(aleph - j, 0, 1)\na = sorted_values[j]\nb = sorted_values[j + 1]\na + ((b - a) * gamma)\n"}},{"id":"skew(values,corrected=false)-instance-method","html_id":"skew(values,corrected=false)-instance-method","name":"skew","doc":"Computes the skewness of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `corrected`: when set to `true`, then the calculations are corrected for statistical bias. Default is `false`.\n\nThis implementation is based on the [scipy/stats.py](https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py#L1039).","summary":"

Computes the skewness of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"args_string":"(values, corrected = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L170","def":{"name":"skew","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = values.size\nm = mean(values)\nm3 = moment(values, m, 3)\nm2 = moment(values, m, 2)\ncorrection_factor = corrected ? (Math.sqrt((n - 1.0) * n)) / (n - 2.0) : 1\n(correction_factor * m3) / (m2 ** 1.5)\n"}},{"id":"std(values,mean=nil,corrected=false)-instance-method","html_id":"std(values,mean=nil,corrected=false)-instance-method","name":"std","doc":"Computes the standard deviation of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `mean`: a pre-computed `mean`. This could be a pre-computed sample's mean\n or the population's known mean. If a mean is not provided, then the sample's\n mean will be computed. Default is `nil`.\n- `corrected`: when set to `true`, then the sum of squares is scaled\n with `values.size - 1`, rather than with `values.size`. Default is `false`.","summary":"

Computes the standard deviation of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"args_string":"(values, mean = nil, corrected = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L188","def":{"name":"std","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Math.sqrt(var(values, mean, corrected))"}},{"id":"var(values,mean=nil,corrected=false)-instance-method","html_id":"var(values,mean=nil,corrected=false)-instance-method","name":"var","doc":"Computes the variance of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `mean`: a pre-computed `mean`. This could be a pre-computed sample's mean\n or the population's known mean. If a mean is not provided, then the sample's\n mean will be computed. Default is `nil`.\n- `corrected`: when set to `true`, then the sum of squares is scaled\n with `values.size - 1`, rather than with `values.size`. Default is `false`.","summary":"

Computes the variance of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"args_string":"(values, mean = nil, corrected = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L201","def":{"name":"var","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"correction_factor = corrected ? values.size / (values.size - 1) : 1\n(moment(values, mean, 2)) * correction_factor\n"}}],"macros":[],"types":[{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","path":"Statistics/Distributions.html","kind":"module","full_name":"Statistics::Distributions","name":"Distributions","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"lib/distributions.cr","line_number":2,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics","kind":"module","full_name":"Statistics","name":"Statistics"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Constant","path":"Statistics/Distributions/Constant.html","kind":"class","full_name":"Statistics::Distributions::Constant","name":"Constant","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":3,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(rand:Float64)-class-method","html_id":"new(rand:Float64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":"Float64"}],"args_string":"(rand : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L6","def":{"name":"new","args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(rand)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand:Float64-instance-method","html_id":"rand:Float64-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Float64","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L4","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rand"}},{"id":"rand=(rand)-instance-method","html_id":"rand=(rand)-instance-method","name":"rand=","doc":null,"summary":null,"abstract":false,"args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":""}],"args_string":"(rand)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L4","def":{"name":"rand=","args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rand = rand"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Exponential","path":"Statistics/Distributions/Exponential.html","kind":"class","full_name":"Statistics::Distributions::Exponential","name":"Exponential","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":10,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(lambda:Float64)-class-method","html_id":"new(lambda:Float64)-class-method","name":"new","doc":"https://en.wikipedia.org/wiki/Inverse_transform_sampling\nhttps://stackoverflow.com/questions/2106503/pseudorandom-number-generator-exponential-distribution/2106564","summary":"

https://en.wikipedia.org/wiki/Inverse_transform_sampling https://stackoverflow.com/questions/2106503/pseudorandom-number-generator-exponential-distribution/2106564

","abstract":false,"args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"args_string":"(lambda : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L13","def":{"name":"new","args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(lambda)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L16","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(-(Math.log(::rand))) / @lambda"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Normal","path":"Statistics/Distributions/Normal.html","kind":"class","full_name":"Statistics::Distributions::Normal","name":"Normal","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":21,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"TWO_PI","name":"TWO_PI","value":"2 * Math::PI","doc":"https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform","summary":"

https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform

"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(mean:Float64,std:Float64)-class-method","html_id":"new(mean:Float64,std:Float64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"mean","doc":null,"default_value":"","external_name":"mean","restriction":"Float64"},{"name":"std","doc":null,"default_value":"","external_name":"std","restriction":"Float64"}],"args_string":"(mean : Float64, std : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L25","def":{"name":"new","args":[{"name":"mean","doc":null,"default_value":"","external_name":"mean","restriction":"Float64"},{"name":"std","doc":null,"default_value":"","external_name":"std","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(mean, std)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L28","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = (Math.sqrt(-2 * (Math.log(::rand)))) * (Math.sin(TWO_PI * ::rand))\n(v * @std) + @mean\n"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Poisson","path":"Statistics/Distributions/Poisson.html","kind":"class","full_name":"Statistics::Distributions::Poisson","name":"Poisson","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":34,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(lambda:Float64)-class-method","html_id":"new(lambda:Float64)-class-method","name":"new","doc":"see https://en.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables\nhttps://www.johndcook.com/SimpleRNG.cpp\nhttps://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/","summary":"

see https://en.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables https://www.johndcook.com/SimpleRNG.cpp https://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/

","abstract":false,"args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"args_string":"(lambda : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L38","def":{"name":"new","args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(lambda)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L41","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x = 0\np = Math.exp(-@lambda)\ns = p\nu = ::rand\nwhile u > s\n x = x + 1\n p = p * (@lambda / x)\n s = s + p\nend\nx\n"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Uniform","path":"Statistics/Distributions/Uniform.html","kind":"class","full_name":"Statistics::Distributions::Uniform","name":"Uniform","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":55,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(min:Float64,max:Float64)-class-method","html_id":"new(min:Float64,max:Float64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Float64"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Float64"}],"args_string":"(min : Float64, max : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L58","def":{"name":"new","args":[{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Float64"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(min, max)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L62","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@min + (::rand * @interval)"}}],"macros":[],"types":[]}]}]}]}} \ No newline at end of file diff --git a/docs/js/doc.js b/docs/js/doc.js new file mode 100644 index 0000000..8796e74 --- /dev/null +++ b/docs/js/doc.js @@ -0,0 +1,1019 @@ +window.CrystalDoc = (window.CrystalDoc || {}); + +CrystalDoc.base_path = (CrystalDoc.base_path || ""); + +CrystalDoc.searchIndex = (CrystalDoc.searchIndex || false); +CrystalDoc.MAX_RESULTS_DISPLAY = 140; + +CrystalDoc.runQuery = function(query) { + function searchType(type, query, results) { + var matches = []; + var matchedFields = []; + var name = type.full_name; + var i = name.lastIndexOf("::"); + if (i > 0) { + name = name.substring(i + 2); + } + var nameMatches = query.matches(name); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + + var namespaceMatches = query.matchesNamespace(type.full_name); + if(namespaceMatches){ + matches = matches.concat(namespaceMatches); + matchedFields.push("name"); + } + + var docMatches = query.matches(type.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + if (matches.length > 0) { + results.push({ + id: type.id, + result_type: "type", + kind: type.kind, + name: name, + full_name: type.full_name, + href: type.path, + summary: type.summary, + matched_fields: matchedFields, + matched_terms: matches + }); + } + + type.instance_methods.forEach(function(method) { + searchMethod(method, type, "instance_method", query, results); + }) + type.class_methods.forEach(function(method) { + searchMethod(method, type, "class_method", query, results); + }) + type.constructors.forEach(function(constructor) { + searchMethod(constructor, type, "constructor", query, results); + }) + type.macros.forEach(function(macro) { + searchMethod(macro, type, "macro", query, results); + }) + type.constants.forEach(function(constant){ + searchConstant(constant, type, query, results); + }); + + type.types.forEach(function(subtype){ + searchType(subtype, query, results); + }); + }; + + function searchMethod(method, type, kind, query, results) { + var matches = []; + var matchedFields = []; + var nameMatches = query.matchesMethod(method.name, kind, type); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + + method.args.forEach(function(arg){ + var argMatches = query.matches(arg.external_name); + if (argMatches) { + matches = matches.concat(argMatches); + matchedFields.push("args"); + } + }); + + var docMatches = query.matches(type.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + + if (matches.length > 0) { + var typeMatches = query.matches(type.full_name); + if (typeMatches) { + matchedFields.push("type"); + matches = matches.concat(typeMatches); + } + results.push({ + id: method.id, + type: type.full_name, + result_type: kind, + name: method.name, + full_name: type.full_name + "#" + method.name, + args_string: method.args_string, + summary: method.summary, + href: type.path + "#" + method.id, + matched_fields: matchedFields, + matched_terms: matches + }); + } + } + + function searchConstant(constant, type, query, results) { + var matches = []; + var matchedFields = []; + var nameMatches = query.matches(constant.name); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + var docMatches = query.matches(constant.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + if (matches.length > 0) { + var typeMatches = query.matches(type.full_name); + if (typeMatches) { + matchedFields.push("type"); + matches = matches.concat(typeMatches); + } + results.push({ + id: constant.id, + type: type.full_name, + result_type: "constant", + name: constant.name, + full_name: type.full_name + "#" + constant.name, + value: constant.value, + summary: constant.summary, + href: type.path + "#" + constant.id, + matched_fields: matchedFields, + matched_terms: matches + }); + } + } + + var results = []; + searchType(CrystalDoc.searchIndex.program, query, results); + return results; +}; + +CrystalDoc.rankResults = function(results, query) { + function uniqueArray(ar) { + var j = {}; + + ar.forEach(function(v) { + j[v + "::" + typeof v] = v; + }); + + return Object.keys(j).map(function(v) { + return j[v]; + }); + } + + results = results.sort(function(a, b) { + var matchedTermsDiff = uniqueArray(b.matched_terms).length - uniqueArray(a.matched_terms).length; + var aHasDocs = b.matched_fields.includes("doc"); + var bHasDocs = b.matched_fields.includes("doc"); + + var aOnlyDocs = aHasDocs && a.matched_fields.length == 1; + var bOnlyDocs = bHasDocs && b.matched_fields.length == 1; + + if (a.result_type == "type" && b.result_type != "type" && !aOnlyDocs) { + if(CrystalDoc.DEBUG) { console.log("a is type b not"); } + return -1; + } else if (b.result_type == "type" && a.result_type != "type" && !bOnlyDocs) { + if(CrystalDoc.DEBUG) { console.log("b is type, a not"); } + return 1; + } + if (a.matched_fields.includes("name")) { + if (b.matched_fields.includes("name")) { + var a_name = (CrystalDoc.prefixForType(a.result_type) || "") + ((a.result_type == "type") ? a.full_name : a.name); + var b_name = (CrystalDoc.prefixForType(b.result_type) || "") + ((b.result_type == "type") ? b.full_name : b.name); + a_name = a_name.toLowerCase(); + b_name = b_name.toLowerCase(); + for(var i = 0; i < query.normalizedTerms.length; i++) { + var term = query.terms[i].replace(/^::?|::?$/, ""); + var a_orig_index = a_name.indexOf(term); + var b_orig_index = b_name.indexOf(term); + if(CrystalDoc.DEBUG) { console.log("term: " + term + " a: " + a_name + " b: " + b_name); } + if(CrystalDoc.DEBUG) { console.log(a_orig_index, b_orig_index, a_orig_index - b_orig_index); } + if (a_orig_index >= 0) { + if (b_orig_index >= 0) { + if(CrystalDoc.DEBUG) { console.log("both have exact match", a_orig_index > b_orig_index ? -1 : 1); } + if(a_orig_index != b_orig_index) { + if(CrystalDoc.DEBUG) { console.log("both have exact match at different positions", a_orig_index > b_orig_index ? 1 : -1); } + return a_orig_index > b_orig_index ? 1 : -1; + } + } else { + if(CrystalDoc.DEBUG) { console.log("a has exact match, b not"); } + return -1; + } + } else if (b_orig_index >= 0) { + if(CrystalDoc.DEBUG) { console.log("b has exact match, a not"); } + return 1; + } + } + } else { + if(CrystalDoc.DEBUG) { console.log("a has match in name, b not"); } + return -1; + } + } else if ( + !a.matched_fields.includes("name") && + b.matched_fields.includes("name") + ) { + return 1; + } + + if (matchedTermsDiff != 0 || (aHasDocs != bHasDocs)) { + if(CrystalDoc.DEBUG) { console.log("matchedTermsDiff: " + matchedTermsDiff, aHasDocs, bHasDocs); } + return matchedTermsDiff; + } + + var matchedFieldsDiff = b.matched_fields.length - a.matched_fields.length; + if (matchedFieldsDiff != 0) { + if(CrystalDoc.DEBUG) { console.log("matched to different number of fields: " + matchedFieldsDiff); } + return matchedFieldsDiff > 0 ? 1 : -1; + } + + var nameCompare = a.name.localeCompare(b.name); + if(nameCompare != 0){ + if(CrystalDoc.DEBUG) { console.log("nameCompare resulted in: " + a.name + "<=>" + b.name + ": " + nameCompare); } + return nameCompare > 0 ? 1 : -1; + } + + if(a.matched_fields.includes("args") && b.matched_fields.includes("args")) { + for(var i = 0; i < query.terms.length; i++) { + var term = query.terms[i]; + var aIndex = a.args_string.indexOf(term); + var bIndex = b.args_string.indexOf(term); + if(CrystalDoc.DEBUG) { console.log("index of " + term + " in args_string: " + aIndex + " - " + bIndex); } + if(aIndex >= 0){ + if(bIndex >= 0){ + if(aIndex != bIndex){ + return aIndex > bIndex ? 1 : -1; + } + }else{ + return -1; + } + }else if(bIndex >= 0) { + return 1; + } + } + } + + return 0; + }); + + if (results.length > 1) { + // if we have more than two search terms, only include results with the most matches + var bestMatchedTerms = uniqueArray(results[0].matched_terms).length; + + results = results.filter(function(result) { + return uniqueArray(result.matched_terms).length + 1 >= bestMatchedTerms; + }); + } + return results; +}; + +CrystalDoc.prefixForType = function(type) { + switch (type) { + case "instance_method": + return "#"; + + case "class_method": + case "macro": + case "constructor": + return "."; + + default: + return false; + } +}; + +CrystalDoc.displaySearchResults = function(results, query) { + function sanitize(html){ + return html.replace(/<(?!\/?code)[^>]+>/g, ""); + } + + // limit results + if (results.length > CrystalDoc.MAX_RESULTS_DISPLAY) { + results = results.slice(0, CrystalDoc.MAX_RESULTS_DISPLAY); + } + + var $frag = document.createDocumentFragment(); + var $resultsElem = document.querySelector(".search-list"); + $resultsElem.innerHTML = ""; + + results.forEach(function(result, i) { + var url = CrystalDoc.base_path + result.href; + var type = false; + + var title = query.highlight(result.result_type == "type" ? result.full_name : result.name); + + var prefix = CrystalDoc.prefixForType(result.result_type); + if (prefix) { + title = "" + prefix + "" + title; + } + + title = "" + title + ""; + + if (result.args_string) { + title += + "" + query.highlight(result.args_string) + ""; + } + + $elem = document.createElement("li"); + $elem.className = "search-result search-result--" + result.result_type; + $elem.dataset.href = url; + $elem.setAttribute("title", result.full_name + " docs page"); + + var $title = document.createElement("div"); + $title.setAttribute("class", "search-result__title"); + var $titleLink = document.createElement("a"); + $titleLink.setAttribute("href", url); + + $titleLink.innerHTML = title; + $title.appendChild($titleLink); + $elem.appendChild($title); + $elem.addEventListener("click", function() { + $titleLink.click(); + }); + + if (result.result_type !== "type") { + var $type = document.createElement("div"); + $type.setAttribute("class", "search-result__type"); + $type.innerHTML = query.highlight(result.type); + $elem.appendChild($type); + } + + if(result.summary){ + var $doc = document.createElement("div"); + $doc.setAttribute("class", "search-result__doc"); + $doc.innerHTML = query.highlight(sanitize(result.summary)); + $elem.appendChild($doc); + } + + $elem.appendChild(document.createComment(JSON.stringify(result))); + $frag.appendChild($elem); + }); + + $resultsElem.appendChild($frag); + + CrystalDoc.toggleResultsList(true); +}; + +CrystalDoc.toggleResultsList = function(visible) { + if (visible) { + document.querySelector(".types-list").classList.add("hidden"); + document.querySelector(".search-results").classList.remove("hidden"); + } else { + document.querySelector(".types-list").classList.remove("hidden"); + document.querySelector(".search-results").classList.add("hidden"); + } +}; + +CrystalDoc.Query = function(string) { + this.original = string; + this.terms = string.split(/\s+/).filter(function(word) { + return CrystalDoc.Query.stripModifiers(word).length > 0; + }); + + var normalized = this.terms.map(CrystalDoc.Query.normalizeTerm); + this.normalizedTerms = normalized; + + function runMatcher(field, matcher) { + if (!field) { + return false; + } + var normalizedValue = CrystalDoc.Query.normalizeTerm(field); + + var matches = []; + normalized.forEach(function(term) { + if (matcher(normalizedValue, term)) { + matches.push(term); + } + }); + return matches.length > 0 ? matches : false; + } + + this.matches = function(field) { + return runMatcher(field, function(normalized, term) { + if (term[0] == "#" || term[0] == ".") { + return false; + } + return normalized.indexOf(term) >= 0; + }); + }; + + function namespaceMatcher(normalized, term){ + var i = term.indexOf(":"); + if(i >= 0){ + term = term.replace(/^::?|::?$/, ""); + var index = normalized.indexOf(term); + if((index == 0) || (index > 0 && normalized[index-1] == ":")){ + return true; + } + } + return false; + } + this.matchesMethod = function(name, kind, type) { + return runMatcher(name, function(normalized, term) { + var i = term.indexOf("#"); + if(i >= 0){ + if (kind != "instance_method") { + return false; + } + }else{ + i = term.indexOf("."); + if(i >= 0){ + if (kind != "class_method" && kind != "macro" && kind != "constructor") { + return false; + } + }else{ + //neither # nor . + if(term.indexOf(":") && namespaceMatcher(normalized, term)){ + return true; + } + } + } + + var methodName = term; + if(i >= 0){ + var termType = term.substring(0, i); + methodName = term.substring(i+1); + + if(termType != "") { + if(CrystalDoc.Query.normalizeTerm(type.full_name).indexOf(termType) < 0){ + return false; + } + } + } + return normalized.indexOf(methodName) >= 0; + }); + }; + + this.matchesNamespace = function(namespace){ + return runMatcher(namespace, namespaceMatcher); + }; + + this.highlight = function(string) { + if (typeof string == "undefined") { + return ""; + } + function escapeRegExp(s) { + return s.replace(/[.*+?\^${}()|\[\]\\]/g, "\\$&").replace(/^[#\.:]+/, ""); + } + return string.replace( + new RegExp("(" + this.normalizedTerms.map(escapeRegExp).join("|") + ")", "gi"), + "$1" + ); + }; +}; +CrystalDoc.Query.normalizeTerm = function(term) { + return term.toLowerCase(); +}; +CrystalDoc.Query.stripModifiers = function(term) { + switch (term[0]) { + case "#": + case ".": + case ":": + return term.substr(1); + + default: + return term; + } +} + +CrystalDoc.search = function(string) { + if(!CrystalDoc.searchIndex) { + console.log("CrystalDoc search index not initialized, delaying search"); + + document.addEventListener("CrystalDoc:loaded", function listener(){ + document.removeEventListener("CrystalDoc:loaded", listener); + CrystalDoc.search(string); + }); + return; + } + + document.dispatchEvent(new Event("CrystalDoc:searchStarted")); + + var query = new CrystalDoc.Query(string); + var results = CrystalDoc.runQuery(query); + results = CrystalDoc.rankResults(results, query); + CrystalDoc.displaySearchResults(results, query); + + document.dispatchEvent(new Event("CrystalDoc:searchPerformed")); +}; + +CrystalDoc.initializeIndex = function(data) { + CrystalDoc.searchIndex = data; + + document.dispatchEvent(new Event("CrystalDoc:loaded")); +}; + +CrystalDoc.loadIndex = function() { + function loadJSON(file, callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open("GET", file, true); + xobj.onreadystatechange = function() { + if (xobj.readyState == 4 && xobj.status == "200") { + callback(xobj.responseText); + } + }; + xobj.send(null); + } + + function loadScript(file) { + script = document.createElement("script"); + script.src = file; + document.body.appendChild(script); + } + + function parseJSON(json) { + CrystalDoc.initializeIndex(JSON.parse(json)); + } + + for(var i = 0; i < document.scripts.length; i++){ + var script = document.scripts[i]; + if (script.src && script.src.indexOf("js/doc.js") >= 0) { + if (script.src.indexOf("file://") == 0) { + // We need to support JSONP files for the search to work on local file system. + var jsonPath = script.src.replace("js/doc.js", "search-index.js"); + loadScript(jsonPath); + return; + } else { + var jsonPath = script.src.replace("js/doc.js", "index.json"); + loadJSON(jsonPath, parseJSON); + return; + } + } + } + console.error("Could not find location of js/doc.js"); +}; + +// Callback for jsonp +function crystal_doc_search_index_callback(data) { + CrystalDoc.initializeIndex(data); +} + +Navigator = function(sidebar, searchInput, list, leaveSearchScope){ + this.list = list; + var self = this; + + var performingSearch = false; + + document.addEventListener('CrystalDoc:searchStarted', function(){ + performingSearch = true; + }); + document.addEventListener('CrystalDoc:searchDebounceStarted', function(){ + performingSearch = true; + }); + document.addEventListener('CrystalDoc:searchPerformed', function(){ + performingSearch = false; + }); + document.addEventListener('CrystalDoc:searchDebounceStopped', function(event){ + performingSearch = false; + }); + + function delayWhileSearching(callback) { + if(performingSearch){ + document.addEventListener('CrystalDoc:searchPerformed', function listener(){ + document.removeEventListener('CrystalDoc:searchPerformed', listener); + + // add some delay to let search results display kick in + setTimeout(callback, 100); + }); + }else{ + callback(); + } + } + + function clearMoveTimeout() { + clearTimeout(self.moveTimeout); + self.moveTimeout = null; + } + + function startMoveTimeout(upwards){ + /*if(self.moveTimeout) { + clearMoveTimeout(); + } + + var go = function() { + if (!self.moveTimeout) return; + self.move(upwards); + self.moveTimout = setTimeout(go, 600); + }; + self.moveTimeout = setTimeout(go, 800);*/ + } + + function scrollCenter(element) { + var rect = element.getBoundingClientRect(); + var middle = sidebar.clientHeight / 2; + sidebar.scrollTop += rect.top + rect.height / 2 - middle; + } + + var move = this.move = function(upwards){ + if(!this.current){ + this.highlightFirst(); + return true; + } + var next = upwards ? this.current.previousElementSibling : this.current.nextElementSibling; + if(next && next.classList) { + this.highlight(next); + scrollCenter(next); + return true; + } + return false; + }; + + this.moveRight = function(){ + }; + this.moveLeft = function(){ + }; + + this.highlight = function(elem) { + if(!elem){ + return; + } + this.removeHighlight(); + + this.current = elem; + this.current.classList.add("current"); + }; + + this.highlightFirst = function(){ + this.highlight(this.list.querySelector('li:first-child')); + }; + + this.removeHighlight = function() { + if(this.current){ + this.current.classList.remove("current"); + } + this.current = null; + } + + this.openSelectedResult = function() { + if(this.current) { + this.current.click(); + } + } + + this.focus = function() { + searchInput.focus(); + searchInput.select(); + this.highlightFirst(); + } + + function handleKeyUp(event) { + switch(event.key) { + case "ArrowUp": + case "ArrowDown": + case "i": + case "j": + case "k": + case "l": + case "c": + case "h": + case "t": + case "n": + event.stopPropagation(); + clearMoveTimeout(); + } + } + + function handleKeyDown(event) { + switch(event.key) { + case "Enter": + event.stopPropagation(); + event.preventDefault(); + leaveSearchScope(); + self.openSelectedResult(); + break; + case "Escape": + event.stopPropagation(); + event.preventDefault(); + leaveSearchScope(); + break; + case "j": + case "c": + case "ArrowUp": + if(event.ctrlKey || event.key == "ArrowUp") { + event.stopPropagation(); + self.move(true); + startMoveTimeout(true); + } + break; + case "k": + case "h": + case "ArrowDown": + if(event.ctrlKey || event.key == "ArrowDown") { + event.stopPropagation(); + self.move(false); + startMoveTimeout(false); + } + break; + case "k": + case "t": + case "ArrowLeft": + if(event.ctrlKey || event.key == "ArrowLeft") { + event.stopPropagation(); + self.moveLeft(); + } + break; + case "l": + case "n": + case "ArrowRight": + if(event.ctrlKey || event.key == "ArrowRight") { + event.stopPropagation(); + self.moveRight(); + } + break; + } + } + + function handleInputKeyUp(event) { + switch(event.key) { + case "ArrowUp": + case "ArrowDown": + event.stopPropagation(); + event.preventDefault(); + clearMoveTimeout(); + } + } + + function handleInputKeyDown(event) { + switch(event.key) { + case "Enter": + event.stopPropagation(); + event.preventDefault(); + delayWhileSearching(function(){ + self.openSelectedResult(); + leaveSearchScope(); + }); + break; + case "Escape": + event.stopPropagation(); + event.preventDefault(); + // remove focus from search input + leaveSearchScope(); + sidebar.focus(); + break; + case "ArrowUp": + event.stopPropagation(); + event.preventDefault(); + self.move(true); + startMoveTimeout(true); + break; + + case "ArrowDown": + event.stopPropagation(); + event.preventDefault(); + self.move(false); + startMoveTimeout(false); + break; + } + } + + sidebar.tabIndex = 100; // set tabIndex to enable keylistener + sidebar.addEventListener('keyup', function(event) { + handleKeyUp(event); + }); + sidebar.addEventListener('keydown', function(event) { + handleKeyDown(event); + }); + searchInput.addEventListener('keydown', function(event) { + handleInputKeyDown(event); + }); + searchInput.addEventListener('keyup', function(event) { + handleInputKeyUp(event); + }); + this.move(); +}; + +var UsageModal = function(title, content) { + var $body = document.body; + var self = this; + var $modalBackground = document.createElement("div"); + $modalBackground.classList.add("modal-background"); + var $usageModal = document.createElement("div"); + $usageModal.classList.add("usage-modal"); + $modalBackground.appendChild($usageModal); + var $title = document.createElement("h3"); + $title.classList.add("modal-title"); + $title.innerHTML = title + $usageModal.appendChild($title); + var $closeButton = document.createElement("span"); + $closeButton.classList.add("close-button"); + $closeButton.setAttribute("title", "Close modal"); + $closeButton.innerText = '×'; + $usageModal.appendChild($closeButton); + $usageModal.insertAdjacentHTML("beforeend", content); + + $modalBackground.addEventListener('click', function(event) { + var element = event.target || event.srcElement; + + if(element == $modalBackground) { + self.hide(); + } + }); + $closeButton.addEventListener('click', function(event) { + self.hide(); + }); + + $body.insertAdjacentElement('beforeend', $modalBackground); + + this.show = function(){ + $body.classList.add("js-modal-visible"); + }; + this.hide = function(){ + $body.classList.remove("js-modal-visible"); + }; + this.isVisible = function(){ + return $body.classList.contains("js-modal-visible"); + } +} + + +document.addEventListener('DOMContentLoaded', function() { + var sessionStorage; + try { + sessionStorage = window.sessionStorage; + } catch (e) { } + if(!sessionStorage) { + sessionStorage = { + setItem: function() {}, + getItem: function() {}, + removeItem: function() {} + }; + } + + var repositoryName = document.querySelector('#repository-name').getAttribute('content'); + var typesList = document.querySelector('.types-list'); + var searchInput = document.querySelector('.search-input'); + var parents = document.querySelectorAll('.types-list li.parent'); + + var scrollSidebarToOpenType = function(){ + var openTypes = typesList.querySelectorAll('.current'); + if (openTypes.length > 0) { + var lastOpenType = openTypes[openTypes.length - 1]; + lastOpenType.scrollIntoView(); + } + } + + scrollSidebarToOpenType(); + + var setPersistentSearchQuery = function(value){ + sessionStorage.setItem(repositoryName + '::search-input:value', value); + } + + for(var i = 0; i < parents.length; i++) { + var _parent = parents[i]; + _parent.addEventListener('click', function(e) { + e.stopPropagation(); + + if(e.target.tagName.toLowerCase() == 'li') { + if(e.target.className.match(/open/)) { + sessionStorage.removeItem(e.target.getAttribute('data-id')); + e.target.className = e.target.className.replace(/ +open/g, ''); + } else { + sessionStorage.setItem(e.target.getAttribute('data-id'), '1'); + if(e.target.className.indexOf('open') == -1) { + e.target.className += ' open'; + } + } + } + }); + + if(sessionStorage.getItem(_parent.getAttribute('data-id')) == '1') { + _parent.className += ' open'; + } + } + + var leaveSearchScope = function(){ + CrystalDoc.toggleResultsList(false); + window.focus(); + } + + var navigator = new Navigator(document.querySelector('.types-list'), searchInput, document.querySelector(".search-results"), leaveSearchScope); + + CrystalDoc.loadIndex(); + var searchTimeout; + var lastSearchText = false; + var performSearch = function() { + document.dispatchEvent(new Event("CrystalDoc:searchDebounceStarted")); + + clearTimeout(searchTimeout); + searchTimeout = setTimeout(function() { + var text = searchInput.value; + + if(text == "") { + CrystalDoc.toggleResultsList(false); + }else if(text == lastSearchText){ + document.dispatchEvent(new Event("CrystalDoc:searchDebounceStopped")); + }else{ + CrystalDoc.search(text); + navigator.highlightFirst(); + searchInput.focus(); + } + lastSearchText = text; + setPersistentSearchQuery(text); + }, 200); + }; + + if(location.hash.length > 3 && location.hash.substring(0,3) == "#q="){ + // allows directly linking a search query which is then executed on the client + // this comes handy for establishing a custom browser search engine with https://crystal-lang.org/api/#q=%s as a search URL + // TODO: Add OpenSearch description + var searchQuery = location.hash.substring(3); + history.pushState({searchQuery: searchQuery}, "Search for " + searchQuery, location.href.replace(/#q=.*/, "")); + searchInput.value = searchQuery; + document.addEventListener('CrystalDoc:loaded', performSearch); + } + + if (searchInput.value.length == 0) { + var searchText = sessionStorage.getItem(repositoryName + '::search-input:value'); + if(searchText){ + searchInput.value = searchText; + } + } + searchInput.addEventListener('keyup', performSearch); + searchInput.addEventListener('input', performSearch); + + var usageModal = new UsageModal('Keyboard Shortcuts', '' + + '' + ); + + function handleShortkeys(event) { + var element = event.target || event.srcElement; + + if(element.tagName == "INPUT" || element.tagName == "TEXTAREA" || element.parentElement.tagName == "TEXTAREA"){ + return; + } + + switch(event.key) { + case "?": + usageModal.show(); + break; + + case "Escape": + usageModal.hide(); + break; + + case "s": + case "/": + if(usageModal.isVisible()) { + return; + } + event.stopPropagation(); + navigator.focus(); + performSearch(); + break; + } + } + + document.addEventListener('keyup', handleShortkeys); + + var scrollToEntryFromLocationHash = function() { + var hash = window.location.hash; + if (hash) { + var targetAnchor = unescape(hash.substr(1)); + var targetEl = document.querySelectorAll('.entry-detail[id="' + targetAnchor + '"]'); + + if (targetEl && targetEl.length > 0) { + targetEl[0].offsetParent.scrollTop = targetEl[0].offsetTop; + } + } + }; + window.addEventListener("hashchange", scrollToEntryFromLocationHash, false); + scrollToEntryFromLocationHash(); +}); diff --git a/docs/search-index.js b/docs/search-index.js new file mode 100644 index 0000000..5e09cac --- /dev/null +++ b/docs/search-index.js @@ -0,0 +1 @@ +crystal_doc_search_index_callback({"repository_name":"github.com/lbarasti/statistics","body":"![Build Status](https://github.com/lbarasti/statistics/workflows/build/badge.svg)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n# statistics\n\nA statistical library to perform descriptive statistics and generate random values based on popular probability distributions.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n statistics:\n github: lbarasti/statistics\n```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"statistics\"\n```\n\n### Descriptive statistics\nYou can compute mean, variance and standard deviation of a collection as follows.\n```crystal\ninclude Statistics\n\nx = [1, 10, 7]\nmean(x) # 6\nvar(x) # 14\nvar(x, corrected: true) # 21\nvar(x, mean: 8) # 18.0\nstd(x) # 3.7416...\n```\n\n### Sampling\nTo work with distributions, import the `Distributions` namespace as follows.\n```crystal\ninclude Statistics::Distributions\n```\n\nNow, here is how we sample values from a normal distribution with `mean = 1.5` and `std = 0.2`.\n```crystal\nNormal.new(1.5, 0.2).rand\n```\n\nWe can generate an iterable of normally distributed random values as follows.\n```crystal\ngen = Normal.new(1.5, 0.2)\n1000.times.map { gen.rand }\n```\n\n#### Supported distributions\nThe following distributions are supported:\n* Constant\n* Exponential\n* Normal\n* Poisson\n* Uniform\n\nDon't see your favourite one on the list? Just fork the repo, add your distribution to the `distributions.cr` file, and open a PR.\n\n## Development\n\nThis shard is a work in progress. Everyone's contribution is welcome.\n\nThe guiding principle at this stage is\n> make it work before you make it right\n\nWhich in this context means: let's not focus on benchmarks and performance, but rather on usability and correctness.\n\n## References\n* [numpy.random](https://numpy.org/devdocs/reference/random/generator.html): distributions and random sampling\n* [numpy statistics](https://numpy.org/devdocs/reference/routines.statistics.html#averages-and-variances): order statistics, averages and variances\n* [scipy stats](https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py) module and related [tests](https://github.com/scipy/scipy/blob/1150c4c033899a5a4556b7d34d6b137352b36b9e/scipy/stats/tests/test_stats.py) tests\n* [julia random](https://docs.julialang.org/en/v1/stdlib/Random/) module\n* [julia statistics](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.std) module\n* [julia distributions](https://juliastats.org/Distributions.jl/latest/starting/) package.\n* on [skewness and kurtosis](https://brownmath.com/stat/shape.htm), by Stan Brown\n* more on [skewness and kurtosis](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm), from NIST.\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [lbarasti](https://github.com/lbarasti) - creator and maintainer\n","program":{"html_id":"github.com/lbarasti/statistics/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"github.com/lbarasti/statistics","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/lbarasti/statistics/Statistics","path":"Statistics.html","kind":"module","full_name":"Statistics","name":"Statistics","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"lib/distributions.cr","line_number":1,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"},{"filename":"statistics.cr","line_number":6,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"\"0.1.0\"","doc":null,"summary":null}],"included_modules":[],"extended_modules":[{"html_id":"github.com/lbarasti/statistics/Statistics","kind":"module","full_name":"Statistics","name":"Statistics"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Basic descriptive statistics functionality.\n\nMore flexible than a scientific-calculator, but not as exhaustive, yet.","summary":"

Basic descriptive statistics functionality.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"describe(values)-instance-method","html_id":"describe(values)-instance-method","name":"describe","doc":"Computes several descriptive statistics of the passed array.\n\nParameters\n- `values`: a one-dimensional dataset.","summary":"

Computes several descriptive statistics of the passed array.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"args_string":"(values)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L14","def":{"name":"describe","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = values.size\nsorted = values.sort\n{mean: mean(values), var: var(values), std: std(values), skewness: skew(values), kurtosis: kurtosis(values), min: sorted.first, max: sorted.last, q1: quantile(sorted, 0.25, sorted: true), median: median(sorted, sorted: true), middle: middle(sorted), q3: quantile(sorted, 0.75, sorted: true)}\n"}},{"id":"frequency(values:Enumerable(T))forallT-instance-method","html_id":"frequency(values:Enumerable(T))forallT-instance-method","name":"frequency","doc":"Computes the number of occurrences of each value in the dataset.\n\nReturns a Hash with each the dataset values as keys and the number of times they appear as value.\n\nParameters\n- `values`: a one-dimensional dataset","summary":"

Computes the number of occurrences of each value in the dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable(T)"}],"args_string":"(values : Enumerable(T)) forall T","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L38","def":{"name":"frequency","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable(T)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"values.reduce(Hash(T, Int32).new(0)) do |freq, v|\n __temp_24 = v\n freq[__temp_24] = freq[__temp_24] + 1\n freq\nend"}},{"id":"kurtosis(values,corrected=false,excess=false)-instance-method","html_id":"kurtosis(values,corrected=false,excess=false)-instance-method","name":"kurtosis","doc":"Computes the kurtosis of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `corrected`: when set to `true`, then the calculations are corrected for statistical bias. Default is `false`.\n- `excess`: when set to `true`, computes the [excess kurtosis](https://en.wikipedia.org/wiki/Kurtosis#Excess_kurtosis). Default is `false`.\n\nThis implementation is based on the [scipy/stats.py](https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py#L1142).","summary":"

Computes the kurtosis of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""},{"name":"excess","doc":null,"default_value":"false","external_name":"excess","restriction":""}],"args_string":"(values, corrected = false, excess = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L53","def":{"name":"kurtosis","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""},{"name":"excess","doc":null,"default_value":"false","external_name":"excess","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = values.size\nm = mean(values)\nm4 = moment(values, m, 4)\nm2 = moment(values, m, 2)\nkurt = if corrected\n (((1 / (n - 2)) / (n - 3)) * (((((n ** 2) - 1) * m4) / (m2 ** 2)) - (3 * ((n - 1) ** 2)))) + 3\nelse\n m4 / (m2 ** 2)\nend\nexcess ? kurt - 3 : kurt\n"}},{"id":"mean(values)-instance-method","html_id":"mean(values)-instance-method","name":"mean","doc":"Computes the mean of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.","summary":"

Computes the mean of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"args_string":"(values)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L72","def":{"name":"mean","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(values.reduce(0) do |acc, v|\n acc + v\nend) / values.size"}},{"id":"median(values,sorted=false)-instance-method","html_id":"median(values,sorted=false)-instance-method","name":"median","doc":"Computes the median of all elements in a dataset.\n\nFor an even number of elements the mean of the two median elements will be computed.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `sorted`: when `true`, the computations assume that the provided values are\n sorted. Default is `false`.\n\nSee Julia's [Statistics.median](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.median).","summary":"

Computes the median of all elements in a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"args_string":"(values, sorted = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L86","def":{"name":"median","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = values.size\nmid = size // 2\nsorted_values = sorted ? values : values.sort\nif size.odd?\n sorted_values[mid]\nelse\n middle([sorted_values[mid - 1], sorted_values[mid]])\nend\n"}},{"id":"middle(a,b)-instance-method","html_id":"middle(a,b)-instance-method","name":"middle","doc":"Computes the middle of two values `a` and `b`.","summary":"

Computes the middle of two values a and b.

","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L111","def":{"name":"middle","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"0.5 * (a + b)"}},{"id":"middle(values)-instance-method","html_id":"middle(values)-instance-method","name":"middle","doc":"Computes the middle of an array `a`, which consists of finding its\nextrema and then computing their mean.\n\nParameters\n- `values`: a one-dimensional dataset.\n\nSee Julia's [Statistics.middle](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.middle).","summary":"

Computes the middle of an array a, which consists of finding its extrema and then computing their mean.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"args_string":"(values)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L105","def":{"name":"middle","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"min, max = values.minmax\nmiddle(min, max)\n"}},{"id":"mode(values:Enumerable)-instance-method","html_id":"mode(values:Enumerable)-instance-method","name":"mode","doc":"Computes the modal (most common) value in a dataset.\n\nReturns a pair with the modal value and the bin-count for the modal bin.\nIf there is more than one such value, no guarantees are made which one will be picked.\nNOTE: computing the mode requires traversing the entire dataset.\n\nParameters\n- `values`: a one-dimensional dataset.","summary":"

Computes the modal (most common) value in a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable"}],"args_string":"(values : Enumerable)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L123","def":{"name":"mode","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Enumerable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(frequency(values)).max_by(&.last)"}},{"id":"moment(values,mean=nil,n=1)-instance-method","html_id":"moment(values,mean=nil,n=1)-instance-method","name":"moment","doc":"Calculates the n-th moment about the mean for a sample.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `mean`: a pre-computed mean. If a mean is not provided, then the sample's\n mean will be computed. Default is `nil`.\n- `n`: Order of central moment that is returned. Default is `1`.","summary":"

Calculates the n-th moment about the mean for a sample.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"n","doc":null,"default_value":"1","external_name":"n","restriction":""}],"args_string":"(values, mean = nil, n = 1)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L134","def":{"name":"moment","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"n","doc":null,"default_value":"1","external_name":"n","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m = mean || (Statistics.mean(values))\n(values.reduce(0) do |a, b|\n a + ((b - m) ** n)\nend) / values.size\n"}},{"id":"quantile(values,p,sorted=false)-instance-method","html_id":"quantile(values,p,sorted=false)-instance-method","name":"quantile","doc":"Computes the quantile of a dataset at a specified probability `p` on the interval [0,1].\n\nQuantiles are computed via linear interpolation between the points `((k-1)/(n-1), v[k])`,\nfor `k = 1:n` where `n = values.size`.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `p`: probability. Values of `p` should be in the interval `[0, 1]`.\n- `sorted` indicates whether `values` can be assumed to be sorted.\n\nImplementation based on Julia's [Statistics.quantile](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.quantile).","summary":"

Computes the quantile of a dataset at a specified probability p on the interval [0,1].

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"args_string":"(values, p, sorted = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L150","def":{"name":"quantile","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":""},{"name":"sorted","doc":null,"default_value":"false","external_name":"sorted","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sorted_values = sorted ? values : values.sort\nn = values.size\naleph = (n - 1) * p\nj = (clamp(aleph.floor, 0, n - 2)).to_i\ngamma = clamp(aleph - j, 0, 1)\na = sorted_values[j]\nb = sorted_values[j + 1]\na + ((b - a) * gamma)\n"}},{"id":"skew(values,corrected=false)-instance-method","html_id":"skew(values,corrected=false)-instance-method","name":"skew","doc":"Computes the skewness of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `corrected`: when set to `true`, then the calculations are corrected for statistical bias. Default is `false`.\n\nThis implementation is based on the [scipy/stats.py](https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py#L1039).","summary":"

Computes the skewness of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"args_string":"(values, corrected = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L170","def":{"name":"skew","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = values.size\nm = mean(values)\nm3 = moment(values, m, 3)\nm2 = moment(values, m, 2)\ncorrection_factor = corrected ? (Math.sqrt((n - 1.0) * n)) / (n - 2.0) : 1\n(correction_factor * m3) / (m2 ** 1.5)\n"}},{"id":"std(values,mean=nil,corrected=false)-instance-method","html_id":"std(values,mean=nil,corrected=false)-instance-method","name":"std","doc":"Computes the standard deviation of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `mean`: a pre-computed `mean`. This could be a pre-computed sample's mean\n or the population's known mean. If a mean is not provided, then the sample's\n mean will be computed. Default is `nil`.\n- `corrected`: when set to `true`, then the sum of squares is scaled\n with `values.size - 1`, rather than with `values.size`. Default is `false`.","summary":"

Computes the standard deviation of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"args_string":"(values, mean = nil, corrected = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L188","def":{"name":"std","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Math.sqrt(var(values, mean, corrected))"}},{"id":"var(values,mean=nil,corrected=false)-instance-method","html_id":"var(values,mean=nil,corrected=false)-instance-method","name":"var","doc":"Computes the variance of a dataset.\n\nParameters\n- `values`: a one-dimensional dataset.\n- `mean`: a pre-computed `mean`. This could be a pre-computed sample's mean\n or the population's known mean. If a mean is not provided, then the sample's\n mean will be computed. Default is `nil`.\n- `corrected`: when set to `true`, then the sum of squares is scaled\n with `values.size - 1`, rather than with `values.size`. Default is `false`.","summary":"

Computes the variance of a dataset.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"args_string":"(values, mean = nil, corrected = false)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L201","def":{"name":"var","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":""},{"name":"mean","doc":null,"default_value":"nil","external_name":"mean","restriction":""},{"name":"corrected","doc":null,"default_value":"false","external_name":"corrected","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"correction_factor = corrected ? values.size / (values.size - 1) : 1\n(moment(values, mean, 2)) * correction_factor\n"}}],"macros":[],"types":[{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","path":"Statistics/Distributions.html","kind":"module","full_name":"Statistics::Distributions","name":"Distributions","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"lib/distributions.cr","line_number":2,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics","kind":"module","full_name":"Statistics","name":"Statistics"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Constant","path":"Statistics/Distributions/Constant.html","kind":"class","full_name":"Statistics::Distributions::Constant","name":"Constant","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":3,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(rand:Float64)-class-method","html_id":"new(rand:Float64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":"Float64"}],"args_string":"(rand : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L6","def":{"name":"new","args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(rand)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand:Float64-instance-method","html_id":"rand:Float64-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Float64","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L4","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rand"}},{"id":"rand=(rand)-instance-method","html_id":"rand=(rand)-instance-method","name":"rand=","doc":null,"summary":null,"abstract":false,"args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":""}],"args_string":"(rand)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L4","def":{"name":"rand=","args":[{"name":"rand","doc":null,"default_value":"","external_name":"rand","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rand = rand"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Exponential","path":"Statistics/Distributions/Exponential.html","kind":"class","full_name":"Statistics::Distributions::Exponential","name":"Exponential","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":10,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(lambda:Float64)-class-method","html_id":"new(lambda:Float64)-class-method","name":"new","doc":"https://en.wikipedia.org/wiki/Inverse_transform_sampling\nhttps://stackoverflow.com/questions/2106503/pseudorandom-number-generator-exponential-distribution/2106564","summary":"

https://en.wikipedia.org/wiki/Inverse_transform_sampling https://stackoverflow.com/questions/2106503/pseudorandom-number-generator-exponential-distribution/2106564

","abstract":false,"args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"args_string":"(lambda : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L13","def":{"name":"new","args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(lambda)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L16","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(-(Math.log(::rand))) / @lambda"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Normal","path":"Statistics/Distributions/Normal.html","kind":"class","full_name":"Statistics::Distributions::Normal","name":"Normal","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":21,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"TWO_PI","name":"TWO_PI","value":"2 * Math::PI","doc":"https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform","summary":"

https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform

"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(mean:Float64,std:Float64)-class-method","html_id":"new(mean:Float64,std:Float64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"mean","doc":null,"default_value":"","external_name":"mean","restriction":"Float64"},{"name":"std","doc":null,"default_value":"","external_name":"std","restriction":"Float64"}],"args_string":"(mean : Float64, std : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L25","def":{"name":"new","args":[{"name":"mean","doc":null,"default_value":"","external_name":"mean","restriction":"Float64"},{"name":"std","doc":null,"default_value":"","external_name":"std","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(mean, std)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L28","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = (Math.sqrt(-2 * (Math.log(::rand)))) * (Math.sin(TWO_PI * ::rand))\n(v * @std) + @mean\n"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Poisson","path":"Statistics/Distributions/Poisson.html","kind":"class","full_name":"Statistics::Distributions::Poisson","name":"Poisson","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":34,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(lambda:Float64)-class-method","html_id":"new(lambda:Float64)-class-method","name":"new","doc":"see https://en.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables\nhttps://www.johndcook.com/SimpleRNG.cpp\nhttps://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/","summary":"

see https://en.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables https://www.johndcook.com/SimpleRNG.cpp https://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/

","abstract":false,"args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"args_string":"(lambda : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L38","def":{"name":"new","args":[{"name":"lambda","doc":null,"default_value":"","external_name":"lambda","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(lambda)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L41","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x = 0\np = Math.exp(-@lambda)\ns = p\nu = ::rand\nwhile u > s\n x = x + 1\n p = p * (@lambda / x)\n s = s + p\nend\nx\n"}}],"macros":[],"types":[]},{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions/Uniform","path":"Statistics/Distributions/Uniform.html","kind":"class","full_name":"Statistics::Distributions::Uniform","name":"Uniform","abstract":false,"superclass":{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/lbarasti/statistics/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/lbarasti/statistics/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"lib/distributions.cr","line_number":55,"url":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr"}],"repository_name":"github.com/lbarasti/statistics","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/lbarasti/statistics/Statistics/Distributions","kind":"module","full_name":"Statistics::Distributions","name":"Distributions"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(min:Float64,max:Float64)-class-method","html_id":"new(min:Float64,max:Float64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Float64"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Float64"}],"args_string":"(min : Float64, max : Float64)","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L58","def":{"name":"new","args":[{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Float64"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(min, max)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"rand-instance-method","html_id":"rand-instance-method","name":"rand","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L62","def":{"name":"rand","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@min + (::rand * @interval)"}}],"macros":[],"types":[]}]}]}]}}) \ No newline at end of file