Ejemplo n.º 1
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
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
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)))
Ejemplo n.º 4
0
    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)
Ejemplo n.º 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
Ejemplo n.º 6
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)
    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
            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
n = 500
rSample = np.zeros(NSim)

# R
# - Costly, used for plotting purposes
R = np.zeros((NSim, n))

# 35878
seed = np.random.choice(range(100000))
print seed
Ejemplo n.º 8
0
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.):
    dJdx = np.gradient(J, dx)
Ejemplo n.º 9
0
D2 = .5

par = .8


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)


def exp_cdf(t, l=1.3):
    return 1 - np.exp(-l * t)


x0 = 1.3
t = 0.
T = .8

from scipy.integrate import quad

JT1, xx = get_Jt(0.8, T, H, exp_cdf)
JT2, _ = get_Jt(-0.03, T, H, exp_cdf)
JT3, _ = get_Jt(-0.8, T, H, exp_cdf)
Ejemplo n.º 10
0
import numpy as np 
import matplotlib.pyplot as plt 
from main import init_dbw_example,potential,Hamiltonian,pStationary,HJacobi_integrator
from scipy.interpolate import UnivariateSpline
"""
Investigating properties of the homotopy method
"""

f,fg = init_dbw_example()
U = potential(f,fg)
H = Hamiltonian(U,lambda x: 0.5)
Pst = pStationary(H)
J = HJacobi_integrator(H,Pst)


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

Jt = J(tt,lambda x : 10*(x-x0)**2)
xx = J.xx
dx = J.dx

"""
Plot the gradient over the contours of the Hamiltonian
"""
fig = plt.figure()
ax = fig.add_subplot(111)

# Smooth the oscillations 
Ejemplo n.º 11
0
            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)

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

NSim = 100
T = 0.5
rSample = np.zeros(NSim)

x0 = 0.1

tt = [0.]
rSample[0] = x0

t = 0.

seed = np.random.choice(range(100))
Ejemplo n.º 12
0
from main import pTransition, pTransition2
from JIntegrator import integrator_pars
from scipy.interpolate import UnivariateSpline
from scipy.integrate import odeint
import matplotlib.pyplot as plt

D2 = .5

par = .8

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)

def exp_cdf(t,l = 1.3):
	return 1-np.exp(-l*t)

x0 = 0.8
t = 0.
T = .1

fig = plt.figure()
ax = fig.add_subplot(111)

for i in range(10) :
	tt = np.linspace(t,t+T,1000)
	J = HJacobi_integrator(H,None)