mesmer.distrib.Expression#
- class mesmer.distrib.Expression(expr, expr_name, boundaries_params=None, boundaries_coeffs=None)#
- __init__(expr, expr_name, boundaries_params=None, boundaries_coeffs=None)#
Symbolic expression of a conditional distribution.
When initialized, the class identifies the distribution, predictors, parameters and coefficients. The expression is then compiled so that it can be evaluated.
- Parameters:
expr (str) – Mathematical expression of the conditional distribution as a string.
expr_name (str) – Name for the expression.
boundaries_params (dict, optional) – Boundaries for the parameters. The keys are the names of the parameters, and the values are lists of two elements, the lower and upper bounds. The default is None, which will set the boundaries to [-inf, inf] for all parameters found in the expression, except scale which must be positive, so the lower boundary will be set to 0. These boundaries will later be enforced when fitting the conditional distribution.
boundaries_coeffs (dict, optional) – Boundaries for the coefficients. The keys are the names of the coefficients as written in the expression, and the values are lists of two elements, the lower and upper bounds. The default is None. These boundaries will later be enforced when fitting the conditional distribution.
Notes
A valid expression of a distribution contains the following elements:
a distribution: must be the name of a distribution in scipy.stats (discrete or or continuous)
the parameters: all names for the parameters of the distributions must be provided (as named in the scipy.stats distribution):
loc,scale,shape,mu,a,b,c, etc.predictors: predictors that the distribution will be conditional to, must be written like a variable in python and surrounded by
"__": e.g.__GMT__,__X1__,__gmt_tm1__, but NOT__gmt-1__,__#days__,__GMT,_GMT_etc.coefficients: coefficients of the predictors, must be named
"c#", with # being the number of the coefficient: e.g.c1,c2,c3.mathematical terms: mathematical terms for the evolutions are be written as they would be normally in python. Only functions from numpy (
np.*) are supported. Spaces do not matter in the equations.
Warning
Currently, the expression can only contain integers as numbers, no floats!
Examples
>>> Expression( ... "genextreme(loc=c1 + c2 * __pred1__, scale=c3 + c4 * __pred2__**2, c=c5)", ... "expr1" ... ) >>> Expression( ... "norm(loc=c1 + (c2 - c1) / ( 1 + np.exp(c3 * __GMT_t__ + c4 * __GMT_tm1__ - c5) ), scale=c6)", ... "expr2" ... )
Methods
__init__(expr, expr_name[, ...])Symbolic expression of a conditional distribution.
evaluate_params(coefficients_values, ...[, ...])Evaluates the parameters for the provided predictors and coefficients