@staticmethod<EOL><INDENT>def lti_sde_to_descrete(F,L,Qc,dt,compute_derivatives=False,<EOL>grad_params_no=None, P_inf=None,<EOL>dP_inf=None, dF = None, dQc=None):<DEDENT>
<EOL>n = F.shape[<NUM_LIT:0>]<EOL>if not isinstance(dt, collections.Iterable): <EOL><INDENT>A  = matrix_exponent(F*dt)<EOL>Phi = np.zeros((<NUM_LIT:2>*n,<NUM_LIT:2>*n))<EOL>Phi[:n,:n] = F<EOL>Phi[:n,n:] = L.dot(Qc).dot(L.T)<EOL>Phi[n:,n:] = -F.T<EOL>AB = matrix_exponent(Phi*dt)<EOL>AB = np.dot(AB, np.vstack((np.zeros((n,n)),np.eye(n))))<EOL>Q_noise_1 = linalg.solve(AB[n:,:].T,AB[:n,:].T)<EOL>Q_noise_2  = P_inf - A.dot(P_inf).dot(A.T)<EOL>if compute_derivatives:<EOL><INDENT>dA = np.zeros([n, n, grad_params_no])<EOL>dQ = np.zeros([n, n, grad_params_no])<EOL>FF  = np.zeros([<NUM_LIT:2>*n, <NUM_LIT:2>*n])<EOL>AA = np.zeros([<NUM_LIT:2>*n, <NUM_LIT:2>*n, grad_params_no])<EOL>for p in range(<NUM_LIT:0>, grad_params_no):<EOL><INDENT>FF[:n,:n] = F<EOL>FF[n:,:n] = dF[:,:,p]<EOL>FF[n:,n:] = F<EOL>AA[:,:,p] = matrix_exponent(FF*dt)<EOL>if p==<NUM_LIT:0>:<EOL><INDENT>A  = AA[:n,:n,p]<EOL>Q_noise_3  = P_inf - A.dot(P_inf).dot(A.T)<EOL>Q_noise = Q_noise_3<EOL><DEDENT>dA[:,:,p] = AA[n:,:n,p]<EOL>tmp = dA[:,:,p].dot(P_inf).dot(A.T)<EOL>dQ[:,:,p] = dP_inf[:,:,p] - tmp- A.dot(dP_inf[:,:,p]).dot(A.T) - tmp.T<EOL>dQ[:,:,p] = <NUM_LIT:0.5>*(dQ[:,:,p] + dQ[:,:,p].T) <EOL><DEDENT><DEDENT>else:<EOL><INDENT>dA = None<EOL>dQ = None<EOL>Q_noise = Q_noise_2<EOL><DEDENT>Q_noise = <NUM_LIT:0.5>*(Q_noise + Q_noise.T) <EOL>return A, Q_noise,None, dA, dQ<EOL><DEDENT>else: <EOL><INDENT>dt_unique, tmp, reconstruct_index = np.unique(np.round(dt,<NUM_LIT:8>),<EOL>return_index=True,return_inverse=True)<EOL>del tmp<EOL>A = np.empty((n,n,dt_unique.shape[<NUM_LIT:0>]))<EOL>Q_noise = np.empty((n,n,dt_unique.shape[<NUM_LIT:0>]))<EOL>if compute_derivatives:<EOL><INDENT>dA = np.empty((n,n,grad_params_no,dt_unique.shape[<NUM_LIT:0>]))<EOL>dQ = np.empty((n,n,grad_params_no,dt_unique.shape[<NUM_LIT:0>]))<EOL><DEDENT>else:<EOL><INDENT>dA = None<EOL>dQ = None<EOL><DEDENT>for j in range(<NUM_LIT:0>,dt_unique.shape[<NUM_LIT:0>]):<EOL><INDENT>A[:,:,j], Q_noise[:,:,j], tmp1, dA_t, dQ_t = ContDescrStateSpace.lti_sde_to_descrete(F,L,Qc,dt_unique[j],<EOL>compute_derivatives=compute_derivatives, grad_params_no=grad_params_no, P_inf=P_inf, dP_inf=dP_inf, dF = dF, dQc=dQc)<EOL>if compute_derivatives:<EOL><INDENT>dA[:,:,:,j] = dA_t<EOL>dQ[:,:,:,j] = dQ_t<EOL><DEDENT><DEDENT>return A, Q_noise, reconstruct_index, dA, dQ<EOL><DEDENT>
Linear Time-Invariant Stochastic Differential Equation (LTI SDE):

    dx(t) = F x(t) dt + L d \beta  ,where

        x(t): (vector) stochastic process
        \beta: (vector) Brownian motion process
        F, L: (time invariant) matrices of corresponding dimensions
        Qc: covariance of noise.

This function rewrites it into the corresponding state-space form:

    x_{k} =  A_{k} * x_{k-1} + q_{k-1};       q_{k-1} ~ N(0, Q_{k-1})

TODO: this function can be redone to "preprocess dataset", when
close time points are handeled properly (with rounding parameter) and
values are averaged accordingly.

Input:
--------------
F,L: LTI SDE matrices of corresponding dimensions

Qc: matrix (n,n)
    Covarince between different dimensions of noise \beta.
    n is the dimensionality of the noise.

dt: double or iterable
    Time difference used on this iteration.
    If dt is iterable, then A and Q_noise are computed for every
    unique dt

compute_derivatives: boolean
    Whether derivatives of A and Q are required.

grad_params_no: int
    Number of gradient parameters

P_inf: (state_dim. state_dim) matrix

dP_inf

dF: 3D array
    Derivatives of F

dQc: 3D array
    Derivatives of Qc

dR: 3D array
    Derivatives of R

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

A: matrix
    A_{k}. Because we have LTI SDE only dt can affect on matrix
    difference for different k.

Q_noise: matrix
    Covariance matrix of (vector) q_{k-1}. Only dt can affect the
    matrix difference for different k.

reconstruct_index: array
    If dt was iterable return three dimensinal arrays A and Q_noise.
    Third dimension of these arrays correspond to unique dt's.
    This reconstruct_index contain indices of the original dt's
    in the uninue dt sequence. A[:,:, reconstruct_index[5]]
    is matrix A of 6-th(indices start from zero) dt in the original
    sequence.
dA: 3D array
    Derivatives of A

dQ: 3D array
    Derivatives of Q