Gaussian Factorial Models
cuthbert.factorial.gaussian
Factorial utilities for Kalman states.
KalmanState = TypeVar('KalmanState', KalmanFilterState, LinearizedKalmanFilterState)
module-attribute
build_factorializer(get_factorial_indices)
Build a factorializer for Kalman states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_factorial_indices
|
GetFactorialIndices
|
Function to extract the factorial indices from model inputs. |
required |
Returns:
| Type | Description |
|---|---|
Factorializer
|
Factorializer object for Kalman states with functions to extract and join |
Factorializer
|
the relevant factors and marginalize and insert the updated factors. |
Source code in cuthbert/factorial/gaussian.py
extract(factorial_state, factorial_inds)
Extract the relevant factors from a factorial Kalman state.
Single dimensional arrays will be treated as scalars e.g. log normalizing constants. This means univariate problems still need to be stored with a dimension array (e.g. means with shape (F, 1) and chol_covs with shape (F, 1, 1)). Multidimensional arrays will be treated as arrays with shape (F, *). In this case the factorial_inds indices will be extracted from the first dimension and then the remaining dimensions will be preserved.
Here F is the number of factors and d is the dimension of the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factorial_state
|
KalmanState
|
Factorial Kalman state storing means and chol_covs with shape (F, d) and (F, d, d) respectively. |
required |
factorial_inds
|
ArrayLike
|
Indices of the factors to extract. Integer array. factorial_inds.ndim == 0 removes the factorial dimension and extracts a single factor. factorial_inds.ndim == 1 retains the factorial dimension, even if len(factorial_inds) == 1. |
required |
Returns:
| Type | Description |
|---|---|
KalmanState
|
Factorial Kalman state storing means and chol_covs with shape (len(factorial_inds), d) and (len(factorial_inds), d, d). If factorial_inds is a single integer, the returned local factorial state will not have a factorial dimension. |
Source code in cuthbert/factorial/gaussian.py
join(local_factorial_state)
Convert a factorial Kalman state into a joint local Kalman state.
Single dimensional arrays will be treated as scalars e.g. log normalizing constants. This means univariate problems still need to be stored with a dimension array (e.g. means with shape (F, 1) and chol_covs with shape (F, 1, 1)). Two dimensional arrays will be treated as means with shape (F, d). In this case the factorial_inds indices will be extracted from the first dimension and then stacked into a single array. Three dimensional arrays will be treated as chol_covs with shape (F, d, d). In this case the factorial_inds indices will be extracted from the first dimension and then stacked into a block diagonal array.
Here F is the number of factors and d is the dimension of the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_factorial_state
|
KalmanState
|
Factorial Kalman state storing means and chol_covs with shape (F, d) and (F, d, d) respectively. |
required |
Returns:
| Type | Description |
|---|---|
KalmanState
|
Joint local Kalman state with no factorial index dimension. |
Source code in cuthbert/factorial/gaussian.py
marginalize(local_state, num_factors)
Marginalize a joint local Kalman state into a factorial Kalman state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_state
|
KalmanState
|
Joint local Kalman state to marginalize and insert. With means and chol_covs with shape (d * len(factorial_inds),) and (d * len(factorial_inds), d * len(factorial_inds)) respectively. |
required |
num_factors
|
int
|
Number of factors to marginalize out. Integer. |
required |
Returns:
| Type | Description |
|---|---|
KalmanState
|
Joint local Kalman state with no factorial index dimension. |
Source code in cuthbert/factorial/gaussian.py
insert(local_factorial_state, factorial_state, factorial_inds)
Insert a local factorial Kalman state into a factorial Kalman state.
Single dimensional arrays will be treated as scalars e.g. log normalizing constants. This means univariate problems still need to be stored with a dimension array (e.g. means with shape (F, 1) and chol_covs with shape (F, 1, 1)). Multidimensional arrays will be treated as arrays with shape (F, *). In this case the factorial_inds indices will be inserted into the first dimension and then the remaining dimensions will be preserved.
Here F is the number of factors and d is the dimension of the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_factorial_state
|
KalmanState
|
Joint local Kalman state to marginalize and insert. With means and chol_covs with shape (len(factorial_inds), d) and (len(factorial_inds), d, d) respectively. |
required |
factorial_state
|
KalmanState
|
Factorial Kalman state storing means and chol_covs with shape (F, d) and (F, d, d) respectively. |
required |
factorial_inds
|
ArrayLike
|
Indices of the factors to insert. Integer array. |
required |
Returns:
| Type | Description |
|---|---|
KalmanState
|
Joint local Kalman state with no factorial index dimension. |