crawlie v1.0.0 Crawlie.Stats.Distribution

Summary

Functions

Adds a value to the bucket in the distribution under the given key

Adds “missing” keys to the distribution for convenience and stuff

Converts the distribution from absolute numbers to proportions or probability distribution if you will

Removes a value from the bucket in the distribution under the given key

Functions

add(map, key, bucket, amount \\ 1)
add(map, term, term, integer | float) :: map

Adds a value to the bucket in the distribution under the given key.

Example

iex> alias Crawlie.Stats.Distribution
iex> stats = %{numbers: %{}, enums: %{}}
iex> stats
...>   |> Distribution.add(:numbers, 3)
...>   |> Distribution.add(:enums, :foo)
%{numbers: %{3 => 1}, enums: %{foo: 1}}
normalize(dist, keys)

Adds “missing” keys to the distribution for convenience and stuff.

Example

iex> alias Crawlie.Stats.Distribution
iex> dist = %{2 => 15, 3 => 10}
iex> Distribution.normalize(dist, 0..4)
%{0 => 0, 1 => 0, 2 => 15, 3 => 10, 4 => 0}
proportions(dist)

Converts the distribution from absolute numbers to proportions or probability distribution if you will.

Example

iex> alias Crawlie.Stats.Distribution
iex> dist = %{1 => 2, 2 => 0, 3 => 3}
iex> Distribution.proportions(dist)
%{1 => 0.4, 2 => 0.0, 3 => 0.6}
remove(map, key, bucket, amount \\ 1)
remove(map, term, term, integer | float) :: map

Removes a value from the bucket in the distribution under the given key.

Example

iex> alias Crawlie.Stats.Distribution
iex> stats = %{numbers: %{0 => 10, 1 => 12}}
iex> Distribution.remove(stats, :numbers, 1)
%{numbers: %{0 => 10, 1 => 11}}