quara.objects.multinomial_distribution module

class MultinomialDistribution(ps, shape=None, eps_zero=None)[source]

Bases: object

Constructor

Parameters
  • ps (np.ndarray) – the probability distribution of multinomial distribution.

  • shape (Tuple[int], optional) – the shape of multinomial distribution, by default None. if shape is None, set len(ps).

  • eps_zero (float, optional) – threshold to determine probabilities as zero, by default 1e-8

Raises
  • ValueError – some elements of ps are negative numbers.

  • ValueError – the sum of ps is not 1.

  • ValueError – the size of ps and shape do not match.

conditionalize(conditional_variable_indices, conditional_variable_values)[source]

conditionalize MultinomialDistribution.

Parameters
  • conditional_variable_indices (List[int]) – indices of the given event of the conditional probability.

  • conditional_variable_values (List[int]) – values of the given event of the conditional probability.

Returns

conditionalized MultinomialDistribution.

Return type

MultinomialDistribution

Raises
  • ValueError – length of conditional_variable_indices does not equal conditional_variable_values.

  • ValueError – conditional_variable_indices has negative numbers.

  • ValueError – conditional_variable_values has negative numbers.

property eps_zero: float

returns threshold to determine probabilities as zero.

Returns

threshold to determine probabilities as zero.

Return type

float

execute_random_sampling(num, size, random_generator=None)[source]

execute random sampling.

Parameters
  • num (int) – number of trials

  • size (int) – size of trials. this size equals the length of the list returned by this function.

  • random_generator (Union[int, np.random.Generator], optional) –

    • If the type is int, generates Generator with seed seed_or_generator and returned generated random.Generator.

    • If the type is Generator, returns Generator.

    • If argument is None, returns np.random.

    • Default value is None.

Returns

list of random sampling.

Return type

List[np.ndarray]

property is_zero_dist: bool

returns whether all probabilities are zero.

Returns

whether all probabilities are zero.

Return type

bool

marginalize(outcome_indices_remain)[source]

marginalize MultinomialDistribution.

Parameters

outcome_indices_remain (List[int]) – calculate the marginal probability of variable outcome_indices_remain.

Returns

marginalized MultinomialDistribution.

Return type

MultinomialDistribution

Raises

ValueError – some elements of outcome_indices_remain are out of range.

property ps: numpy.ndarray

returns ps.

Returns

the probability distribution of multinomial distribution.

Return type

np.ndarray

property shape: Tuple[int]

returns shape.

Returns

the shape of multinomial distribution.

Return type

Tuple[int]