import numpy as np


def initialize(trials, params, config):
    """Make skeleton"""
    from sklearn.decomposition import FactorAnalysis

    zdim = params['zdim']
    xdim = params['xdim']

    y = np.concatenate([trial['y'] for trial in trials], axis=0)
    ydim = y.shape[-1]
    fa = FactorAnalysis(n_components=zdim, random_state=0)
    z = fa.fit_transform(y)
    a = fa.components_
    b = np.log(np.mean(y, axis=0, keepdims=True))
    noise = np.var(y - z @ a, ddof=0, axis=0)

    params.update(a=a, b=b, noise=noise)

    for trial in trials:
        length = trial['y'].shape[0]
        trial.update({
            'mu': fa.transform(trial['y']),
            'x': np.ones((length, xdim, ydim)),
            'w': np.zeros((length, zdim)),
            'v': np.zeros((length, zdim))
        })

    params = {
        'ydim': ydim,
        'zdim': zdim,
        'xdim': xdim,
        'length': length,
        'a': a,
        'b': b,
        'noise': noise,
        'sigma': np.full(zdim, fill_value=1.0),
        'omega': np.full(zdim, fill_value=1e-4),
        'rank': length // 5,
        'gp_noise': 1e-4,
        'dt': 1,
        'tau': 500,
        'likelihood': np.array(['poisson'] * ydim)
    }

    trials = [{
        'y': trial['y'],
        'mu': fa.transform(trial['y']),
        'x': np.ones((length, 1, ydim)),
        'w': np.zeros((length, zdim)),
        'v': np.zeros((length, zdim)),
    } for trial in data]

    return trials, params

@@ -796,16 +796,193 @@
     %7D)%0A%0A
+%0Adef get_params(trials, zdim, xdim, lik):%0A    y = trials%5B0%5D%5B'y'%5D%0A    ydim = y.shape%5B-1%5D%0A%0A    if not isinstance(lik, list):%0A        lik = %5Blik%5D * ydim%0A    lik = np.asarray(lik)%0A%0A
     para
@@ -1067,55 +1067,71 @@
    '
-length': length,%0A        'a': a,%0A        'b': b
+a': np.zeros((zdim, ydim)),%0A        'b': np.zeros((xdim, ydim))
 ,%0A  
@@ -1146,20 +1146,28 @@
 oise': n
-oise
+p.ones(ydim)
 ,%0A      
@@ -1277,20 +1277,57 @@
 k': 
-length // 5,
+50,  # TODO: consider merge with window in config
 %0A   
@@ -1412,268 +1412,37 @@
 d': 
-np.array(%5B'poisson'%5D * ydim)%0A    %7D%0A%0A    trials = %5B%7B%0A        'y': trial%5B'y'%5D,%0A        'mu': fa.transform(trial%5B'y'%5D),%0A        'x': np.ones((length, 1, ydim)),%0A        'w': np.zeros((length, zdim)),%0A        'v': np.zeros((length, zdim)),%0A    %7D for trial in data%5D
+lik%0A    %7D%0A%0A    return params%0A
 %0A%0A  

add function to prepare params