def run():
    # w, s = sp_odeint(f, w0, t, full_output=True)
    w = sp_odeint(f, w0, t)
    return w
Exemple #2
0
z0_bar = delta_zi.copy()
z0_bar[:, 0] += x0
z0_bar[:, 1] += v0

normed_delta_zi = np.square(delta_zi)
normed_delta_zi = np.sum(normed_delta_zi, 1)
normed_delta_zi = np.sqrt(normed_delta_zi)

z_lambda_list = list()

for time_interval in T[1:]:
    zf_list = list()
    t = np.linspace(0, time_interval, 2001)
    for z0 in z0_bar:
        zf_list.append(sp_odeint(v_, z0, t)[-1])

    zf = np.array(zf_list)
    normed_zf = zf.copy()
    normed_zf[:, 0] = normed_zf[:, 0] - normed_zf[0, 0]
    normed_zf[:, 1] = normed_zf[:, 1] - normed_zf[0, 1]
    normed_zf = np.square(normed_zf)
    normed_zf = np.sum(normed_zf, 1)
    normed_zf = np.sqrt(normed_zf)

    z_lambda_list.append(np.sum(np.log(normed_zf[1:] / normed_delta_zi[1:])) / ((N - 1) * time_interval))

z_lambda = np.array(z_lambda_list)
plt.plot(z_lambda)
plt.show()
def run(years):
    # w, s = sp_odeint(f, w0, t, full_output=True)
    w = sp_odeint(f, get_w0(), get_t(years))
    return w
def run():
    # w, s = sp_odeint(f, w0, t, full_output=True)
    w = sp_odeint(f, w0, t)
    return w
# wx0 = 50 * (np.random.rand(particle_index) - .5)
# wv0 = 50 * (np.random.rand(particle_index) - .5)
# w0 = np.concatenate([wx0, wv0])
w0 = np.array([], dtype=np.float64)
for x0i, y0i, z0i in zip(x0, y0, z0):
    w0 = np.concatenate([w0, [x0i], [y0i], [z0i]])
for vx0i, vy0i, vz0i in zip(vx0, vy0, vz0):
    w0 = np.concatenate([w0, [vx0i], [vy0i], [vz0i]])

# w0 = np.array([x0[0], y0[0], z0[0], x0[3], y0[3], z0[3], vx0[0], vy0[0], vz0[0], vx0[3], vy0[3], vz0[3]], dtype=np.float64)

# w0 = np.concatenate([[-10, 0, 0, 10, 0, 0, 0, 10, 0, 0, -10, 0], [0, -1, 0, 0, 1, 0, 1, 0, 0, -1, 0, 0]])
# w0 = np.concatenate([[-10, 0, 0, 10, 0, 0], [0, -1, 0, 0, 1, 0]])
t = np.arange(0, time_interval, dt, dtype=np.float64)
w_result = sp_odeint(f, w0, t, mxstep=50000000, hmin=.0001)

trajectories = []
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection='3d')
# ax.axis('off')

colors = plt.cm.jet(np.linspace(0, 1, number_particles))
lines = sum([ax.plot([], [], [], '.', c=c) for c in colors], [])

lim = 2.0 * earth_distance
ax.set_xlim3d([-lim, lim])
ax.set_ylim3d([-lim, lim])
ax.set_zlim3d([-lim, lim])
time_template = 'time = %.1fdays'
time_text = ax.text(0.05, 0.9, 0.05, '', transform=ax.transAxes)
Exemple #6
0
z0_bar = delta_zi.copy()
z0_bar[:, 0] += x0
z0_bar[:, 1] += v0

normed_delta_zi = np.square(delta_zi)
normed_delta_zi = np.sum(normed_delta_zi, 1)
normed_delta_zi = np.sqrt(normed_delta_zi)

z_lambda_list = list()

for time_interval in T[1:]:
    zf_list = list()
    t = np.linspace(0, time_interval, 2001)
    for z0 in z0_bar:
        zf_list.append(sp_odeint(v_, z0, t)[-1])

    zf = np.array(zf_list)
    normed_zf = zf.copy()
    normed_zf[:, 0] = normed_zf[:, 0] - normed_zf[0, 0]
    normed_zf[:, 1] = normed_zf[:, 1] - normed_zf[0, 1]
    normed_zf = np.square(normed_zf)
    normed_zf = np.sum(normed_zf, 1)
    normed_zf = np.sqrt(normed_zf)

    z_lambda_list.append(
        np.sum(np.log(normed_zf[1:] / normed_delta_zi[1:])) /
        ((N - 1) * time_interval))

z_lambda = np.array(z_lambda_list)
plt.plot(z_lambda)
Exemple #7
0
def generate_double_pend(
        batch=1000,
        ntotal=500,
        nsample=100,
        start_theta_1=np.pi / 4,
        start_theta_2=np.pi / 4,
        stop_t=5,  # approximately equal to 6pi
        noise_std=.1,
        l1=1.,
        l2=1.,
        m1=1,
        m2=1,
        g=9.8,
        savefig=True):
    """
    Args:
      batch: batch dimension
      ntotal: total number of datapoints per set
      nsample: number of sampled datapoints for model fitting
      start_theta_1: first arm starting theta value
      start_theta_2: second arm starting theta value
      stop: ending t value
      noise_std: observation noise standard deviation
      l1, l2, m1, m2, g: parameters of the double pendulum
      savefig: plot the ground truth for sanity check

    Returns:
      Tuple where first element is true trajectory of size (ntotal, 2),
      second element is noisy observations of size (batch, nsample, 2),
      third element is timestamps of size (ntotal,),
      and fourth element is timestamps of size (nsample,)
    """
    y0 = [start_theta_1, start_theta_2, 0.0, 0.0]

    orig_ts = np.linspace(0, stop_t, num=ntotal)
    samp_ts = orig_ts[:nsample]
    sample_plot_range = np.zeros((batch, nsample))

    original = sp_odeint(pen_sim.double_pendulum,
                         y0,
                         orig_ts,
                         args=(g, l1, l2, m1, m2))

    # remove omega values
    original = original[:, 0:2]
    samp_trajs = []

    for i in range(batch):

        # don't sample t0 very near the start or the end
        t0_idx = npr.randint(0, ntotal - nsample)

        sample_plot_range[i, :] = orig_ts[t0_idx:t0_idx + nsample]

        samp_traj = original[t0_idx:t0_idx + nsample, :].copy()
        samp_traj += npr.randn(*samp_traj.shape) * noise_std
        samp_trajs.append(samp_traj)

    samp_trajs = np.stack(samp_trajs, axis=0)

    return original, samp_trajs, orig_ts, samp_ts, sample_plot_range
# wx0 = 50 * (np.random.rand(particle_index) - .5)
# wv0 = 50 * (np.random.rand(particle_index) - .5)
# w0 = np.concatenate([wx0, wv0])
w0 = np.array([], dtype=np.float64)
for x0i, y0i, z0i in zip(x0, y0, z0):
    w0 = np.concatenate([w0, [x0i], [y0i], [z0i]])
for vx0i, vy0i, vz0i in zip(vx0, vy0, vz0):
    w0 = np.concatenate([w0, [vx0i], [vy0i], [vz0i]])

# w0 = np.array([x0[0], y0[0], z0[0], x0[3], y0[3], z0[3], vx0[0], vy0[0], vz0[0], vx0[3], vy0[3], vz0[3]], dtype=np.float64)

# w0 = np.concatenate([[-10, 0, 0, 10, 0, 0, 0, 10, 0, 0, -10, 0], [0, -1, 0, 0, 1, 0, 1, 0, 0, -1, 0, 0]])
# w0 = np.concatenate([[-10, 0, 0, 10, 0, 0], [0, -1, 0, 0, 1, 0]])
t = np.arange(0, time_interval, dt, dtype=np.float64)
w_result = sp_odeint(f, w0, t, mxstep=50000000, hmin=.0001)

trajectories = []
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection='3d')
# ax.axis('off')

colors = plt.cm.jet(np.linspace(0, 1, number_particles))
lines = sum([ax.plot([], [], [], '.', c=c) for c in colors], [])

lim = 2.0 * earth_distance
ax.set_xlim3d([-lim, lim])
ax.set_ylim3d([-lim, lim])
ax.set_zlim3d([-lim, lim])
time_template = 'time = %.1fdays'
time_text = ax.text(0.05, 0.9, 0.05, '', transform=ax.transAxes)
def run(years):
    # w, s = sp_odeint(f, w0, t, full_output=True)
    w = sp_odeint(f, get_w0(), get_t(years))
    return w
import sympy as sp
import numpy as np
import matplotlib.pylab as plt

sp.init_printing()

from scipy.integrate import odeint as sp_odeint


def v_(z, t):
    return np.array([z[1], -np.sin(z[0]) - np.sin(z[0] - 2 * t)])


ti = 0
tf = 200
dt = .1
xi_vi = [-.5, 0]

t2 = np.linspace(ti, tf, 20001)
t1 = np.linspace(ti, tf, 2001)

x1_v1 = sp_odeint(v_, xi_vi, t1)
x2_v2 = sp_odeint(v_, xi_vi, t2)

plt.plot(t2, x2_v2)
plt.plot(t1, x1_v1)
plt.show()