예제 #1
0
    def testFig8Lce(self):  # takes a long time, so its disabled
        sys = NBodySystem(body_masses=[1, 1, 1], G=1)
        solver = SystemSolver(sys)
        tspan = [0, 1.5]
        y0 = np.zeros(2 * sys.body_dim * len(sys.body_masses),
                      dtype=np.float64)

        x1 = np.array([0.97000436, -0.24308753, 0])
        x3p = np.array([-0.93240737, -0.86473146, 0])

        y0[0:3] = x1
        y0[3:6] = -x1
        y0[6:9] = 0
        y0[9:12] = -x3p / 2
        y0[12:15] = -x3p / 2
        y0[15:18] = x3p
        # print(sys.fun(np.zeros_like(y0), y0).reshape(6, -1))
        lce, run = solver.get_lce(tspan[1], y0)
        t = run['results'].t[1:]
        y = run['results'].y[sys.dim:, 1:].reshape(sys.dim, sys.dim, -1)
        #print(y[:, :, -1])
        lces = []
        for i, t_val in enumerate(t):
            Df_y = y[:, :, i]
            lces.append(solver.calc_lce(Df_y, t_val))
        print(lces[-1])
        print(np.mean(lces[-5:]))
        clearFigs()
        plt.figure()
        plt.plot(t, lces)
        plt.show(True)
예제 #2
0
 def testLCE(self):
     # slv.calc_lce(Df_y0, T)
     sys = RestrictedCircular3Body()
     slv = SystemSolver(sys)
     lce, lce_run = slv.get_lce(T=100)
     t = lce_run['results'].t
     y = lce_run['results'].y
     sys_dim = sys.dim
     lces = []
     start_t = 10
     for i in range(start_t, t.shape[0]):
         Df_y0 = y[sys_dim:, i].reshape(sys_dim, sys_dim)
         lce = slv.calc_lce(Df_y0, t[i])
         lces.append(lce)
     plt.plot(t[start_t:], lces)
     plt.show(True)
예제 #3
0
 def runLCETest(self, sigma, rho, beta, l1):
     sys = LorenzSystem(sigma, rho, beta)
     slv = SystemSolver(sys)
     lce, run = slv.get_lce(T=100)
     T0 = 0
     t = run['results'].t[T0:]
     y = run['results'].y[:, T0:]
     lces = []
     for i, t_val in enumerate(t):
         Df_y0 = y[sys.dim:, i].reshape(sys.dim, sys.dim)
         lces.append(slv.calc_lce(Df_y0, t_val))
     clearFigs()
     plt.figure()
     plt.plot(t, lces)
     plt.show(True)
     print(Df_y0)
     print(lce, l1, (lce - l1) / l1)
     self.assertAlmostEqual((lce - l1) / l1, 0, places=0)
run, lce, ts_data, results = res
sys = run['system']
slvr = SystemSolver(sys)
dir_pre = os.path.join('..', 'images', 'doub_pend')

# print small details
print('lce:', lce[0])
# LCE
lce_val, lce_run = lce
T0 = 0
t = lce_run['results'].t[T0:]
y = lce_run['results'].y[:, T0:]
lces = []
for i, t_val in enumerate(t):
    Df_y0 = y[sys.dim:, i].reshape(sys.dim, sys.dim)
    lces.append(slvr.calc_lce(Df_y0, t_val))
plt.figure()
plt.title(f'Double Pendulum LCE ({lce_val:.3}) vs t')
plt.xlabel('t')
plt.ylabel('LCE')
plt.plot(t, lces)
plt.savefig(os.path.join(dir_pre, 'lce_converge.png'))
exit()

print(run['results'].y[:, 0])
test_rmse = [rmse for _, _, _, (_, _, rmse) in results['best model rmse']]
test_rmse = np.array(test_rmse)


def rmse(d, y):
    num_samples = d.shape[0]
예제 #5
0
tspan = [0, 200]
y0 = np.zeros(2 * sys.body_dim * len(sys.body_masses), dtype=np.float64)

x1 = np.array([0.97000436, -0.24308753])
x3p = np.array([-0.93240737, -0.86473146])

y0[0:2] = x1
y0[2:4] = -x1
# y0[4:6] = zero
y0[6:8] = -x3p / 2
y0[8:10] = -x3p / 2
y0[10:12] = x3p

# print(sys.fun(np.zeros_like(y0), y0).reshape(6, -1))
lce, run = solver.get_lce(tspan[1], y0)
t = run['results'].t[1:]
y = run['results'].y[sys.dim:, 1:].reshape(sys.dim, sys.dim, -1)
#print(y[:, :, -1])
lces = []
for i, t_val in enumerate(t):
    Df_y = y[:, :, i]
    lces.append(solver.calc_lce(Df_y, t_val))

plt.figure()
plt.title(f'LCE ({lces[-1]:.2}) Convergence for 3 Body Figure 8')
plt.plot(t, lces)
plt.ylabel('LCE')
plt.xlabel('t')
plt.savefig(os.path.join(dir_pre, 'lce_converge.png'))
# plt.show(True)