Prescribing probability functions#
- class equadratures.weight.Weight(weight_function, support=None, pdf=False, mean=None, variance=None)[source]#
The class offers a template to input bespoke weight (probability density) functions. The resulting weight function can be given to
Parameter
to create a bespoke analytical or data-driven parameter.- Parameters
weight_function (Callable,numpy.ndarray) – A callable function or an array of data representing the weights.
support (list, optional) – Lower and upper bounds of the weight respectively. Values such as
-inf
orinf
are not acceptable.pdf (bool, optional) – If set to
True
, then the weight_function is assumed to be normalised to integrate to unity. Otherwise, the integration constant is computed and used to normalise weight_function.mean (float, optional) – User-defined mean for distribution. When provided, the code does not compute the mean of the weight_function over its support.
variance (float, optional) – User-defined variance for distribution. When provided, the code does not compute the variance of the weight_function over its support.
Example
- Analytical weight functions
>>> # exp(-x)/sqrt(x) >>> pdf_1 = Weight(lambda x: np.exp(-x)/ np.sqrt(x), [0.00001, -np.log(1e-10)], >>> pdf=False) >>> >>> # A triangular distribution >>> a = 3. >>> b = 6. >>> c = 4. >>> mean = (a + b + c)/3. >>> var = (a**2 + b**2 + c**2 - a*b - a*c - b*c)/18. >>> pdf_2 = Weight(lambda x : 2*(x-a)/((b-a)*(c-a)) if (a <= x < c) >>> else( 2/(b-a) if (x == c) >>> else( 2*(b-x)/((b-a)*(b-c)))), >>> support=[a, b], pdf=True) >>> >>> # Passing to Parameter >>> param = Parameter(distribution='analytical', weight_function=pdf_2, order=2)
- Data driven weight functions
>>> # Constructing a kde based on given data, using Rilverman's rule for bandwidth selection >>> pdf_2 = Weight( stats.gaussian_kde(data, bw_method='silverman'), >>> support=[-3, 3.2]) >>> >>> # Passing to Parameter >>> param = Parameter(distribution='analytical', weight_function=pdf, order=2)
- get_pdf(points=None)[source]#
Returns the pdf associated with the distribution.
- Parameters
points (numpy.ndarray, optional) – Array of points to evaluate pdf at.
- Returns
Array with shape ( len(points),1 ) containing the probability distribution.
- Return type