Exemple #1
0
def _fit_k_lin(nlds, k, kf_i=[]):
    data = nlds.data
    fn = nlds.fn
    # linear fit (KF)
    if (kf_i == []):
        kf = KF(data, k)  # without init params
    else:
        kf = kf_i  # with init params
    kf.em(ITER, ITERe)  # em algorithm
    nlds.setKFParams(kf)
    # fit si
    nlds = nlds.fit_si()
    if (DBG): nlds.plot("%s_%d" % (fn, k))
    (Sta, Obs) = nlds.gen(len(data))
    err = tl.RMSE(Obs, data)
    if (DBG): print("nlds:fit_k_lin (k:%d):rmse: %f" % (k, err))
    return (nlds, err)
Exemple #2
0
    observations = 20 * (np.sin(x) + 0.005 * np.random.random(n))
    data[:,0]=observations
    return (data) 
 
#----------------------------------#
#     main 
#----------------------------------#
if __name__ == "__main__":
    from kf import KF
    tl.comment("kf.py -- example ")
    tl.msg("create synthetic sequence (1-dim)")
    (data)=_example1()
    fn='../output/tmp/kf_sample'
    
   
    k=2 #4 
    tl.msg("k=%d: # of latent variables"%(k)) 
    tl.msg("init params")
    mykf=KF(data,k)
    tl.msg("em algorithm -- START")
    tic = tl.time.clock()
    mykf.em(ITER=2, iter_each=10)
    toc = tl.time.clock(); fittime= toc-tic;
    tl.msg("em algorithm -- END (%f sec.)"%(fittime))
    tl.msg("plot/save models")
    mykf.plot(fn)
    mykf.printParams(fn)