anml.getter#
anml.getter.prior#
- class anml.getter.prior.SplinePriorGetter(prior, size=100, order=0, domain=(0.0, 1.0), domain_type='rel')[source]#
Bases:
object
Prior getter for spline variable.
SplinePriorGetter
takes in a prior without the attribute mat. And when we call the get_prior function with a spline as the argument, it will generate and assign the the design matrix to the prior.- Parameters
prior (anml.prior.main.Prior) – Prior instance without attribute mat.
size (int) – Size of the spline prior. Default is 100. It determines the number of sample points in the specified domain.
order (int) – Order of the spline derivative. Default is 0.
domain (Tuple[float, float]) – Lower and upper bounds for domain. Default is (0.0, 1.0).
domain_type ({'rel', 'abs'}) – Type of the domain. Default is ‘rel’. It can only be ‘abs’ or ‘rel’. When it is ‘abs’, lower and upper bounds are interpreted as the absolute position of the domain. When it is ‘rel’, lower and upper bounds are treated as the percentage of the domain.
Examples
Here are some common spline priors.
import numpy as np from xspline import XSpline from anml.prior.main import UniformPrior from anml.prior.getter import SplinePriorGetter # increasing prior prior_getter = SplinePriorGetter(UniformPrior(lb=0.0, ub=np.inf), order=1) # decreasing prior prior_getter = SplinePriorGetter(UniformPrior(lb=-np.inf, ub=0.0), order=1) # convex prior prior_getter = SplinePriorGetter(UniformPrior(lb=0.0, ub=np.inf), order=2) # concave prior prior_getter = SplinePriorGetter(UniformPrior(lb=-np.inf, ub=0.0), order=2) # use the get_prior function create prior spline = XSpline(knots=np.linspace(0.0, 2.0, 5), degree=3) prior = prior_getter.get_prior(spline)
- property prior#
Prior instance without attribute mat.
- Raises
TypeError – Raised when prior is not an instance of
Prior
.ValueError – Raised when prior mat exists.
- property size#
Size of the spline prior.
- Raises
ValueError – Raised when input size is not positive.
- property order#
Order of the spline derivative.
- Raises
ValueError – Raised when input order is negative.
- property domain#
Lower and upper bounds for domain.
- Raises
ValueError – Raised when length of the input domain is less or geater than 2.
ValueError – Raised when domain lower bound is greater than upper bound.
- property domain_type#
Type of the domain.
- Raises
ValueError – Raised when the input is not one of ‘rel’ or ‘abs’.
anml.getter.spline#
- class anml.getter.spline.SplineGetter(knots, degree=3, l_linear=False, r_linear=False, include_first_basis=False, knots_type='abs')[source]#
Bases:
object
Spline getter for
XSpline
instance. Given the settings of the spline, when attach the data it can infer the knots position, construct and return an instance ofXSpline
.- Parameters
knots (numpy.ndarray[Any, numpy.dtype[numpy.typing._generic_alias.ScalarType]]) – Knots placement of the spline. Depends on knots_type this will be used differently.
degree (int) – Degree of the spline. Default to be 3.
l_linear (bool) – If True, spline will use left linear tail. Default to be False.
r_linear (bool) – If True, spline will use right linear tail. Default to be False.
include_first_basis (bool) – If True, spline will include the first basis of the spline. Default to be True.
knots_type ({'abs', 'rel_domain', 'rel_freq'}) – Type of the spline knots. Can only be choosen from three options, ‘abs’, ‘rel_domian’ and ‘rel_freq’. When it is ‘abs’ which standards for absolute, the knots will be used as it is. When it is rel_domain which standards for relative domain, the knots requires to be between 0 and 1, and will be interpreted as the proportion of the domain. And when it is rel_freq which standards for relative frequency, it will be interpreted as the frequency of the data and required to be between 0 and 1.
- property knots_type#
Type of the spline knots.
- Raises
ValueError – Raised when the input knots type are not one of ‘abs’, ‘rel_domain’ or ‘rel_freq’.
- property num_spline_bases: int#
Number of the spline bases.