Example #1
0
def test_strat_1D_additive():
    tspan = np.arange(0.0, 2000.0, 0.002)
    y0 = 0.0
    f = lambda y, t: -1.0 * y
    G = lambda y, t: 0.2
    y = sdeint.stratint(f, G, y0, tspan)
    assert (np.isclose(np.mean(y), 0.0, rtol=0, atol=1e-02))
    assert (np.isclose(np.var(y), 0.2 * 0.2 / 2, rtol=1e-01, atol=0))
Example #2
0
def test_strat_1D_additive():
    tspan = np.arange(0.0, 2000.0, 0.002)
    y0 = 0.0
    f = lambda y, t: -1.0 * y
    G = lambda y, t: 0.2
    y = sdeint.stratint(f, G, y0, tspan)
    assert(np.isclose(np.mean(y), 0.0, rtol=0, atol=1e-02))
    assert(np.isclose(np.var(y), 0.2*0.2/2, rtol=1e-01, atol=0))
Example #3
0
def test_strat_ND_additive():
    tspan = np.arange(0.0, 2000.0, 0.002)
    y0 = np.zeros(3)
    def f(y, t):
        return np.array([ -1.0*y[0],
                          y[2],
                          -1.0*y[1] - 0.4*y[2] ])
    def G(y, t):
        return np.diag([0.2, 0.0, 0.5])
    y = sdeint.stratint(f, G, y0, tspan)
    w = np.fft.rfft(y[:, 2])
Example #4
0
def test_strat_ND_additive():
    tspan = np.arange(0.0, 2000.0, 0.002)
    y0 = np.zeros(3)

    def f(y, t):
        return np.array([-1.0 * y[0], y[2], -1.0 * y[1] - 0.4 * y[2]])

    def G(y, t):
        return np.diag([0.2, 0.0, 0.5])

    y = sdeint.stratint(f, G, y0, tspan)
    w = np.fft.rfft(y[:, 2])
Example #5
0
    def solve(self, **kwargs):
        """ Solves initial value problem """

        if (len(self.sol) == 0):
            # Solve only if not already solved
            if(self.method == 'EuMa'):
                self.sol_cartesian = sdeint.itoEuler(self.f, self.G, self.y0, self.ts, **kwargs)

            elif (self.method == 'Ito'):
                self.sol_cartesian = sdeint.itoint(self.f, self.G, self.y0, self.ts, **kwargs)

            elif (self.method == 'Strato'):
                self.sol_cartesian = sdeint.stratint(self.f, self.G, self.y0, self.ts, **kwargs)

            else:
                raise ValueError('Only supported methods are EuMa, Ito and Strato')
        else:
            # Do nothing
            pass

        if self.topology == 'cartesian':
            self.sol = self.sol_cartesian
        elif self.topology == 'torus':
            self.sol = np.mod(self.sol_cartesian, 2*np.pi)
Example #6
0
# ax.plot(times, result.expect[1],label="MagnetizationZ",linestyle='--',marker='o',markersize='2');
# ax.plot(times, result.expect[2],label="Exp(SigmaZ,0)");
# ax.plot(times, result.expect[3],label="Exp(SigmaX,0)",linestyle='--');
# ax.plot(times, np.abs(ups),label="Tr(rho_0,uu)",linestyle='--');
# ax.plot(times, np.abs(downs),label="Tr(rho_0,dd)",linestyle='-');
#ax[1].set_xlabel('Days')
#ax[1].set_ylabel('')
ax[1].legend(loc="right")
#plt.show()

A = np.array([[-0.1, 0.5], [-0.5, 0.1]])

B = np.diag([0.5, 0.5])  # diagonal, so independent driving Wiener processes
B = np.array([[-0.0, -5], [0.0, 0]])
tspan = np.linspace(0.0, 10.0, 10001)
x0 = np.array([1.0, 0.1])


def f(x, t):
    return A.dot(x)


def G(x, t):
    return B


result = sdeint.stratint(f, G, x0, tspan)
print(result)
ax[2].plot(tspan, result)
plt.show()