Smoothing
cuthbert.smoothing
Unified cuthbert smoothing interface.
smoother(smoother_obj, filter_states, model_inputs=None, parallel=False, key=None)
Applies offline smoothing given a smoother object, output from filter, and model inputs.
filter_states should have leading temporal dimension of length T + 1, where
T is the number of time steps excluding the initial state.
Each element of model_inputs refers to the transition from t to t+1, except for the
first element which refers to the initial state. The initial state model_inputs
are not used for smoothing. Thus the model_inputs used here have length T.
By default, filter_states.model_inputs[1:] are used (i.e. the model_inputs
used for the initial state is ignored).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smoother_obj
|
Smoother
|
The smoother inference object. |
required |
filter_states
|
ArrayTreeLike
|
The filtered states (with leading temporal dimension of length T + 1). |
required |
model_inputs
|
ArrayTreeLike | None
|
The model inputs (with leading temporal dimension of length T).
Optional, if None then |
None
|
parallel
|
bool
|
Whether to run the smoother in parallel.
Requires |
False
|
key
|
KeyArray | None
|
The key for the random number generator. |
None
|
Returns:
| Type | Description |
|---|---|
ArrayTree
|
The smoothed states (NamedTuple with leading temporal dimension of length T + 1). |
Source code in cuthbert/smoothing.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
cuthbert.inference
Provides protocols and types for representing unified inference objects.
Smoother
Bases: NamedTuple
Smoother object.
Typically passed to cuthbert.smoothing.smoother.
Attributes:
| Name | Type | Description |
|---|---|---|
convert_filter_to_smoother_state |
ConvertFilterToSmootherState
|
Function to convert the final filter state to a smoother state. |
smoother_prepare |
SmootherPrepare
|
Function to prepare intermediate states for the smoother. |
smoother_combine |
SmootherCombine
|
Function that combines two smoother states to produce another. |
associative |
bool
|
Whether |
convert_filter_to_smoother_state
instance-attribute
smoother_prepare
instance-attribute
smoother_combine
instance-attribute
associative = False
class-attribute
instance-attribute
SmootherPrepare
Bases: Protocol
Protocol for preparing the state for the smoother.
__call__(filter_state, model_inputs, key=None)
Prepare the state for the smoother at the next time point.
Converts filter_state with model_inputs (and any stochasticity) into a
unified state object which can be combined with a state (of the same form)
from the next time point with SmootherCombine.
Remember smoothing iterates backwards in time.
Note that the model_inputs here are different to filter_state.model_inputs.
The model_inputs required here are for the transition from t to t+1.
filter_state.model_inputs represents the transition from t-1 to t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_state
|
ArrayTreeLike
|
The state from the filter at the previous time point. |
required |
model_inputs
|
ArrayTreeLike
|
Model inputs for the transition from t to t+1. |
required |
key
|
KeyArray | None
|
The key for the random number generator. Optional, as only used for stochastic inference methods |
None
|
Returns:
| Type | Description |
|---|---|
ArrayTree
|
The state prepared for |
Source code in cuthbert/inference.py
SmootherCombine
Bases: Protocol
Protocol for combining the next smoother state with the state prepared with latest model inputs.
__call__(state_1, state_2)
Combine the state from the next time point with the state from SmootherPrepare.
Remember smoothing iterates backwards in time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_1
|
ArrayTreeLike
|
The state from |
required |
state_2
|
ArrayTreeLike
|
The state from the next time point. |
required |
Returns:
| Type | Description |
|---|---|
ArrayTree
|
The combined smoother state, a NamedTuple with inference-specific fields. |
Source code in cuthbert/inference.py
ConvertFilterToSmootherState
Bases: Protocol
Protocol for converting a filter state to a smoother state.
__call__(filter_state, model_inputs=None, key=None)
Convert the filter state to a smoother state.
Useful for offline smoothing where the final filter state is statistically equivalent to the final smoother state. This function converts the filter state to the smoother state data structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_state
|
ArrayTreeLike
|
The filter state. |
required |
model_inputs
|
ArrayTreeLike | None
|
Only used to create an empty |
None
|
key
|
KeyArray | None
|
The key for the random number generator. Optional, as only used for stochastic inference methods |
None
|
Returns:
| Type | Description |
|---|---|
ArrayTree
|
The smoother state. |