prodigy.distribution.symengine_distribution

class SymengineDist(function, *variables)[source]

Bases: Distribution

Parameters:

variables (Symbol | str)

static factory()[source]

Returns a factory for this subclass of distribution

Return type:

Type[CommonDistributionsFactory]

coefficient_sum()[source]
Return type:

Expr

iter_with(monomial_iterator)[source]

Iterates over the expression with a custom monomial order. :type monomial_iterator: Iterator[List[int]] :param monomial_iterator: An iterator that yields the monomial order.

Return type:

Iterator[Tuple[str, State]]

Returns:

An iterator over the expression in the given order.

get_prob_by_diff(state)[source]

Get the probability of a given state by means of differentiation :type state: State :param state: The state to get the probability of

Return type:

Basic

Returns:

The probability of the given state

get_prob_by_series(state)[source]

Get the probability of a given state by means of taylor expansion :type state: State :param state: The state to get the probability of

Return type:

Basic

Returns:

The probability of the given state

copy(deep=True)[source]

Returns a full copy of itself.

Parameters:

deep (bool)

Return type:

SymengineDist

get_probability_mass()[source]

Returns the probability mass of the distribution.

Return type:

str

get_expected_value_of(expression)[source]

Returns the expected value of the expression expression evaluated in the distribution.

Parameters:

expression (VarExpr | BoolLitExpr | NatLitExpr | RealLitExpr | UnopExpr | BinopExpr | CategoricalExpr | SubstExpr | TickExpr | FunctionCallExpr | InferExpr | SampleExpr | str)

Return type:

str

normalize()[source]

Normalizes the probability mass of the distribution.

Return type:

SymengineDist

get_variables()[source]

Returns all variables of the distribution as strings

Return type:

set[str]

get_parameters()[source]

Returns all parameters of the distribution as strings

Return type:

set[str]

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:

SymengineDist

static evaluate(expression, state)[source]

Evaluates the expression in a given state.

Parameters:
is_zero_dist()[source]

Returns whether the distribution encodes the 0 distribution.

Return type:

bool

is_finite()[source]

Returns whether the distribution has finite support.

Return type:

bool

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.

Parameters:

exclude (set[str] | frozenset[str])

Return type:

str

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:

SymengineDist

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:

SymengineDist

Returns:

The marginal distribution.

set_variables(*variables)[source]

Sets the free variables in a distribution.

Parameters:

variables (str) – The variables.

Return type:

SymengineDist

Returns:

The distribution with free variables variables.

set_parameters(*parameters)[source]

Sets the parameters in a distribution.

Parameters:

parameters (str) – The parameters.

Return type:

SymengineDist

Returns:

The distribution with parameters parameters.

set_variables_and_parameters(variables, parameters)[source]

todo

Parameters:
approximate(threshold)[source]

Computes the approximation until the given threshold is reached (might not terminate).

Parameters:

threshold (str | int) – The threshold either as a maximum number of states (int), or a certain probability mass (str).

Return type:

Generator[SymengineDist]

Returns:

The approximated (truncated) probability distribution.

safe_subs(*parameters, fun=None)[source]

Substitution with checks for divisions by zero. Uses plain substitution if no pole is hit (see _hits_pole). Otherwise, converts to sympy and cancels the fraction if the function is rational, or takes the limit.

Parameters:
  • parameters (Tuple[str, str | int] | str | Expr | int) – The substitution parameters of form variable, value.

  • fun (Expr) – The function the substitution should be performed on. If not given, self._s_func is used.

Return type:

Expr

Returns:

The substituted se.Expr

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:

SymengineDist

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:

SymengineDist

class SymenginePGF[source]

Bases: CommonDistributionsFactory

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:
  • var (str | VarExpr)

  • p (str | VarExpr | BoolLitExpr | NatLitExpr | RealLitExpr | UnopExpr | BinopExpr | CategoricalExpr | SubstExpr | TickExpr | FunctionCallExpr | InferExpr | SampleExpr)

Return type:

SymengineDist

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:

SymengineDist

static bernoulli(var, p)[source]

A bernoulli distribution with parameter p.

Parameters:
  • var (str | VarExpr)

  • p (str | VarExpr | BoolLitExpr | NatLitExpr | RealLitExpr | UnopExpr | BinopExpr | CategoricalExpr | SubstExpr | TickExpr | FunctionCallExpr | InferExpr | SampleExpr)

Return type:

SymengineDist

static poisson(var, lam)[source]

A poisson distribution with parameter lam.

Parameters:
  • var (str | VarExpr)

  • lam (str | VarExpr | BoolLitExpr | NatLitExpr | RealLitExpr | UnopExpr | BinopExpr | CategoricalExpr | SubstExpr | TickExpr | FunctionCallExpr | InferExpr | SampleExpr)

Return type:

SymengineDist

static log(var, p)[source]

A logarithmic distribution with parameter p.

Parameters:
  • var (str | VarExpr)

  • p (str | VarExpr | BoolLitExpr | NatLitExpr | RealLitExpr | UnopExpr | BinopExpr | CategoricalExpr | SubstExpr | TickExpr | FunctionCallExpr | InferExpr | SampleExpr)

Return type:

SymengineDist

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:

SymengineDist

static undefined(*variables)[source]

A distribution where actually no information about the states is given.

Parameters:

variables (str | VarExpr)

Return type:

SymengineDist

static zero(*variables)[source]
Parameters:

variables (str | VarExpr)

Return type:

SymengineDist

static one(*variables)[source]

A distribution where all variables are initialized with 0.

Parameters:

variables (str | VarExpr)

Return type:

SymengineDist

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:

SymengineDist