anml.variable

anml.variable.main

class anml.variable.main.Variable(component, priors=None)[source]

Bases: object

Variable class that contains information of variable, including name and priors. It provides functions of create design matrix and gather prior information for likelihood building.

Parameters
  • component (Union[str, anml.data.component.Component]) – You can pass in the name of the variable corresponding to the column name in the data frame. It will be automatically converted into an instance of Component with NoNans as the validator. Alternatively, you can also pass in an instance of Component, with your own set of validators.

  • priors (Optional[List[anml.prior.main.Prior]]) – A list of priors corresponding to the variable.

property component

Data compoent for the variable.

Raises

TypeError – Raised when the input component are not a string nor an instance of Component.

property priors

A list of priors corresponding to the variable.

Raises

TypeError – Raised when the input priors are not a list of given prior types. Different classes have different legal prior types that is stored in a protected class variable _prior_types.

property size: Optional[int]

Size of the variable.

attach(df)[source]

Attach the data to variable. It will attach data to the component.

Parameters

df (pandas.core.frame.DataFrame) – The data frame contains the corresponding data column.

get_design_mat(df)[source]

Get design matrix.

Parameters

df (pandas.core.frame.DataFrame) – The data frame contains the corresponding data column.

Returns

The design matrix as a numpy array.

Return type

NDArray

get_direct_prior_params(prior_type)[source]

Get the direct prior parameters. The direct prior refers to the priors that do not have a linear map and direct act on the variable. We require that one variable can only have one direct prior for a given prior type. If there is no direct prior in the prior list, we will use the default prior parameters of the given prior type.

Parameters

prior_type (str) – Given name of the prior type.

Returns

The prior parameters as an array.

Return type

NDArray

Raises
  • ValueError – Raised when have more than one direct priors.

  • ValueError – Raised when the size of the prior parameters doesn’t match with the size of the variable.

get_linear_prior_params(prior_type)[source]

Get the linear prior parameters. The linear prior refers to the priors that contain a linear map. If there is no linear prior in the prior list, we will return empty arrays that match the size of the variable.

Parameters

prior_type (str) – Given name of the prior type.

Returns

The prior parameters as an array. The first one is the distribution parameters and the second one is the linear map.

Return type

Tuple[NDArray, NDArray]

Raises

ValueError – Raised when the size of the prior parameters doesn’t match with the size of the variable.

anml.variable.spline

anml.variable.spline.SplineVariablePrior

Allowed prior type for spline variable.

alias of Union[anml.prior.main.Prior, anml.getter.prior.SplinePriorGetter]

class anml.variable.spline.SplineVariable(component, spline, priors=None)[source]

Bases: anml.variable.main.Variable

Variable class that contains information of variable, including name, priors and spline.

Parameters
  • component (Union[str, anml.data.component.Component]) – You can pass in the name of the variable corresponding to the column name in the data frame. It will be automatically converted into an instance of Component with NoNans as the validator. Alternatively, you can also pass in an instance of Component, with your own set of validators.

  • spline (Union[xspline.core.XSpline, anml.getter.spline.SplineGetter]) – Given spline for the variable. You can pass in an instance of XSpline or SplineGetter. If input is an instance of SplineGetter, when use attach data it will automatically envolve into an instance of XSpline.

  • priors (Optional[List[Union[anml.prior.main.Prior, anml.getter.prior.SplinePriorGetter]]]) – A list of priors corresponding to the variable. The prior in the list can be either an instance of Prior or SplinePriorGetter. When attach data, the instance of SplinePriorGetter will envolve into an instance of Prior.

property spline

Given spline for the variable.

Raises

TypeError – Raised if input spline is not an instance of XSpline nor SplineGetter.

property size: int

Size of the variable.

attach(df)[source]

Attach the data to variable. It will attach data to the component. And create spline and priors if necessary.

Parameters

df (pandas.core.frame.DataFrame) – The data frame contains the corresponding data column.

get_design_mat(df)[source]

Get design matrix.

Parameters

df (pandas.core.frame.DataFrame) – The data frame contains the corresponding data column.

Returns

The design matrix as a numpy array.

Return type

NDArray