prodigy.distribution.distribution¶
- constant_value(expression)[source]¶
The value of an arithmetic expression without variables, or None if the expression contains variables, an operator other than + - * / % ^, or an intermediate result that natural-number arithmetic does not allow (negative difference, division by zero, non-integer modulo or exponent).
- class MarginalType(*values)[source]¶
Bases:
EnumSpecifies the type of marginalization.
- INCLUDE = 1¶
- EXCLUDE = 2¶
- class State(valuations=dict())[source]¶
Bases:
objectDescribes a state of a distribution, i.e., an assignment of variables to values
- class Distribution[source]¶
Bases:
ABCAbstract class that models different representations of probability distributions.
- abstractmethod static factory()[source]¶
Returns a factory for this subclass of distribution
- Return type:
- abstractmethod copy(deep=True)[source]¶
Returns a full copy of itself.
- Parameters:
deep (
bool)- Return type:
- abstractmethod get_probability_mass()[source]¶
Returns the probability mass of the distribution.
- Return type:
- abstractmethod get_expected_value_of(expression)[source]¶
Returns the expected value of the expression expression evaluated in the distribution.
- abstractmethod normalize()[source]¶
Normalizes the probability mass of the distribution.
- Return type:
- filter_state(state)[source]¶
Filters the distribution such that only the specified state is left. If the state does not contain assignments for all variables of the distribution, the resulting distribution contains all extensions of the state.
- Parameters:
state (
State)- Return type:
- 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:
- abstractmethod hadamard_product(other)[source]¶
Computes the Hadamard product of the distributions, i.e., the point-wise product of the probabilities.
- Parameters:
other (
Distribution)- Return type:
- get_symbols()[source]¶
Returns all symbols that occur in this distribution (a subset of self.get_variables() | self.get_parameters()).
- abstractmethod static evaluate(expression, state)[source]¶
Evaluates the expression in a given state.
- classmethod evaluate_condition(condition, state)[source]¶
Evaluates whether the condition holds in the specified state.
- evaluate_expression(expression, new_var=None)[source]¶
Creates a new distribution with a single variable that represents all possible results of the given expression.
- Parameters:
- Return type:
- abstractmethod is_zero_dist()[source]¶
Returns whether the distribution encodes the 0 distribution.
- Return type:
- abstractmethod is_finite()[source]¶
Returns whether the distribution has finite support.
- Return type:
- update(expression, approximate=None)[source]¶
Updates the current distribution by applying the expression to itself.
Some operations are illegal and will cause this function to raise an error. These operations include subtraction that may cause a variable to have a negative value, division that may cause a variable to have a value that is not an integer, and certain operations on infinite generating functions if the variables involved have an infinite marginal (such as multiplication of two variables) and approximation is disabled.
Every intermediate result that depends on a variable must be a natural number. A constant that is not a natural number may therefore only be a factor or a divisor: p/q * e is evaluated as (p * e) / q and is subject to the same divisibility check as a division, which is exact for infinite marginals of rational generating functions as well. Any other use, such as x + 1/2, raises an error.
The approximate parameter is used to determine up to which precision unilateral approximation should be performed if an update is not possible on infinite distributions.
Parameters are not allowed in an update expression.
- Parameters:
- Return type:
- abstractmethod 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.
- abstractmethod 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:
- abstractmethod 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.
- abstractmethod 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.
- abstractmethod set_parameters(*parameters)[source]¶
Sets the parameters in a distribution.
- Parameters:
parameters (
str) – The parameters.- Return type:
- Returns:
The distribution with parameters parameters.
- abstractmethod approximate(threshold)[source]¶
Computes the approximation until the given threshold is reached (might not terminate).
- abstractmethod 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:
- class CommonDistributionsFactory[source]¶
Bases:
ABCAbstract Factory Class implementing a Factory for common distributions.
- abstractmethod 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:
- abstractmethod 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:
- abstractmethod static bernoulli(var, p)[source]¶
A bernoulli distribution with parameter p.
- Parameters:
- Return type:
- abstractmethod static poisson(var, lam)[source]¶
A poisson distribution with parameter lam.
- Parameters:
- Return type:
- abstractmethod static log(var, p)[source]¶
A logarithmic distribution with parameter p.
- Parameters:
- Return type:
- abstractmethod 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:
- abstractmethod static undefined(*variables)[source]¶
A distribution where actually no information about the states is given.
- Parameters:
variables (
str|VarExpr)- Return type:
- abstractmethod static one(*variables)[source]¶
A distribution where all variables are initialized with 0.
- Parameters:
variables (
str|VarExpr)- Return type:
- abstractmethod 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: