def testExample(self): sys = RestrictedCircular3Body() slv = SystemSolver(sys) lce, lce_run = slv.get_lce() slv.calc_lce # print(lce) init = [1, -1, 1, -1] run = slv.run([0, 5], init) run['results'].y = run['results'].y[:2, :] slv.plot2d(run)
class TestModel(unittest.TestCase): def setUp(self): # test data self.circle_solver = SystemSolver(CircleSystem()) def testSomething(self): res = self.circle_solver.run([0, 7], [0, 1])['results'] self.assertTrue(res.success) for i, t in enumerate(res.t): x, y = res.y[:, i] x_exp, y_exp = np.array([-np.sin(t), np.cos(t)]) self.assertAlmostEqual(x, x_exp, places=2) self.assertAlmostEqual(y, y_exp, places=2) def testCircleBox(self): t_span = [0, 300] res = self.circle_solver.run(t_span, [0, 1]) fig = self.circle_solver.plot2d(res, None) ax = fig.get_axes()[0] t_dense = np.arange(*t_span, t_span[1]/1000) box = np.array([np.cos(t_dense), -np.sin(t_dense)]) ax.plot(*box, '-') newbox = np.sqrt(res['results'].y[0, -1]**2 + res['results'].y[1, -1]**2)*box ax.plot(*newbox, '-') plt.show(False)
class TestModel(unittest.TestCase): def setUp(self): # test data self.circle_solver = SystemSolver(CircleSystem()) self.lorenz_solver = SystemSolver(LorenzSystem()) def test3dGraph(self): res = self.lorenz_solver.run([0, 10], [1, 1, 1]) fig = self.lorenz_solver.plotnd(res) self.lorenz_solver.plot3d(res) self.assertEqual(4, len(fig.get_axes())) def test2dGraph(self): res = self.circle_solver.run([0, 10], [1, 1]) fig = self.circle_solver.plotnd(res) self.circle_solver.plot2d(res) self.assertEqual(3, len(fig.get_axes())) def testMultiGraph(self): run1 = self.lorenz_solver.run([0, 20], [1, 1, 1]) run2 = self.lorenz_solver.run([0, 20], [1, 1, 1]) run3 = self.lorenz_solver.run([0, 20], [1, 1, 1 + 10**-9]) fig = self.lorenz_solver.plot3d(run1) fig = self.lorenz_solver.plot3d(run2, fig) self.lorenz_solver.plot3d(run3, fig) # You should see that orange (2nd graph) covers blue (1st graph) while # adding a billionth to green (3rd graph) causes it to diverge. def testMulti2dGraph(self): run1 = self.circle_solver.run([0, 20], [0, 2]) run2 = self.circle_solver.run([0, 20], [0, 1]) fig = self.circle_solver.plot2d(run1) self.circle_solver.plot2d(run2, fig) def testMultiNdGraph(self): run1 = self.lorenz_solver.run([0, 20], [1, 1, 1]) run2 = self.lorenz_solver.run([0, 20], [1, 1, 1.001]) fig = self.lorenz_solver.plotnd(run1) self.lorenz_solver.plotnd(run2, fig)
import numpy as np import matplotlib.pyplot as plt from echonn.sys import SystemSolver, RestrictedCircular3Body, LyapunovSystem if __name__ == "__main__": mu = 0.5 sys = RestrictedCircular3Body(body_ratio=mu) lce = LyapunovSystem(sys) #init = [1, -1, .1, .1] init = np.array(1000 * np.random.rand(4), dtype=int) / 1000 slv = SystemSolver(sys) #run = slv.run([0, 10], init, max_step=0.001) T = 100 lce, run = slv.get_lce(T=T, y0=init) #lce, run = slv.get_lce(T=T) mat = run['results'].y[4:, -1].reshape(4, 4) run['results'].y = run['results'].y[[0, 2], :] slv.plot2d(run) plt.scatter([-sys.alpha, sys.mu], [0, 0]) print(init) print(mat) print('lce:', lce) #plt.xlim((-15, 15)) #plt.ylim((-15, 15)) # Saved manually since it can't be scripted plt.show(True)
ranking = np.argsort(rank_metric_cv) def rmse(d, y): num_samples = d.shape[0] return np.sqrt(np.sum((d-y)**2) / num_samples) # extract system and build solver sys = run['system'] slvr = SystemSolver(sys) # draw full data runt = deepcopy(run) runt['results'].y = run['results'].y[[0, 2], :] slvr.plot2d(runt) plt.scatter([-sys.alpha, sys.mu], [0, 0]) plt.savefig(os.path.join(dir_pre, 'full_differential.png')) # draw test data runt['results'].t = ts_data.test_t runt['results'].y = ts_data.test_y[:, [0, 2]].T slvr.plot2d(runt) plt.scatter([-sys.alpha, sys.mu], [0, 0]) plt.savefig(os.path.join(dir_pre, 'test_data.png')) how_many = 5 for rank, i in enumerate(ranking[:how_many]): ds_test, ys_test, total_rmse = results['best model rmse'][i][3] print(i, total_rmse, results['params'][i])