uravu.distribution

The storage and manipulation of probability distributions is fundamental to the operation of uravu and Bayesian inference. The Distribution class oversees these operations.

class uravu.distribution.Distribution(samples: Union[List[Union[float, int]], numpy.ndarray], name: str = 'Distribution', random_state: numpy.random._generator.Generator = None)[source]

Bases: object

In addition to storage of the probability distribution, this class allows for some basic analysis, such as determination of normality.

samples

Samples in the distribution.

Type:array_like
name

Distribution name.

Type:str
normal

Are the samples normally distributed?

Type:bool
kde

Kernel density approximation for the distribution.

Type:scipy.stats.kde.gaussian_kde
Parameters:
  • samples (array_like) – Sample for the distribution.
  • name (str, optional) – A name to identify the distribution. Default is 'Distribution'.
  • ci_points (array_like, optional) – The two percentiles at which confidence intervals should be found. Default is [2.5, 97.5] (a 95 % confidence interval).
add_samples(samples: Union[List[Union[float, int]], numpy.ndarray])[source]

Add samples to the distribution.

Parameters:samples (array_like) – Samples to be added to the distribution.
check_normality() → bool[source]

Uses a scipy.stats.normaltest() to evaluate if samples are normally distributed and updates the normal attribute.

ci(ci_points: List[float] = [2.5, 97.5]) → numpy.ndarray[source]

Get the extrema of the confidence intervals of the distribution.

Parameters:ci_points – The confidence interval points to return.
Returns:Distribution values at the confidence interval.
con_int(ci_points: List[float] = [2.5, 97.5]) → numpy.ndarray[source]

Get the extrema of the confidence intervals of the distribution.

Parameters:ci_points – The confidence interval points to return.
Returns:Distribution values at the confidence interval.
dist_max

Get the value that maximises the distribution. If no kde has been created (for example if the distribution has fewer than 8 values) the median is returned.

Returns:Most likely value.
classmethod from_dict(my_dict: dict) → uravu.distribution.Distribution[source]
Parameters:my_dict – Dictionary description of the distribution.
Returns:Distribution object form the dictionary.
logpdf(x: Union[float, List[Union[float, int]], numpy.ndarray]) → Union[float, numpy.ndarray][source]

Get the natural log probability density function for the distribution.

Parameters:x – Value to return natural log probability of.
Returns:Natural log probability.
max

Sample maximum.

Type:return
min

Sample minimum.

Type:return
n

Median value.

Type:return
negative_pdf(x: Union[float, List[Union[float, int]], numpy.ndarray]) → Union[float, numpy.ndarray][source]

Get the negative of the probability density function for the distribution.

Parameters:x – Value to return negative probability of.
Returns:Negative probability.
pdf(x: Union[float, List[Union[float, int]], numpy.ndarray]) → Union[float, numpy.ndarray][source]

Get the probability density function for the distribution.

Parameters:x – Value to return probability of.
Returns:Probability.
s

Standard deviation of the distribution. For a non-normal distribution, this will return None.

Type:return
size

Number of samples in the distribution.

Type:return
to_dict() → dict[source]
Returns:Dictionary description of the object.
v

Standard deviation of the distribution. For a non-normal distribution, this will return None.

Type:return