コード例 #1
0
ファイル: EM.py プロジェクト: riviera2015/mvn
from mvn import Mvn
from mvn.matrix import Matrix
from mvn.mixture import Mixture

import pylab
pylab.ion()

source = Mixture([
    Mvn.rand(2),
    Mvn.rand(2),
])

data = source.sample(200)

W1, R1 = [1e7], Mvn(mean=[10.0, 10.0], var=numpy.array([10.0, 10.0])**2)
W2, R2 = [1e7], Mvn(mean=[-10.0, -10.0], var=numpy.array([10.0, 10.0])**2)

old_p = numpy.inf

for N in range(10):
    pylab.gcf().clear()

    pi1 = sum(W1)
    pi2 = sum(W2)

    (pi1, pi2) = [pi1 / (pi1 + pi2), pi2 / (pi1 + pi2)]

    d1 = R1.density(data) * pi1
    d2 = R2.density(data) * pi2
コード例 #2
0
    #directory for resulting figures
    path = 'kalman'
    #seed the rng so results are reproducible.
    seed(path)
    #create publisher
    P = Publisher(path)
    #create figure
    fig = pylab.figure(figsize=(6, 6))

    ## kalman filter parameters

    #the actual, hidden state
    actual = numpy.array([[0, 5]])

    #the sensor
    sensor = Mvn(vectors=[[1, 0], [0, 1]], var=[1, numpy.inf])

    #the system noise
    noise = Mvn(vectors=[[1, 0], [0, 1]], var=numpy.array([0.5, 1])**2)

    #the shear transform to move the system forward
    transform = Matrix([[1, 0], [0.5, 1]])

    filtered = sensor.measure(actual)

    ## initial plot

    ax = newAx(fig)

    #plot the initial actual position
    ax.plot(actual[:, 0], actual[:, 1], **actualParams)