import numpy as np
import pylab as plt
from time import sleep

f = lambda mu,s,n: np.hstack([np.random.normal(mu[i],abs(s[i]),n[i]) for i in range(len(n))])

mu = np.random.rand(1000)
s = np.random.rand(1000)
#n = np.random.randint(100,200,100)
n = np.hstack([1]*1000)

yt = np.random.normal(0,1,1000)

i=0
while True:
    np.random.seed(42)
    y = f(mu,s,n)
    err = yt - y
    mu += 0.01 * err
    #s += 0.0001 * err
    print(np.sum(err**2))
    if 1==0:
        plt.subplot(2,1,1)
        plt.plot(y)
        plt.subplot(2,1,2)
        plt.hist(y,100)
        plt.show()
        sleep(1)
    i+=1
