Discrete Factorial Models
cuthbert.factorial.discrete
Factorial utilities for discrete HMM states.
build_factorializer(get_factorial_indices)
Build a factorializer for discrete HMM filter 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 discrete states with functions to extract and join |
Factorializer
|
the relevant factors and marginalize and insert the updated factors. |
Source code in cuthbert/factorial/discrete.py
extract(factorial_state, factorial_inds)
Extract the relevant factors from a factorial discrete filter state.
Here F is the number of factors and K is the number of states per factor. The relevant leaves are: - elem.f with shape (F, K, K) - elem.log_g with shape (F, K) Both leaves are indexed on the leading factorial axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factorial_state
|
DiscreteFilterState
|
Factorial discrete filter state storing transition-like arrays and log normalizing vectors with leading factorial dimension F. |
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 |
|---|---|
DiscreteFilterState
|
Factorial discrete filter state with: - elem.f of shape (len(factorial_inds), K, K) - elem.log_g of shape (len(factorial_inds), K) If factorial_inds is a single integer, the returned local factorial state will not have a factorial dimension. |
Source code in cuthbert/factorial/discrete.py
join(local_factorial_state)
Convert a local factorial discrete state into a joint local state.
This operation is applied to
- elem.f with shape (F, K, K), combined into a joint transition matrix of shape (KF, KF) via Kronecker products.
- elem.log_g with shape (F, K), mapped to a joint vector of shape (K**F,). In this implementation, log_g is treated as a shared log-normalizing scalar and broadcast to the joint state dimension.
Here F is the number of local factors and K is the number of states per factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_factorial_state
|
DiscreteFilterState
|
Local factorial discrete state storing leaves with leading factorial dimension F. |
required |
Returns:
| Type | Description |
|---|---|
DiscreteFilterState
|
Joint local discrete state with no factorial index dimension. |
Source code in cuthbert/factorial/discrete.py
marginalize(local_state, num_factors)
Marginalize a joint local discrete state into a local factorial state.
A joint local state stores
- elem.f with shape (KF, KF)
- elem.log_g with shape (K**F,)
This function returns: - elem.f with shape (F, K, K) by summing out all non-target factors. - elem.log_g with shape (F, K) by broadcasting the shared log-normalizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_state
|
DiscreteFilterState
|
Joint local discrete state with no factorial index dimension. |
required |
num_factors
|
int
|
Number of factors to marginalize out. Integer. |
required |
Returns:
| Type | Description |
|---|---|
DiscreteFilterState
|
Local factorial discrete state with leading factorial dimension num_factors. |
Source code in cuthbert/factorial/discrete.py
insert(local_factorial_state, factorial_state, factorial_inds)
Insert a local factorial discrete state into a factorial discrete state.
This operation is applied to
- elem.f: local factors are inserted at factorial_inds in the leading axis.
- elem.log_g: treated as a shared scalar log-normalizer and broadcast across all global factors/states.
Here F is the number of factors and K is the number of states per factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_factorial_state
|
DiscreteFilterState
|
Local factorial discrete state to insert. Leaves with a factorial axis should have first dimension len(factorial_inds). |
required |
factorial_state
|
DiscreteFilterState
|
Global factorial discrete state with first dimension F on leaves that carry a factorial axis. |
required |
factorial_inds
|
ArrayLike
|
Indices of the factors to insert. Integer array. |
required |
Returns:
| Type | Description |
|---|---|
DiscreteFilterState
|
Updated factorial discrete state with inserted factors. |