Bernoulli

class stats_arrays.BernoulliUncertainty

Bases: stats_arrays.distributions.base.BoundedUncertaintyBase

classmethod bounded_random_variables(params, size, seeded_random=None, maximum_iterations=None)

No bounds checking because the bounds do not exclude any of the distribution.

classmethod check_2d_inputs(params, vector)

Convert vector to 2 dimensions if not already, and raise stats_arrays.InvalidParamsError if vector and params dimensions don’t match.

classmethod check_bounds_reasonableness(params, *args, **kwargs)

Always true because the bounds do not exclude any of the distribution.

classmethod from_dicts(*dicts)

Construct a Heterogeneous parameter array from parameter dictionaries.

Dictionary keys are the normal parameter array columns. Each distribution defines which columns are required and which are optional.

Example:

>>> from stats_arrays import UncertaintyBase
>>> import numpy as np
>>> UncertaintyBase.from_dicts(
...     {'loc': 2, 'scale': 3, 'uncertainty_type': 3},
...     {'loc': 5, 'minimum': 3, 'maximum': 10, 'uncertainty_type': 5}
...     )
array([(2.0, 3.0, nan, nan, nan, False, 3),
       (5.0, nan, nan, 3.0, 10.0, False, 5)],
       dtype=[('loc', '<f8'), ('scale', '<f8'), ('shape', '<f8'),
              ('minimum', '<f8'), ('maximum', '<f8'), ('negative', '?'),
              ('uncertainty_type', 'u1')])
Args:
One of more dictionaries.
Returns:
A Heterogeneous parameter array
classmethod from_tuples(*data)

Construct a Heterogeneous parameter array from parameter tuples.

The order of the parameters is:

  1. loc
  2. scale
  3. shape
  4. minimum
  5. maximum
  6. negative
  7. uncertainty_type

Each input tuple must have a length of exactly 7. For more flexibility, use from_dicts.

Example:

>>> from stats_arrays import UncertaintyBase
>>> import numpy as np
>>> UncertaintyBase.from_tuples(
...     (2, 3, np.NaN, np.NaN, np.NaN, False, 3),
...     (5, np.NaN, np.NaN, 3, 10, False, 5)
...     )
array([(2.0, 3.0, nan, nan, nan, False, 3),
       (5.0, nan, nan, 3.0, 10.0, False, 5)],
       dtype=[('loc', '<f8'), ('scale', '<f8'), ('shape', '<f8'),
              ('minimum', '<f8'), ('maximum', '<f8'), ('negative', '?'),
              ('uncertainty_type', 'u1')])
Args:
One of more tuples of length 7.
Returns:
A Heterogeneous parameter array
classmethod pdf(params, *args, **kwargs)

Provide a standard interface to calculate the probability distribution function of a uncertainty distribution. Default is cls.default_number_points_in_pdf points between min to max range if bounds are present, or cls.standard_deviations_in_default_range standard distributions.

Inputs

  • params : A one-row Parameter array.
  • xs : Optional. A one-dimensional numpy array of input values.

Output

Important

The output format for PDF is different than CDF or PPF.

A tuple of a vactor x values and a vector of y values. Y values are a one-dimensional array of probability densities, bounded on (0,1), with length xs, if provided, or cls.default_number_points_in_pdf.

classmethod rescale(params)

Rescale params to a (0,1) interval. Return adjusted_means and scale. Needed because SciPy assumes a (0,1) interval for many distributions.

classmethod statistics(params, *args, **kwargs)

Build a dictionary of mean, mode, median, and 95% confidence interval upper and lower values.

Inputs

Output

{‘mean’: mean value, ‘mode’: mode value, ‘median’: median value, ‘upper’: upper limit value, ‘lower’: lower limit value}. All values should be floats (not single-element arrays). Parameters that are not defined should be returned None, not omitted.