HistoryTracker
Pre-allocated, growable storage for a state (and time) history. Backs
Model.hist / Model.hist_t, so that repeated forecast steps do not
reallocate on every call.
dynamodels.history.HistoryTracker
Pre-allocated, growable storage for a state (and time) history.
Backs dynamodels.model.Model and bias estimators in downstream packages:
states are written into two pre-allocated arrays, _hist (shape
(capacity, N, m)) and _hist_t (shape (capacity,)), so that
appending new states (the common case, one per forecast step) does not
reallocate on every call. current_ti tracks the index of the next empty
slot; hist / hist_t expose only the [:current_ti] valid prefix.
When the buffer fills up, _increase_hist_size grows it in bulk.
Source code in dynamodels/history.py
8 9 10 11 12 13 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
hist
property
ndarray: The valid (non-empty) portion of the state buffer,
_hist[:current_ti], shape (current_ti, N, m).
hist_t
property
ndarray: The valid portion of the time buffer,
_hist_t[:current_ti], shape (current_ti,).
capacity
property
int: Total number of pre-allocated slots, _hist_t.shape[0]
(>= current_ti).
current_state
property
ndarray: Most recent state, hist[current_ti - 1].
current_time
property
float: Time stamp of current_state.
current_ti = 0
instance-attribute
property
writable
int: Index of the next empty slot in the buffer (i.e. the number of valid entries currently stored).
__init__(initial_capacity=1000)
Initialise an empty tracker (the storage arrays themselves are
allocated lazily, by the first update_history(..., reset=True)
call).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_capacity
|
int
|
Initial capacity of the history arrays. |
1000
|
Source code in dynamodels/history.py
61 62 63 64 65 66 67 68 69 70 71 72 73 | |
update_history(state, t, reset=False, modify_saved_states=False)
Write state into the history buffer.
Three mutually exclusive modes, selected by reset /
modify_saved_states:
reset=True: replace the entire buffer withstate(via_reset_history), re-allocating storage sized tomax(state.shape[0], initial_capacity).modify_saved_states=True: overwrite the most recentstate.shape[0]already-stored entries in place (via_reset_last_states), without advancingcurrent_ti.- otherwise (default): append
stateas new entries starting atcurrent_ti, growing the buffer first (via_increase_hist_size) if it would not fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ndarray
|
State(s) to write. In append mode (the default) must have shape
|
required |
t
|
ndarray or None
|
Time stamp(s) matching |
required |
reset
|
bool
|
If True, replace the entire history (see above). |
False
|
modify_saved_states
|
bool
|
If True, overwrite recent entries in place instead of appending
(see above); ignored if |
False
|
Source code in dynamodels/history.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |