prodigy.distribution.fast_generating_function

class FPS(expression, *variables, finite=None)[source]

Bases: Distribution

This class models a probability distribution in terms of a formal power series. These formal powerseries are itself provided by prodigy a python binding to GiNaC, something similar to a computer algebra system implemented in C++.

Parameters:
classmethod from_dist(dist, variables, parameters, finite=None)[source]
Parameters:
static factory()[source]

Returns a factory for this subclass of distribution

Return type:

Type[ProdigyPGF]

copy(deep=True)[source]

Returns a full copy of itself.

Parameters:

deep (bool)

Return type:

Distribution

get_probability_mass()[source]

Returns the probability mass of the distribution.

Return type:

VarExpr | BoolLitExpr | NatLitExpr | RealLitExpr | UnopExpr | BinopExpr | CategoricalExpr | SubstExpr | TickExpr | FunctionCallExpr | InferExpr | SampleExpr | 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:

FPS

get_variables()[source]

Returns the free variables of the distribution.

Return type:

Set[str]

get_parameters()[source]

Returns the parameters of the distribution.

Return type:

Set[str]

get_symbols()[source]

Returns all symbols that occur in this distribution (a subset of self.get_variables() | self.get_parameters()).

Return type:

Set[str]

static evaluate(expression, state)[source]

Evaluates the expression in a given state.

Parameters:
Return type:

int

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:

Distribution

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

old_update(expression)[source]
Parameters:

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

Return type:

FPS

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:

FPS

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:

FPS

Returns:

The marginal distribution.

set_variables(*variables)[source]

Sets the free variables in a distribution.

Parameters:

variables (str) – The variables.

Return type:

FPS

Returns:

The distribution with free variables variables.

set_parameters(*parameters)[source]

Sets the parameters in a distribution.

Parameters:

parameters (str) – The parameters.

Return type:

FPS

Returns:

The distribution with parameters 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[Distribution]

Returns:

The approximated (truncated) probability distribution.

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:

Distribution

class ProdigyPGF(*args, **kwargs)[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:

FPS

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:

FPS

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:

FPS

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:

FPS

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:

FPS

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:

FPS

static undefined(*variables)[source]

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

Parameters:

variables (str | VarExpr)

Return type:

FPS

static one(*variables)[source]

A distribution where all variables are initialized with 0.

Parameters:

variables (str | VarExpr)

Return type:

FPS

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:

FPS

static zero(*variables)[source]
Parameters:

variables (str | VarExpr)

Return type:

FPS