pfjax.models
Submodules
Package Contents
Classes
Brownian motion state space model. |
|
Lotka-Volterra predator-prey model. |
|
Prokaryotic auto-regulatory gene network Model. |
- class pfjax.models.BMModel(dt, unconstrained_theta=False)[source]
Bases:
pfjax.models.base_model.BaseModelBrownian motion state space model.
The model is:
x_0 ~ pi(x_0) \propto 1 x_t ~ N(x_{t-1} + mu dt, sigma^2 dt) y_t ~ N(x_t, tau^2)
- Parameters
dt – Interobservation time.
unconstrained_theta – Whether or not to use the regular parameters scale theta = (mu, sigma, tau) or the unconstrained scale theta = (mu, log(sigma), log(tau)).
- state_lpdf(x_curr, x_prev, theta)[source]
Calculates the log-density of p(x_curr | x_prev, theta).
- Parameters
x_curr – State variable at current time t.
x_prev – State variable at previous time t-1.
theta – Parameter value.
- Returns
The log-density of p(x_curr | x_prev, theta).
- state_sample(key, x_prev, theta)[source]
Samples from x_curr ~ p(x_curr | x_prev, theta).
- Parameters
key – PRNG key.
x_prev – State variable at previous time t-1.
theta – Parameter value.
- Returns
x_curr ~ p(x_curr | x_prev, theta).
- Return type
Sample of the state variable at current time t
- meas_lpdf(y_curr, x_curr, theta)[source]
Log-density of p(y_curr | x_curr, theta).
- Parameters
y_curr – Measurement variable at current time t.
x_curr – State variable at current time t.
theta – Parameter value.
- Returns
The log-density of p(y_curr | x_curr, theta).
- meas_sample(key, x_curr, theta)[source]
Sample from p(y_curr | x_curr, theta).
- Parameters
key – PRNG key.
x_curr – State variable at current time t.
theta – Parameter value.
- Returns
y_curr ~ p(y_curr | x_curr, theta).
- Return type
Sample of the measurement variable at current time t
- pf_init(key, y_init, theta)[source]
Get particles for initial state x_init = x_state[0].
Samples from an importance sampling proposal distribution
x_init ~ q(x_init) = q(x_init | y_init, theta)
and calculates the log weight
logw = log p(y_init | x_init, theta) + log p(x_init | theta) - log q(x_init)
In this case we have an exact proposal
q(x_init) = p(x_init | y_init, theta) <=> x_init ~ N(y_init, tau)
Moreover, due to symmetry of arguments we have q(x_init) = p(y_init | x_init, theta), and since p(x_init | theta) propto 1 we have logw = 0.
- Parameters
key – PRNG key.
y_init – Measurement variable at initial time t = 0.
theta – Parameter value.
- Returns
x_init - A sample from the proposal distribution for x_init.
logw - The log-weight of x_init.
- Return type
Tuple
- loglik_exact(y_meas, theta)[source]
Marginal loglikelihood of the BM model.
Actually calculates log p(y_{1:N} | theta, y_0), since for the flat prior on x_0 the marginal likelihood p(y_{0:N} | theta) does not exist.
- Parameters
y_meas – Vector of observations y_0, …, y_N.
theta – Parameter value.
- Returns
The marginal loglikelihood log p(y_{1:N} | theta, y_0).
- Return type
float
- class pfjax.models.LotVolModel(dt, n_res)[source]
Bases:
pfjax.sde.SDEModelLotka-Volterra predator-prey model.
The model is:
exp(x_m0) = exp( (logH_m0, logL_m0) ) ~ pi(x_m0) \propto 1 logH_mt ~ N(logH_{m,t-1} + (alpha - beta exp(logL_{m,t-1})) dt/m, sigma_H^2 dt/m) logL_mt ~ N(logL_{m,t-1} + (-gamma + delta exp(logH_{m,t-1})) dt/m, sigma_L^2 dt/m) y_t ~ N( exp(x_{m,mt}), diag(tau_H^2, tau_L^2) )
Model parameters: theta = (alpha, beta, gamma, delta, sigma_H, sigma_L, tau_H, tau_L).
Global constants: dt and n_res, i.e., m.
State dimensions: n_state = (n_res, 2).
Measurement dimensions: n_meas = 2.
Notes:
The measurement y_t corresponds to x_t = (x_{m,(t-1)m+1}, …, x_{m,tm}), i.e., aligns with the last element of x_t.
The prior is such that p(x_0 | y_0, theta) is given by:
x_{m,n} = 0 for n = -m+1, ..., -1, exp(x_{m0}) ~ TruncatedNormal( y_0, diag(tau_H^2, tau_L^2) ),
where
z ~ TruncatedNormal(mu, diag(sigma^2)) <=> z = mu + diag(sigma) Z_0, Z_0 ~iid N(0,1) truncated at -mu.
- Parameters
dt – SDE interobservation time.
n_res – SDE resolution number. There are n_res latent variables per observation, equally spaced with interobservation time dt/n_res.
- meas_lpdf(y_curr, x_curr, theta)[source]
Log-density of p(y_curr | x_curr, theta).
- Parameters
y_curr – Measurement variable at current time t.
x_curr – State variable at current time t.
theta – Parameter value.
- Returns
The log-density of p(y_curr | x_curr, theta).
- meas_sample(key, x_curr, theta)[source]
Sample from p(y_curr | x_curr, theta).
- Parameters
key – PRNG key.
x_curr – State variable at current time t.
theta – Parameter value.
- Returns
y_curr ~ p(y_curr | x_curr, theta).
- Return type
Sample of the measurement variable at current time t
- pf_init(key, y_init, theta)[source]
Importance sampler for x_init.
See file comments for exact sampling distribution of p(x_init | y_init, theta), i.e., we have a “perfect” importance sampler with logw = CONST(theta).
- Parameters
key – PRNG key.
y_init – Measurement variable at initial time t = 0.
theta – Parameter value.
- Returns
x_init: A sample from the proposal distribution for x_init.
logw: The log-weight of x_init.
- Return type
Tuple
- class pfjax.models.PGNETModel(dt, n_res, bootstrap=True)[source]
Bases:
pfjax.sde.SDEModelProkaryotic auto-regulatory gene network Model.
The base model involves differential equations of the chemical reactions:
DNA + P2 --> DNA_P2 DNA_P2 --> DNA + P2 DNA --> DNA + RNA RNA --> RNA + P P + P --> P2 P2 --> P + P RNA --> 0 P --> 0
These equations are associated with a parameter in theta = (theta0, …, theta7). The model is approximated by a SDE described in Golightly & Wilkinson (2005). A particular restriction on the chemical reactions is by the conservation law which implies that DNA + DNA_P2 = K. Thus the SDE model can be described in terms of x_t = (RNA, P, P2, DNA).
Then assuming a standard form of the SDE, the base model can be written as
x_mt = x_{m, t-1} + mu_mt dt/m + Sigma_mt^{1/2} dt/m y_t ~ N( exp(x_{m,mt}), diag(tau^2) )
Ito’s Lemma is applied to transform the base model on the log-scale to allow for unconstrained variables
logx_mt = log(x_mt)
so mu_mt and Sigma_mt are transformed accordingly.
Model parameters: theta = (theta0, … theta7, tau0, … tau3).
Global constants: dt and n_res, i.e., m.
State dimensions: n_state = (n_res, 4).
Measurement dimensions: n_meas = 4.
- Parameters
dt – SDE interobservation time.
n_res – SDE resolution number. There are n_res latent variables per observation, equally spaced with interobservation time dt/n_res.
bootstrap (bool) – Flag indicating whether to use a Bootstrap particle filter or a bridge filter.
- meas_lpdf(y_curr, x_curr, theta)[source]
Log-density of p(y_curr | x_curr, theta).
- Parameters
y_curr – Measurement variable at current time t.
x_curr – State variable at current time t.
theta – Parameter value.
- Returns
The log-density of p(y_curr | x_curr, theta).
- meas_sample(key, x_curr, theta)[source]
Sample from p(y_curr | x_curr, theta).
- Parameters
x_curr – State variable at current time t.
theta – Parameter value.
key – PRNG key.
- Returns
y_curr ~ p(y_curr | x_curr, theta).
- Return type
Sample of the measurement variable at current time t
- pf_init(key, y_init, theta)[source]
Particle filter calculation for x_init.
Samples from an importance sampling proposal distribution
x_init ~ q(x_init) = q(x_init | y_init, theta)
and calculates the log weight
logw = log p(y_init | x_init, theta) + log p(x_init | theta) - log q(x_init)
FIXME: Explain what the proposal is and why it gives logw = CONST.
- Parameters
y_init – Measurement variable at initial time t = 0.
theta – Parameter value.
key – PRNG key.
- Returns
x_init: A sample from the proposal distribution for x_init.
logw: The log-weight of x_init.
- Return type
Tuple
- pf_step(key, x_prev, y_curr, theta)[source]
Get particles at subsequent steps.
- Parameters
x_prev – State variable at previous time t-1.
y_curr – Measurement variable at current time t.
theta – Parameter value.
key – PRNG key.
- Returns
x_curr: Sample of the state variable at current time t: x_curr ~ q(x_curr).
logw: The log-weight of x_curr.
- Return type
Tuple