@classmethod<EOL><INDENT>def extended_kalman_filter(cls,p_state_dim, p_a, p_f_A, p_f_Q, p_h, p_f_H, p_f_R, Y, m_init=None,<EOL>P_init=None,calc_log_likelihood=False):<DEDENT>
<EOL>Y.shape, old_Y_shape  =  cls._reshape_input_data(Y.shape)<EOL>if m_init is None:<EOL><INDENT>m_init = np.zeros((p_state_dim,<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>m_init = np.atleast_2d(m_init).T<EOL><DEDENT>if P_init is None:<EOL><INDENT>P_init = np.eye(p_state_dim)<EOL><DEDENT>elif not isinstance(P_init, collections.Iterable): <EOL><INDENT>P_init = P_init*np.eye(p_state_dim)<EOL><DEDENT>if p_a is None:<EOL><INDENT>p_a = lambda k,m,A: np.dot(A, m)<EOL><DEDENT>old_A_shape = None<EOL>if not isinstance(p_f_A, types.FunctionType): <EOL><INDENT>p_f_A = np.atleast_1d(p_f_A)<EOL>(p_A, old_A_shape) = cls._check_A_matrix(p_f_A)<EOL>p_f_A = lambda k, m, P: p_A[:,:, <NUM_LIT:0>] <EOL><DEDENT>else:<EOL><INDENT>if p_f_A(<NUM_LIT:1>, m_init, P_init).shape[<NUM_LIT:0>] != m_init.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>old_Q_shape = None<EOL>if not isinstance(p_f_Q, types.FunctionType): <EOL><INDENT>p_f_Q = np.atleast_1d(p_f_Q)<EOL>(p_Q, old_Q_shape) = cls._check_Q_matrix(p_f_Q)<EOL>p_f_Q = lambda k: p_Q[:,:, <NUM_LIT:0>] <EOL><DEDENT>else:<EOL><INDENT>if p_f_Q(<NUM_LIT:1>).shape[<NUM_LIT:0>] != m_init.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if p_h is None:<EOL><INDENT>lambda k,m,H: np.dot(H, m)<EOL><DEDENT>old_H_shape = None<EOL>if not isinstance(p_f_H, types.FunctionType): <EOL><INDENT>p_f_H = np.atleast_1d(p_f_H)<EOL>(p_H, old_H_shape) = cls._check_H_matrix(p_f_H)<EOL>p_f_H = lambda k, m, P: p_H <EOL><DEDENT>else:<EOL><INDENT>if p_f_H(<NUM_LIT:1>, m_init, P_init).shape[<NUM_LIT:0>] != Y.shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>old_R_shape = None<EOL>if not isinstance(p_f_R, types.FunctionType): <EOL><INDENT>p_f_R = np.atleast_1d(p_f_R)<EOL>(p_R, old_R_shape) = cls._check_H_matrix(p_f_R)<EOL>p_f_R = lambda k: p_R <EOL><DEDENT>else:<EOL><INDENT>if p_f_R(<NUM_LIT:1>).shape[<NUM_LIT:0>] != m_init.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL>
Extended Kalman Filter

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

p_state_dim: integer

p_a: if None - the function from the linear model is assumed. No non-
     linearity in the dynamic is assumed.

     function (k, x_{k-1}, A_{k}). Dynamic function.
     k: (iteration number),
     x_{k-1}: (previous state)
     x_{k}: Jacobian matrices of f_a. In the linear case it is exactly A_{k}.

p_f_A: matrix - in this case function which returns this matrix is assumed.
       Look at this parameter description in kalman_filter function.

       function (k, m, P) return Jacobian of dynamic function, it is
       passed into p_a.

       k: (iteration number),
       m: point where Jacobian is evaluated
       P: parameter for Jacobian, usually covariance matrix.

p_f_Q: matrix. In this case function which returns this matrix is asumed.
       Look at this parameter description in kalman_filter function.

       function (k). Returns noise matrix of dynamic model on iteration k.
       k: (iteration number).

p_h: if None - the function from the linear measurement model is assumed.
     No nonlinearity in the measurement is assumed.

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

p_f_H: matrix - in this case function which returns this matrix is assumed.
       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: matrix. In this case function which returns this matrix is asumed.
       function (k). Returns noise matrix of measurement equation
       on iteration k.
       k: (iteration number).

Y: matrix or vector
    Data. If Y is matrix then samples are along 0-th dimension and
    features along the 1-st. May have missing values.

p_mean: vector
    Initial distribution mean. If None it is assumed to be zero

P_init: square symmetric matrix or scalar
    Initial covariance of the states. If the parameter is scalar
    then it is assumed that initial covariance matrix is unit matrix
    multiplied by this scalar. If None the unit matrix is used instead.

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