Example #1
0
def test():
    import numpy as np
    from main import init_dbw_example, potential, Hamiltonian, pStationary, HJacobi_integrator
    from main import pTransition
    from scipy.integrate import odeint
    from scipy.interpolate import UnivariateSpline

    x0 = 0.3
    T = 0.5
    par = 0.8

    D2 = .5

    def f(x):
        return -(-x**4 + 2 * par * x**2)

    def fgrad(x):
        return -(4 * x * (par - x**2))

    U = potential(f, fgrad)
    H = Hamiltonian(U, lambda x: D2)
    Pst = None
    J = HJacobi_integrator(H, Pst)

    def J0f(x):
        return 10 * (x - x0)**2

    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax = fig.add_subplot(111)

    def dJdt(J, t=0, xx=[1., 0.]):
        dx = xx[1] - xx[0]
        dJdx = np.gradient(J, dx)
        return -H(xx, dJdx)
Example #2
0
def objFunc(par):
    # Set up the necessary functions
    def f(x):
        return -(-x**4 + 2 * par * x**2)

    def fgrad(x):
        return -(4 * x * (par - x**2))

    U = potential(f, fgrad)
    H = Hamiltonian(U, lambda x: D2)

    eps = 0.0

    def func(x, p):
        return eps * (p - H.seperatrix(x))**2

    H.set_add_term(func)

    Pst = None

    rootPar = np.sqrt(par)
    #xRep = [-0.63,0.63]
    xRep = [z[20], z[-20]]
    try:
        val = 0.
        J = HJacobi_integrator(H, Pst)
        pT1 = pTransition(J)
        pT1.make(xRep[0], tt)
        pT2 = pTransition(J)
        pT2.make(xRep[1], tt)

        xx = J.xx
        """
		fig  = plt.figure()
		ax = fig.add_subplot(111)
		ax.plot(xx,pT1(xx))
		ax.plot(xx,pT2(xx))
		"""
        val = 0.
        for i in range(X.size - 1):
            x = X[i]
            xT = X[i + 1]
            if x < xRep[0]:
                val += np.log(pT1(xT))
            elif x > xRep[1]:
                val += np.log(pT2(xT))
            else:
                w = abs(x - xRep[0]) / (xRep[1] - xRep[0])
                val += np.log(w * pT1(xT) + (1 - w) * pT2(xT))
        return -val
    except:
        return np.inf
def objFuncMF(par):
    # Set up the necessary functions
    def f(x):
        return -(-x**4 + 2 * par * x**2)

    def fgrad(x):
        return -(4 * x * (par - x**2))

    U = potential(f, fgrad)
    H = Hamiltonian(U, lambda x: D2)
    Pst = pStationary(H)

    return -np.sum(np.log(Pst(X)))
    def __call__(self, par, delT):
        self.tt = np.linspace(0., delT, 100)
        D2 = np.exp(par[1])

        def f(x):
            return -(-x**4 + 2 * par[0] * x**2)

        def fgrad(x):
            return -(4 * x * (par[0] - x**2))

        U = potential(f, fgrad)
        H = Hamiltonian(U, lambda x: D2)
        Pst = None
        if self.has_repr:
            return self.evalLL_wrep(H, Pst)
        else:
            return self.evalLL(H, Pst)
Example #5
0
def makeH():
    import numpy as np
    from main import init_dbw_example, potential, Hamiltonian, pStationary, HJacobi_integrator
    from main import pTransition
    from scipy.integrate import odeint
    from scipy.interpolate import UnivariateSpline

    x0 = 0.3
    T = 0.5
    par = 0.8

    D2 = .5

    def f(x):
        return -(-x**4 + 2 * par * x**2)

    def fgrad(x):
        return -(4 * x * (par - x**2))

    U = potential(f, fgrad)
    H = Hamiltonian(U, lambda x: D2)
    return H
def objFunc(par):
    # Set up the necessary functions
    def f(x):
        return -(-x**4 + 2 * par * x**2)

    def fgrad(x):
        return -(4 * x * (par - x**2))

    U = potential(f, fgrad)
    H = Hamiltonian(U, lambda x: D2)
    Pst = None

    try:
        val = 0.
        for i in range(X.size - 1):
            J = HJacobi_integrator(H, Pst)
            pT = pTransition(J)
            pT.make(X[i], tt)
            val += -np.log(pT(X[i + 1]))
        return val
    except:
        return np.inf
        X = np.zeros(nSim)
        for i in range(nSim):
            s = self.sim(x0, T, n)
            X[i] = s[-1]
        if withMix:
            from sklearn import mixture
            clf = mixture.GaussianMixture(n_components=2,
                                          covariance_type='full')
            clf.fit(X.reshape(nSim, 1))
            return np.mean(X), np.var(X), clf
        else:
            return np.mean(X), np.var(X)


f, fg = init_dbw_example()
U = potential(f, fg)

x0 = 0.4
T = 0.5
tt = np.linspace(0., T, 100)


def J0f(x):
    return 100 * (x - x0)**2


H = Hamiltonian(U, lambda x: 0.5)
Pst = pStationary(H)
dX = Diffusion(H)

NSim = 100
Example #8
0
x0 = 0.3
T = 0.5
par = 0.8

D2 = .5


def f(x):
    return -(-x**4 + 2 * par * x**2)


def fgrad(x):
    return -(4 * x * (par - x**2))


U = potential(f, fgrad)
H = Hamiltonian(U, lambda x: D2)
Pst = None
J = HJacobi_integrator(H, Pst)


def J0f(x):
    return 10 * (x - x0)**2


import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)


def dJdt(J, t=0, xx=None, dx=1.):