Exemplo n.º 1
0
def test_simulation(n=1e2, tau=0.995):

    T = pth.GaussianKernel(tau)
    X = [np.random.random(int(n)) * 100]

    for i in xrange(1000):
        X.append(T(X[-1]))

    X = np.array(X)

    ## plot convergence to stationary distribution

    fig, ax = plt.subplots(1, 2, figsize=(8, 4))
    fig.suptitle(r'$\tau={0:.3e}$'.format(tau), y=1.)

    [ax[0].plot(x, lw=2, color='k', alpha=0.1) for x in X.T]

    ax[0].plot(X.mean(1), lw=3, color='r')
    ax[0].axhline(T.stationary.mu, ls='--', lw=3, label=r'$\mu$', color='k')
    ax[0].set_xlabel('iteration')
    ax[0].set_ylabel('mean')
    ax[0].legend()

    ax[1].plot(X.std(1), color='r')
    ax[1].axhline(T.stationary.sigma,
                  ls='--',
                  lw=3,
                  label=r'$\sigma$',
                  color='k')
    ax[1].set_xlabel('iteration')
    ax[1].set_ylabel('standard deviation')
    ax[1].legend()

    fig.tight_layout()
Exemplo n.º 2
0
def test_composition():

    T = pth.GaussianKernel(0.9,
                           np.random.standard_normal() * 10,
                           np.random.gamma(1))

    print T
    print T.compose(T.compose(T.compose(T)))
    print T.power(4)
    print T.stationary
Exemplo n.º 3
0
import numpy as np
import paths as pth
import matplotlib.pylab as plt

start = pth.GaussianKernel(0.9, 20., 10.)
end = pth.GaussianKernel(0.995, 0., 1.)

log_Z = end.stationary.log_Z - start.stationary.log_Z

scheduler = pth.Scheduler(start, end, pth.Bridge)
schedule = scheduler.find_schedule(10)

scheduler = pth.Scheduler(start, end, pth.GeometricBridge)
schedule2 = scheduler.find_schedule(10)

bridge = pth.make_bridge(start, end, schedule, constructor=pth.Bridge)
bridge2 = pth.make_bridge(start,
                          end,
                          schedule2,
                          constructor=pth.GeometricBridge)

prob = [T.stationary for T in bridge]
prob2 = [T.stationary for T in bridge2]

kl = [q.kl(p) for p, q in zip(prob[1:], prob)]
kl2 = [q.kl(p) for p, q in zip(prob2[1:], prob2)]

print 'first bridge', np.mean(kl), np.std(kl)
print 'second bridge', np.mean(kl2), np.std(kl)

colors = ('b', 'g')