@classmethod<EOL><INDENT>def _cont_discr_kalman_filter_raw(cls,state_dim, p_dynamic_callables, p_measurement_callables, X, Y,<EOL>m_init, P_init,<EOL>p_kalman_filter_type='<STR_LIT>',<EOL>calc_log_likelihood=False,<EOL>calc_grad_log_likelihood=False, grad_params_no=None,<EOL>dm_init=None, dP_init=None):<DEDENT>
<EOL>steps_no = Y.shape[<NUM_LIT:0>] <EOL>time_series_no = Y.shape[<NUM_LIT:2>] <EOL>M = np.empty(((steps_no+<NUM_LIT:1>),state_dim,time_series_no))<EOL>M[<NUM_LIT:0>,:,:] = m_init <EOL>P = np.empty(((steps_no+<NUM_LIT:1>),state_dim,state_dim))<EOL>P_init = <NUM_LIT:0.5>*( P_init + P_init.T) <EOL>P[<NUM_LIT:0>,:,:] = P_init <EOL>if p_kalman_filter_type == '<STR_LIT>':<EOL><INDENT>(U,S,Vh) = sp.linalg.svd( P_init,full_matrices=False, compute_uv=True,<EOL>overwrite_a=False,check_finite=True)<EOL>S[ (S==<NUM_LIT:0>) ] = <NUM_LIT> <EOL>P_upd = (P_init, S,U)<EOL><DEDENT>log_likelihood = <NUM_LIT:0> if calc_log_likelihood else None<EOL>grad_log_likelihood = <NUM_LIT:0> if calc_grad_log_likelihood else None<EOL>dm_upd = dm_init<EOL>dP_upd = dP_init<EOL>for k in range(<NUM_LIT:0>,steps_no):<EOL><INDENT>prev_mean = M[k,:,:] <EOL>if p_kalman_filter_type == '<STR_LIT>':<EOL><INDENT>m_pred, P_pred, dm_pred, dP_pred =cls._kalman_prediction_step_SVD(k, prev_mean ,P_upd, p_dynamic_callables,<EOL>calc_grad_log_likelihood=calc_grad_log_likelihood,<EOL>p_dm = dm_upd, p_dP = dP_upd)<EOL><DEDENT>else:<EOL><INDENT>m_pred, P_pred, dm_pred, dP_pred =cls._kalman_prediction_step(k, prev_mean ,P[k,:,:], p_dynamic_callables,<EOL>calc_grad_log_likelihood=calc_grad_log_likelihood,<EOL>p_dm = dm_upd, p_dP = dP_upd )<EOL><DEDENT>k_measurment = Y[k,:,:]<EOL>if (np.any(np.isnan(k_measurment)) == False):<EOL><INDENT>if p_kalman_filter_type == '<STR_LIT>':<EOL><INDENT>m_upd, P_upd, log_likelihood_update, dm_upd, dP_upd, d_log_likelihood_update =cls._kalman_update_step_SVD(k,  m_pred , P_pred, p_measurement_callables,<EOL>k_measurment, calc_log_likelihood=calc_log_likelihood,<EOL>calc_grad_log_likelihood=calc_grad_log_likelihood,<EOL>p_dm = dm_pred, p_dP = dP_pred )<EOL><INDENT>m_upd, P_upd, log_likelihood_update, dm_upd, dP_upd, d_log_likelihood_update =cls._kalman_update_step(k,  m_pred , P_pred[<NUM_LIT:0>], f_h, f_H, p_R.f_R, k_measurment,<EOL>calc_log_likelihood=calc_log_likelihood,<EOL>calc_grad_log_likelihood=calc_grad_log_likelihood,<EOL>p_dm = dm_pred, p_dP = dP_pred, grad_calc_params_2 = (dH, dR))<EOL>(U,S,Vh) = sp.linalg.svd( P_upd,full_matrices=False, compute_uv=True,<EOL>overwrite_a=False,check_finite=True)<EOL>P_upd = (P_upd, S,U)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>m_upd, P_upd, log_likelihood_update, dm_upd, dP_upd, d_log_likelihood_update =cls._kalman_update_step(k,  m_pred , P_pred, p_measurement_callables, k_measurment,<EOL>calc_log_likelihood=calc_log_likelihood,<EOL>calc_grad_log_likelihood=calc_grad_log_likelihood,<EOL>p_dm = dm_pred, p_dP = dP_pred )<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if k_measurment.shape != (<NUM_LIT:1>,<NUM_LIT:1>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>m_upd = m_pred; P_upd = P_pred; dm_upd = dm_pred; dP_upd = dP_pred<EOL>log_likelihood_update = <NUM_LIT:0.0>;<EOL>d_log_likelihood_update = <NUM_LIT:0.0>;<EOL><DEDENT><DEDENT>if calc_log_likelihood:<EOL><INDENT>log_likelihood += log_likelihood_update<EOL><DEDENT>if calc_grad_log_likelihood:<EOL><INDENT>grad_log_likelihood += d_log_likelihood_update<EOL><DEDENT>M[k+<NUM_LIT:1>,:,:] = m_upd <EOL>if p_kalman_filter_type == '<STR_LIT>':<EOL><INDENT>P[k+<NUM_LIT:1>,:,:] = P_upd[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>P[k+<NUM_LIT:1>,:,:] = P_upd<EOL><DEDENT><DEDENT>return (M, P, log_likelihood, grad_log_likelihood, p_dynamic_callables.reset(False))<EOL>
General filtering algorithm for inference in the continuos-discrete
state-space model:

    d/dt x(t) =  F * x(t) + L * w(t);         w(t) ~ N(0, Qc)
    y_{k} = H_{k} * x_{k} + r_{k};            r_{k-1} ~ N(0, R_{k})

Returns estimated filter distributions x_{k} ~ N(m_{k}, P(k))

Current Features:
----------------------------------------

1) Function support "multiple time series mode" which means that exactly
the same State-Space model is used to filter several sets of measurements.
In this case third dimension of Y should include these state-space measurements
Log_likelihood and Grad_log_likelihood have the corresponding dimensions then.

2) Measurement may include missing values. In this case update step is
not done for this measurement. (later may be changed)

Input:
-----------------
state_dim: int
    Demensionality of the states

F: (state_dim, state_dim) matrix
    F in the model.

L: (state_dim, noise_dim) matrix
    L in the model.

Qc: (noise_dim, noise_dim) matrix
    Q_c in the model.

P_inf: (state_dim, state_dim) matrix
    State varince matrix on infinity.

p_h: function (k, x_{k}, H_{k}). Measurement function.
    k (iteration number),
    x_{k}
    H_{k} Jacobian matrices of f_h. In the linear case it is exactly H_{k}.

f_H: function (k, m, P) return Jacobian of dynamic function, it is
    passed into p_h.
    k (iteration number),
    m: point where Jacobian is evaluated,
    P: parameter for Jacobian, usually covariance matrix.

p_f_R: function (k). Returns noise matrix of measurement equation
    on iteration k.
    k (iteration number).

m_init: vector or matrix
    Initial distribution mean. For "multiple time series mode"
    it is matrix, second dimension of which correspond to different
    time series. In regular case ("one time series mode") it is a
    vector.

P_init: matrix or scalar
    Initial covariance of the states. Must be not None
    "multiple time series mode" does not affect it, since it does not
    affect anything related to state variaces.

p_kalman_filter_type: string, one of ('regular', 'svd')
    Which Kalman Filter is used. Regular or SVD. SVD is more numerically
    stable, in particular, Covariace matrices are guarantied to be
    positive semi-definite. However, 'svd' works slower, especially for
    small data due to SVD call overhead.

calc_log_likelihood: boolean
    Whether to calculate marginal likelihood of the state-space model.

calc_grad_log_likelihood: boolean
    Whether to calculate gradient of the marginal likelihood
    of the state-space model. If true then the next parameter must
    provide the extra parameters for gradient calculation.

grad_params_no: int
    Number of gradient parameters

dP_inf, dF, dQc, dH, dR, dm_init, dP_init: matrices or 3D arrays.
    Necessary parameters for derivatives calculation.