pfjax.models.bm_model

Module Contents

Classes

BMModel

Brownian motion state space model.

class pfjax.models.bm_model.BMModel(dt, unconstrained_theta=False)[source]

Bases: pfjax.models.base_model.BaseModel

Brownian 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