anml.parameter#

anml.parameter.main#

class anml.parameter.main.Parameter(variables, transform=None, offset=None, priors=None)[source]#

Bases: object

Parameter class contains information from a list of variables that are used to parametrize the distribution parameter. Parameter class also include optional transformation function, offset and list of priors.

Parameters
  • variables (List[Variable]) – A list of variables that parametrized the linear predictor of the parameter.

  • transform (Optional[SmoothMapping]) – A SmoothMapping instance that transforms the linear prediction from the variables to the parameter space. Default is None, which will be converted into identity mapping.

  • offset (Optional[Union[str, Component]]) – A data component contains the offset information for the parameter. Default is None which indicates no offset. Offset will be applied onto the linear predictor.

  • priors (Optional[List[Prior]]) – A list of additional priors that directly apply to the parameter linear predictor. Default is None, where no additional priors will be added.

property variables#

A list of variables that parametrized the linear predictor of the parameter.

Raises

TypeError – Raised if the input variables are not all instances of Variable.

property transform#

A function that transforms the linear prediction to the parameter space.

Raises

TypeError – Raised when the input transform is not an instance of SmoothMapping.

property offset#

Offset for the linear predictor.

Raises

TypeError – Raised when the input offset is not None, or a string, or an instance of DataComponent.

property priors#

A list of additional priors that apply to the linear predictor.

Raises

TypeError – Raised when the input priors are not None or a list of instances of Prior.

property size: int#

Size of the parameter coefficients. It is the sum of all sizes for variables.

attach(df)[source]#

Attach data frame to offset and cache the design matrix and gather the prior information.

Parameters

df (DataFrame) – Given data frame.

get_params(x, df=None, order=0)[source]#

Compute and return the parameter. Denote \(x\) as the coefficients, \(A\) as the design matrix, \(z\) as the offset, \(f\) as the transformation function, the parameter \(p\) can be represented as

\[p = f(z + Ax)\]

Here we call \(Ax\) as the linear predictor.

Parameters
  • x (NDArray) – Coefficients for the design matrix.

  • df (Optional[DataFrame]) – Given data frame used for compute the design matrix. Default is None.

  • order (int) – Order of the derivative. Default is 0.

Returns

When order=0, it will return the parameter value. When order=1, it will return the Jacobian matrix. And when order=2, it will return the second order Jacobian tensor.

Return type

NDArray

Raises

ValueError – Raised when there is not cache of the design matrix and no data frame is provided.

prior_objective(x)[source]#

Objective function from the prior.

Parameters

x (NDArray) – Coefficients for the design matrix.

Returns

Objective value from the prior.

Return type

float

prior_gradient(x)[source]#

Gradient function from the prior.

Parameters

x (NDArray) – Coefficients for the design matrix.

Returns

Gradient value from the prior.

Return type

NDArray

prior_hessian(x)[source]#

Hessian function from the prior.

Parameters

x (NDArray) – Coefficients for the design matrix.

Returns

Hessian value from the prior.

Return type

NDArray

anml.parameter.smoothmapping#

class anml.parameter.smoothmapping.SmoothMapping[source]#

Bases: abc.ABC

Smooth mapping that contains function, first and second derivative information.

property inverse: anml.parameter.smoothmapping.SmoothMapping#

Inverse function of the current instance. The inverse function is also an instance of SmoothMapping.

class anml.parameter.smoothmapping.Identity[source]#

Bases: anml.parameter.smoothmapping.SmoothMapping

Identity smooth mapping.

property inverse: anml.parameter.smoothmapping.SmoothMapping#

Inverse of Identity is Identity.

class anml.parameter.smoothmapping.Exp[source]#

Bases: anml.parameter.smoothmapping.SmoothMapping

Exponential smooth mapping.

property inverse: anml.parameter.smoothmapping.SmoothMapping#

Inverse of Exp is Log.

class anml.parameter.smoothmapping.Log[source]#

Bases: anml.parameter.smoothmapping.SmoothMapping

Logarithm smooth mapping.

Raises

ValueError – Raised when the argument is not all positive.

property inverse: anml.parameter.smoothmapping.SmoothMapping#

Inverse of Log is Exp.

class anml.parameter.smoothmapping.Expit[source]#

Bases: anml.parameter.smoothmapping.SmoothMapping

Expit smooth mapping.

\[\mathrm{expit}(x) = \frac{1}{1 + \exp(-x)}\]
property inverse: anml.parameter.smoothmapping.SmoothMapping#

Inverse of Expit is Logit.

class anml.parameter.smoothmapping.Logit[source]#

Bases: anml.parameter.smoothmapping.SmoothMapping

Logit smooth mapping.

\[\mathrm{logit}(x) = \log\left(\frac{x}{1 - x}\right)\]
Raises

ValueError – Raised when the argument is not all strictly between 0 and 1.

property inverse: anml.parameter.smoothmapping.SmoothMapping#

Inverse of Logit is Expit.