5.5. pypfilt.obs¶
All observations models should derive the following base class:
-
class
pypfilt.obs.
Obs
¶ The base class of observation models, which defines the minimal set of methods that are required.
-
log_llhd
(ctx, op, time, obs, curr, hist)¶ Return the log-likelihood \(\mathcal{l}(y_t \mid x_t)\) for the observation \(y_t\) and every particle \(x_t\).
Parameters: - ctx – The simulation context.
- op – The observation model parameters dictionary.
- time – The current simulation time, \(t\).
- obs – An observation for the current time-step, \(y_t\).
- curr – The particle state vectors, \(x_t\).
- hist – The particle state histories, indexed by observation period.
-
expect
(ctx, op, time, period, prev, curr)¶ Return the expected observation value \(\mathbb{E}[y_t]\) for every particle \(x_t\), at one or more times \(t\).
Parameters: - ctx – The simulation context.
- op – The observation model parameters dictionary.
- time – The simulation time(s), \(t\).
- period – The duration of the observation period (in days).
- prev – The state vectors at the start of the observation period(s), \(x_t\).
- curr – The state vectors at the end of the observation period(s).
-
quantiles
(ctx, op, time, mu, wt, probs)¶ Return the values \(y_i\) that satisfy:
\[y_i = \inf\left\{ y : p_i \le \sum_i w_i \cdot \mathcal{L}(y_t \le y \mid x_t^i)\right\}\]Parameters: - ctx – The simulation context.
- op – The observation model parameters dictionary.
- time – The current simulation time, \(t\).
- mu – The expected case fraction for each particle, \(\mathbb{E}(y_t)\).
- wt – The weight associated with each particle, \(w_i\).
- probs – The probabilities \(p_i\), which must be sorted in ascending order.
-
simulate
(ctx, op, time, period, expected, rng=None)¶ Return a random sample of \(y_t\) for each particle \(x_t\).
Parameters: - ctx – The simulation context.
- op – The observation model parameters dictionary.
- time – The simulation time(s), \(t\).
- period – The duration of the observation period (in days).
- expected – The expected observation value for each particle \(x_t\).
- rng – The (optional) random number generator to use.
-
from_file
(filename, time_scale)¶ Load observations from a space-delimited text file with column headers defined in the first line.
Parameters: - filename – The file to read.
- time_scale – The simulation time scale.
Returns: A list of observations, ordered as per the original file, and the underlying data table.
Return type: Tuple[List[dict], numpy.ndarray]
-
-
pypfilt.obs.
expect
(ctx, time, unit, period, prev, curr)¶ Return the expected observation value \(\mathbb{E}[y_t]\) for every every particle \(x_t\), at one or more times \(t\).
Parameters: - ctx – The simulation context.
- time – The simulation time(s).
- unit (str) – The observation units (see classes in :py:module`data`).
- period (int) – The duration of the observation period (in days).
- prev (numpy.ndarray) – The state vectors at the start of the observation period(s).
- curr (numpy.ndarray) – The state vectors at the end of the observation period(s).
-
pypfilt.obs.
log_llhd_of
(ctx, hist, hist_ix, obs, max_back=None)¶ Return the log-likelihood of obtaining observations from each particle.
Parameters: - ctx – The simulation context.
- hist – The particle history matrix.
- hist_ix – The index of the current time-step in the history matrix.
- obs – The observation(s) that have been made.
- max_back – The number of time-steps into the past when the most
recent resampling occurred (i.e., how far back the current particle
ordering is guaranteed to persist; default is
None
, no limit).
Returns: An array containing the log-likelihood for each particle.
-
pypfilt.obs.
bisect_cdf
(probs, cdf_fn, bisect_fn, y_lower, y_upper)¶ Use a bisection method to estimate the values \(y_i\) that satisfy:
\[y_i = \inf\left\{ y : p_i \le \sum_i w_i \cdot \mathcal{L}(y_t \le y \mid x_t^i)\right\}\]Parameters: - probs – The probabilities \(p_i\), which must be sorted in ascending order.
- cdf_fn – The CDF function \(f(y) = \sum_i w_i \cdot \mathcal{L}(y_t \le y \mid x_t^i)\).
- bisect_fn – The bisection function
f(a, b)
that either returns the midpoint of the interval \([a, b]\) orNone
if the search should stop (e.g., because a tolerance has been reached). - y_lower – A lower bound for all \(y_i\).
- y_upper – An upper bound for all \(y_i\).
-
pypfilt.obs.
simulate
(ctx, time, unit, period, expected, rng=None)¶ Return a random sample of \(y_t\) for each particle \(x_t\).
Parameters: - ctx – The simulation context.
- time – The simulation time.
- unit – The observation unit.
- period – The duration of the observation period (in days).
- expected – The expected observation value for each particle \(x_t\).
- rng – The (optional) random number generator to use.