defmodule Wizard.Stats do @moduledoc """ Wizard's Statistics functions """ @doc """ mean(list) - produces the mean from a list of numbers """ @spec mean(list) :: number def mean(list) do Math.sum(list)/length list end @doc """ binomial(n,theta) - produces a binomial distribution function with n items and theta success """ @spec binomial(non_neg_integer, number) :: fun def binomial(n, theta) do fn x -> Math.combination(n, x) * Math.pow(theta, x) * Math.pow(1-theta, n-x) end end @doc """ poisson(theta) - produces a poisson distribution function with probability theta """ @spec poisson(number) :: fun def poisson(theta) do fn x -> (Math.pow(theta, x) * 1/Math.pow(Math.e, theta))/Math.factorial(x) end end end