analysis_prep v0.1.2 AnalysisPrep.Probability
Provide basic probability functions
Summary
Functions
The number of ways to choose c items from a list of n items
Get combinations of n items at a time, returned as combinations
The cross produce of all items from two collections. Uses arrays for each pair
Joint probability from two map-like distributions
The probability of an event, given a sample space of equiprobable outcomes. The event can be either a set of outcomes, or a predicate (true for outcomes in the event)
Generate samples from a series
Filter a data series by a predicate
Functions
The number of ways to choose c items from a list of n items
Examples
iex> choose(3,2)
3.0
iex> choose(12,4)
495.0
iex> choose(3,0)
0
Get combinations of n items at a time, returned as combinations
Examples
iex> combinations(1..3) [[3,2], [3,1], [2,1]]
iex> combinations(1..4, 3) [[4,3,2], [4,3,1], [4,2,1], [3,2,1]]
The cross produce of all items from two collections. Uses arrays for each pair.
Examples
iex> cross(1..2, 4..5)
[[1,4],[1,5],[2,4],[2,5]]
Joint probability from two map-like distributions.
Example
iex> joint(%{a: 0.3, b: 0.6}, %{x: 0.25, y: 0.75})
%{{:a, :x} => 0.075, {:a, :y} => 0.22499999999999998, {:b, :x} => 0.15, {:b, :y} => 0.44999999999999996}
The probability of an event, given a sample space of equiprobable outcomes. The event can be either a set of outcomes, or a predicate (true for outcomes in the event).
Examples
iex> p([1,2], [1,2,3,4]) Ratio.new(2,4)
iex> p([1,2,3], 2..5) Ratio.new(2,4)
iex> p([:a], %{a: 1, b: 2}) Ratio.new(1,3)
Generate samples from a series
Examples
iex> sample(0..5) <= 5
true
iex> sample [42]
42
iex> length sample(0..5, 2)
2
iex> sample []
nil
iex> sample 1..5, 0
nil
Filter a data series by a predicate.
Examples
iex> such_that(fn(e) -> rem(e, 2) == 0 end, 1..10) |> Enum.to_list
[2,4,6,8,10]
iex> such_that(& &1 == :a, %{a: 1, b: 2})
%{a: 1}