prodigy.distribution.generating_function¶
- class GeneratingFunction(function, *variables, closed=None, finite=None)[source]¶
Bases:
DistributionThis class represents a generating function. It wraps the sympy library. A GeneratingFunction object is designed to be immutable. This class does not ensure to be in a healthy state (i.e., every coefficient is non-negative).
- Parameters:
- use_simplification = False¶
- use_latex_output = False¶
- hadamard_product(other)[source]¶
Computes the Hadamard product of two univariate rational functions, i.e. the point-wise product of the coefficients in their formal power series representation.
- Parameters:
other (
Distribution)- Return type:
- get_fresh_variable(exclude=frozenset({}))[source]¶
Returns a str that is the name of neither an existing variable nor an existing parameter of this distribution nor contained in the exclude parameter.
- approximate_unilaterally(variable, probability_mass)[source]¶
Approximates the distribution in one variable via its series expansion, up until the specified probability mass is reached.
- Parameters:
- Return type:
- update_iid(sampling_dist, count, variable)[source]¶
Updates the distribution by the the iid-sampling rules.
- Parameters:
sampling_dist (
VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)count (
VarExpr)variable (
str|VarExpr)
- Return type:
- get_expected_value_of(expression)[source]¶
Returns the expected value of the expression expression evaluated in the distribution.
- set_variables(*variables)[source]¶
Sets the free variables in a distribution.
- Parameters:
variables (
str) – The variables.- Return type:
- Returns:
The distribution with free variables variables.
- set_parameters(*parameters)[source]¶
Sets the parameters in a distribution.
- Parameters:
parameters (
str) – The parameters.- Return type:
- Returns:
The distribution with parameters parameters.
- approximate(threshold)[source]¶
Generate an approximation of a generating function, until threshold percent or terms of the probability mass is captured.
- is_finite()[source]¶
Checks whether the generating function is finite.
- Returns:
True if the GF is a polynomial, False otherwise.
- classmethod evaluate_condition(condition, state)[source]¶
Evaluates whether the condition holds in the specified state.
- marginal(*variables, method=MarginalType.INCLUDE)[source]¶
Computes the marginal distribution for the given variables (MarginalType.Include), or for all but the given variables (MarginalType.Exclude).
- Parameters:
variables (
str|VarExpr) – A list of variables for which the marginal distribution should be computed. If this list is empty or contains symbols that are not known variables of this distribution, this function will raise an exception.method (
MarginalType) – The method of marginalization.
- Return type:
- Returns:
The marginal distribution.
- filter(condition)[source]¶
Filters the distribution such that only the parts which satisfy the condition are left.
- Parameters:
condition (
VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)- Return type:
- class SympyPGF[source]¶
Bases:
CommonDistributionsFactoryImplements PGFs of standard distributions.
- static geometric(var, p)[source]¶
A geometric distribution with success probability p, i.e., p + p*(1-p)*x + p*(1-p)^2*x^2 + ….
- Parameters:
- Return type:
- static uniform(var, lower, upper)[source]¶
A uniform distribution with bounds [lower,`upper`].
- Parameters:
var (
str|VarExpr)lower (
str|VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)upper (
str|VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)
- Return type:
- static bernoulli(var, p)[source]¶
A bernoulli distribution with parameter p.
- Parameters:
- Return type:
- static poisson(var, lam)[source]¶
A poisson distribution with parameter lam.
- Parameters:
- Return type:
- static binomial(var, n, p)[source]¶
A binomial distribution with parameters n and p.
- Parameters:
var (
str|VarExpr)n (
str|VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)p (
str|VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)
- Return type:
- static undefined(*variables)[source]¶
A distribution where actually no information about the states is given.
- Parameters:
variables (
str|VarExpr)- Return type:
- static one(*variables)[source]¶
A distribution where all variables are initialized with 0.
- Parameters:
variables (
str|VarExpr)- Return type:
- static from_expr(expression, *variables, **kwargs)[source]¶
A distribution represented by the expression.
- Parameters:
expression (
str|VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)- Return type: