Factorial Utilities
cuthbert.factorial.utils
Utility functions to convert between serial and factorial trees.
serial_to_factorial(extract, serial_tree, factorial_inds, init_factorial_tree=None)
Convert a serial tree into a list of trees, one for each factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extract
|
Extract
|
Function to extract the relevant factors from the serial tree. |
required |
serial_tree
|
ArrayTreeLike
|
The serial tree to convert.
Each leaf of the tree should have shape (T, F, ...) where T is the number of
time steps and F is the number of factors.
Although some leaves may not have the factorial dimension F, as controlled
by the |
required |
factorial_inds
|
ArrayLike
|
The indices of the factors used in each element of the serial tree. Shape (T, F). |
required |
init_factorial_tree
|
ArrayTree
|
Optional initial factorial tree to use, as the first elements of the returned list. Leaves with shape (F, ...) |
None
|
Returns:
| Type | Description |
|---|---|
list[ArrayTree]
|
A list of trees, one for each factor. Length max(factorial_inds) + 1. Each element has shape (T_i, ...) where T_i is the number of occurrences of index i in factorial_inds (which may be zero). |
Source code in cuthbert/factorial/utils.py
serial_to_single_factor(extract, serial_tree, factorial_inds, factorial_index, init_factorial_tree=None)
Convert a serial tree into a single factor tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extract
|
Extract
|
Function to extract the relevant factors from the serial tree. |
required |
serial_tree
|
ArrayTreeLike
|
The serial tree to convert. Each leaf of the tree should have shape (T, F, ...) where T is the number of time steps and F is the number of factors. |
required |
factorial_inds
|
ArrayLike
|
The indices of the factors used in each element of the serial tree. Shape (T, F). |
required |
factorial_index
|
int
|
Single integer index of the factor to extract. |
required |
init_factorial_tree
|
ArrayTree
|
Optional initial factorial tree to use, as the first elements of the returned list. Leaves with shape (F, ...) of which only the factorial_index element will be used. |
None
|
Returns:
| Type | Description |
|---|---|
ArrayTree
|
A single ArrayTree with shape (T_i, ...) where T_i is the number of occurrences of |
ArrayTree
|
the factorial index in factorial_inds. |