Smoother

smoother.Smoother

class smoother.Smoother(lb=0, ub=1, num=50) [source]

The smoother computes a distribution by maximizing an objective function (i.e. a smoothness function) given constraints.

Attributes: x : np.array

A linearly spaced (self.num,) array of points between the lower and upper bounds of the distribution.

f_x : np.array

The probability density function of self.x.

F_x : np.array

The cumulative distribution function of self.x.

Methods

mean(self) [source]

Returns: mean : float

var(self) [source]

Returns: variance : float

std(self) [source]

Returns: standard deviation : float

median(self) [source]

Returns: median : float

entropy(self) [source]

Returns: entropy : float

pdf(self, x) [source]

Parameters: x : float

Returns: pdf(x) : float

Probability density function of x.

cdf(self, x) [source]

Parameters: x : float

Returns: cdf(x) : float between 0. and 1.

Cumulative distribution function of x.

ppf(self, q) [source]

Parameters: q : float between 0. and 1.

Quantile.

Returns: ppf(q) : float

Percent point function; inverse of self.cdf.

sf(self, x) [source]

Parameters: x : float

Returns: sf(x) : float between 0. and 1.

Survival function; 1-self.cdf.

isf(self, q) [source]

Parameters: q : float between 0. and 1.

Returns: isf(x) : float

Inverse survival function.

moment(self, degree=1, type_='raw', norm=False) [source]

Parameters: degree : int, default=1

The degree of the moment, e.g. first (mean), second (var). type_ : str, default='raw' Type of moment; 'raw', 'central', or 'standardized'. norm : bool, default=False Indicates whether to return the norm of the moment. If True, return moment**(1/degree).

Returns: moment : float

fit(self, lb, ub, constraints, objective=lambda self: self.entropy(), num=50) [source]

Parameters: lb : scalar

Lower bound of the distribution.

ub : scalar

Upper bound of the distribution.

constraints : list of callables

Constraints take in a Smoother and return a float. Lower values indicate that the constraints are satisfied.

objective :

The objective or smoothing function. The objective function takes a Smoother and returns a float. This objective function is maximized subject to constraints. By default, it maximizes entropy.

num : int, default=50

Number of points on the distribution used for approximation.

Returns: self :

dump(self) [source]

Returns: state_dict : dict

JSON dump of the state dictionary.

load(state_dict) [source]

Parameters: state_dict : dict

Output of Smoother.dump.

Returns: smoother : Smoother

Smoother with the specified state dictionary.