@classmethod<EOL><INDENT>def rts_smoother(cls,state_dim, p_dynamic_callables, filter_means,<EOL>filter_covars):<DEDENT>
no_steps = filter_covars.shape[<NUM_LIT:0>]-<NUM_LIT:1><EOL>M = np.empty(filter_means.shape) <EOL>P = np.empty(filter_covars.shape) <EOL>M[-<NUM_LIT:1>,:] = filter_means[-<NUM_LIT:1>,:]<EOL>P[-<NUM_LIT:1>,:,:] = filter_covars[-<NUM_LIT:1>,:,:]<EOL>for k in range(no_steps-<NUM_LIT:1>,-<NUM_LIT:1>,-<NUM_LIT:1>):<EOL><INDENT>m_pred, P_pred, tmp1, tmp2 =cls._kalman_prediction_step(k, filter_means[k,:],<EOL>filter_covars[k,:,:], p_dynamic_callables,<EOL>calc_grad_log_likelihood=False)<EOL>p_m = filter_means[k,:]<EOL>if len(p_m.shape)<<NUM_LIT:2>:<EOL><INDENT>p_m.shape = (p_m.shape[<NUM_LIT:0>],<NUM_LIT:1>)<EOL><DEDENT>p_m_prev_step = M[k+<NUM_LIT:1>,:]<EOL>if len(p_m_prev_step.shape)<<NUM_LIT:2>:<EOL><INDENT>p_m_prev_step.shape = (p_m_prev_step.shape[<NUM_LIT:0>],<NUM_LIT:1>)<EOL><DEDENT>m_upd, P_upd, G_tmp = cls._rts_smoother_update_step(k,<EOL>p_m ,filter_covars[k,:,:],<EOL>m_pred, P_pred, p_m_prev_step ,P[k+<NUM_LIT:1>,:,:], p_dynamic_callables)<EOL>M[k,:] = m_upd<EOL>P[k,:,:] = P_upd<EOL><DEDENT>return (M, P)<EOL>
This function implements Rauch–Tung–Striebel(RTS) smoother algorithm
based on the results of kalman_filter_raw.
These notations are the same:
    x_{k} =  A_{k} * x_{k-1} + q_{k-1};       q_{k-1} ~ N(0, Q_{k-1})
    y_{k} = H_{k} * x_{k} + r_{k};            r_{k-1} ~ N(0, R_{k})

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

Input:
--------------

p_a: function (k, x_{k-1}, A_{k}). Dynamic function.
        k (iteration number), starts at 0
        x_{k-1} State from the previous step
        A_{k} Jacobian matrices of f_a. In the linear case it is exactly A_{k}.

p_f_A: function (k, m, P) return Jacobian of dynamic function, it is
    passed into p_a.
    k (iteration number), starts at 0
    m: point where Jacobian is evaluated
    P: parameter for Jacobian, usually covariance matrix.

p_f_Q: function (k). Returns noise matrix of dynamic model on iteration k.
    k (iteration number). starts at 0

filter_means: (no_steps+1,state_dim) matrix or (no_steps+1,state_dim, time_series_no) 3D array
    Results of the Kalman Filter means estimation.

filter_covars: (no_steps+1, state_dim, state_dim) 3D array
    Results of the Kalman Filter covariance estimation.

Output:
-------------

M: (no_steps+1, state_dim) matrix
    Smoothed estimates of the state means

P: (no_steps+1, state_dim, state_dim) 3D array
    Smoothed estimates of the state covariances