def seriescoeff(m=<NUM_LIT:6>,lengthScale=<NUM_LIT:1.0>,magnSigma2=<NUM_LIT:1.0>, true_covariance=False):
if true_covariance:<EOL><INDENT>bb = lambda j,m: (<NUM_LIT:1.0> + np.array((j != <NUM_LIT:0>), dtype=np.float64) ) / (<NUM_LIT:2>**(j)) *sp.special.binom(j, sp.floor( (j-m)/<NUM_LIT> * np.array(m<=j, dtype=np.float64) ))*np.array(m<=j, dtype=np.float64) *np.array(sp.mod(j-m,<NUM_LIT:2>)==<NUM_LIT:0>, dtype=np.float64)<EOL>M,J = np.meshgrid(range(<NUM_LIT:0>,m+<NUM_LIT:1>),range(<NUM_LIT:0>,m+<NUM_LIT:1>))<EOL>coeffs = bb(J,M) / sp.misc.factorial(J) * sp.exp( -lengthScale**(-<NUM_LIT:2>) ) *(lengthScale**(-<NUM_LIT:2>))**J  *magnSigma2<EOL>coeffs_dl = np.sum( coeffs*lengthScale**(-<NUM_LIT:3>)*(<NUM_LIT>-<NUM_LIT>*J*lengthScale**<NUM_LIT:2>),<NUM_LIT:0>)         <EOL>coeffs = np.sum(coeffs,<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>coeffs = <NUM_LIT:2>*magnSigma2*sp.exp( -lengthScale**(-<NUM_LIT:2>) ) * special.iv(range(<NUM_LIT:0>,m+<NUM_LIT:1>),<NUM_LIT:1.0>/lengthScale**(<NUM_LIT:2>))<EOL>if np.any( np.isfinite(coeffs) == False):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>coeffs[<NUM_LIT:0>] = <NUM_LIT:0.5>*coeffs[<NUM_LIT:0>]<EOL>coeffs_dl = np.zeros(m+<NUM_LIT:1>)<EOL>coeffs_dl[<NUM_LIT:1>:] = magnSigma2*lengthScale**(-<NUM_LIT:3>) * sp.exp(-lengthScale**(-<NUM_LIT:2>))*(-<NUM_LIT:4>*special.iv(range(<NUM_LIT:0>,m),lengthScale**(-<NUM_LIT:2>)) + <NUM_LIT:4>*(<NUM_LIT:1>+np.arange(<NUM_LIT:1>,m+<NUM_LIT:1>)*lengthScale**(<NUM_LIT:2>))*special.iv(range(<NUM_LIT:1>,m+<NUM_LIT:1>),lengthScale**(-<NUM_LIT:2>)) )    <EOL>coeffs_dl[<NUM_LIT:0>] = magnSigma2*lengthScale**(-<NUM_LIT:3>) * np.exp(-lengthScale**(-<NUM_LIT:2>))*(<NUM_LIT:2>*special.iv(<NUM_LIT:0>,lengthScale**(-<NUM_LIT:2>)) - <NUM_LIT:2>*special.iv(<NUM_LIT:1>,lengthScale**(-<NUM_LIT:2>)) )     <EOL><DEDENT>return coeffs.squeeze(), coeffs_dl.squeeze()<EOL>
Calculate the coefficients q_j^2 for the covariance function 
approximation:

    k(\tau) =  \sum_{j=0}^{+\infty} q_j^2 \cos(j\omega_0 \tau)

Reference is:

[1] Arno Solin and Simo Särkkä (2014). Explicit link between periodic 
    covariance functions and state space models. In Proceedings of the 
    Seventeenth International Conference on Artifcial Intelligence and 
    Statistics (AISTATS 2014). JMLR: W&CP, volume 33.    

Note! Only the infinite approximation (through Bessel function) 
      is currently implemented.

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

m: int
    Degree of approximation. Default 6.
lengthScale: float
    Length scale parameter in the kerenl
magnSigma2:float
    Multiplier in front of the kernel.


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

coeffs: array(m+1)
    Covariance series coefficients

coeffs_dl: array(m+1)
    Derivatives of the coefficients with respect to lengthscale.