Exemple #1
0
    def test_tracker_linear(self):
        default_precision(30)
        x = self.x
        y = self.y
        t = self.t
        s = System()

        vars = VariableGroup()
        vars.append(y)
        s.add_function(y - t)
        s.add_path_variable(t)
        s.add_variable_group(vars)

        ampconfig = amp_config_from(s)

        tracker = AMPTracker(s)

        stepping_pref = SteppingConfig()
        newton_pref = NewtonConfig()

        tracker.setup(Predictor.Euler, 1e-5, 1e5, stepping_pref, newton_pref)
        tracker.precision_setup(ampconfig)

        t_start = mpfr_complex(1)
        t_end = mpfr_complex(0)

        y_start = mi.VectorXmp([mpfr_complex(1)])

        y_end = mi.VectorXmp()

        tracker.track_path(y_end, t_start, t_end, y_start)

        self.assertEqual(y_end.rows(), 1)
        self.assertLessEqual(mp.norm(y_end[0] - mpfr_complex(0)), 1e-5)
Exemple #2
0
 def setUp(self):
     default_precision(30)
     self.x_d = complex(-2.43, .21)
     self.y_d = complex(4.84, -1.94)
     self.z_d = complex(-6.48, -.731)
     self.p_d = complex(-.321, -.72)
     self.tol_d = float(1e-15)
     #
     self.x_mp = mpfr_complex("-2.43", ".21")
     self.y_mp = mpfr_complex("4.84", "-1.94")
     self.z_mp = mpfr_complex("-6.48", "-.731")
     self.p_mp = mpfr_complex("-.321", "-.72")
     self.tol_mp = mpfr_float("1e-27")
Exemple #3
0
 def test_sub(self):
     x = self.x
     y = self.y
     z = self.z
     p = self.p
     a = self.a
     b = self.b
     tol_d = self.tol_d
     tol_mp = self.tol_mp
     #
     f = Function(x - y - a)
     self.assertLessEqual(np.abs(f.eval_d().real / (-10.39) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (1.538) - 1), tol_d)
     #
     self.assertLessEqual(
         mp.abs(f.eval_mp().real / mpfr_float("-10.39") - 1), tol_mp)
     self.assertLessEqual(
         mp.abs(f.eval_mp().imag / mpfr_float("1.538") - 1), tol_mp)
     #
     f = Function(y - Float("3.87"))
     self.assertLessEqual(np.abs(f.eval_d().real / (0.97) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (-1.94) - 1), tol_d)
     #
     f = Function(y - Float("3.87", "0"))
     self.assertLessEqual(np.abs(f.eval_d().real / (0.97) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (-1.94) - 1), tol_d)
     #
     #
     f = Function(y - mpfr_complex("3.87", "-2.1"))
     self.assertLessEqual(np.abs(f.eval_d().real / (0.97) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (0.16) - 1), tol_d)
     #
     self.assertLessEqual(mp.abs(f.eval_mp().real / mpfr_float("0.97") - 1),
                          tol_mp)
     self.assertLessEqual(mp.abs(f.eval_mp().imag / mpfr_float("0.16") - 1),
                          tol_mp)
     #
     f = Function(y - (-5))
     self.assertLessEqual(np.abs(f.eval_d().real / (9.84) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (-1.94) - 1), tol_d)
     #
     f = Function(x)
     f -= y
     f -= a
     self.assertLessEqual(np.abs(f.eval_d().real / (-10.39) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (1.538) - 1), tol_d)
     #
     self.assertLessEqual(
         mp.abs(f.eval_mp().real / mpfr_float("-10.39") - 1), tol_mp)
     self.assertLessEqual(
         mp.abs(f.eval_mp().imag / mpfr_float("1.538") - 1), tol_mp)
     #
     f = Function(y)
     f -= Float("3.87")
     self.assertLessEqual(np.abs(f.eval_d().real / (0.97) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (-1.94) - 1), tol_d)
Exemple #4
0
 def test_plus(self):
     x = self.x
     y = self.y
     z = self.z
     p = self.p
     a = self.a
     b = self.b
     tol_d = self.tol_d
     tol_mp = self.tol_mp
     #
     f = Function(x + y + a)
     self.assertLessEqual(np.abs(f.eval_d().real / (5.53) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (-1.118) - 1), tol_d)
     #
     self.assertLessEqual(mp.abs(f.eval_mp().real / mpfr_float("5.53") - 1),
                          tol_mp)
     self.assertLessEqual(
         mp.abs(f.eval_mp().imag / mpfr_float("-1.118") - 1), tol_mp)
     #
     f = Function(x + Float("3.87"))
     self.assertLessEqual(np.abs(f.eval_d().real / (1.44) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (0.21) - 1), tol_d)
     #
     f = Function(x + mpfr_complex("3.87", "-2.1"))
     self.assertLessEqual(np.abs(f.eval_d().real / (1.44) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (-1.89) - 1), tol_d)
     #
     self.assertLessEqual(mp.abs(f.eval_mp().real / mpfr_float("1.44") - 1),
                          tol_mp)
     self.assertLessEqual(
         mp.abs(f.eval_mp().imag / mpfr_float("-1.89") - 1), tol_mp)
     #
     f = Function(x + (-5))
     self.assertLessEqual(np.abs(f.eval_d().real / (-7.43) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (0.21) - 1), tol_d)
     #
     self.assertLessEqual(
         mp.abs(f.eval_mp().real / mpfr_float("-7.43") - 1), tol_mp)
     self.assertLessEqual(mp.abs(f.eval_mp().imag / mpfr_float("0.21") - 1),
                          tol_mp)
     #
     f = Function(x)
     f += y
     f += a
     self.assertLessEqual(np.abs(f.eval_d().real / (5.53) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (-1.118) - 1), tol_d)
     #
     self.assertLessEqual(mp.abs(f.eval_mp().real / mpfr_float("5.53") - 1),
                          tol_mp)
     self.assertLessEqual(
         mp.abs(f.eval_mp().imag / mpfr_float("-1.118") - 1), tol_mp)
     #
     f = Function(x)
     f += Float("3.87")
     self.assertLessEqual(np.abs(f.eval_d().real / (1.44) - 1), tol_d)
     self.assertLessEqual(np.abs(f.eval_d().imag / (0.21) - 1), tol_d)
Exemple #5
0
    def test_tracker_singular_start(self):
        default_precision(30)
        x = self.x
        y = self.y
        t = self.t
        s = System()

        vars = VariableGroup()
        vars.append(y)
        vars.append(x)
        s.add_function(x**2 + (1 - t) * x)
        s.add_function(y**2 + (1 - t) * y)
        s.add_path_variable(t)
        s.add_variable_group(vars)
        s.precision(30)
        ampconfig = amp_config_from(s)

        tracker = AMPTracker(s)

        stepping_pref = SteppingConfig()
        newton_pref = NewtonConfig()

        tracker.setup(Predictor.Euler, 1e-5, 1e5, stepping_pref, newton_pref)
        tracker.precision_setup(ampconfig)

        t_start = mpfr_complex(1)
        t_end = mpfr_complex(0)

        y_start = mi.VectorXmp([mpfr_complex(0),
                                mpfr_complex(0)])

        y_end = mi.VectorXmp()

        track_success = tracker.track_path(y_end, t_start, t_end, y_start)

        self.assertTrue(track_success == SuccessCode.SingularStartPoint)
        self.assertEqual(y_end.rows(), 0)
Exemple #6
0
 def setUp(self):
     default_precision(30)
     self.x = Variable("x")
     self.x.set_current_value(complex(-2.43, .21))
     self.y = Variable("y")
     self.y.set_current_value(complex(4.84, -1.94))
     self.z = Variable("z")
     self.z.set_current_value(complex(-6.48, -.731))
     self.p = Variable("p")
     self.p.set_current_value(complex(-.321, -.72))
     self.a = Float(mpfr_complex("3.12", ".612"))
     self.b = Float(mpfr_complex("-.823", "2.62"))
     self.tol_d = float(9e-14)
     #
     self.x.set_current_value(mpfr_complex("-2.43", ".21"))
     self.y.set_current_value(mpfr_complex("4.84", "-1.94"))
     self.z.set_current_value(mpfr_complex("-6.48", "-.731"))
     self.p.set_current_value(mpfr_complex("-.321", "-.72"))
     self.a = Float(mpfr_complex("3.12", ".612"))
     self.b = Float(mpfr_complex("-.823", "2.62"))
     self.tol_mp = mpfr_float("1e-27")
Exemple #7
0
    def test_using_total_degree_ss(self):
        default_precision(self.ambient_precision);

        x = Variable("x");
        y = Variable("y");
        t = Variable("t");
        #
        sys = System();
        #
        var_grp = VariableGroup();
        var_grp.append(x);
        var_grp.append(y);

        sys.add_variable_group(var_grp);

        sys.add_function((x-1)**3)
        sys.add_function((y-1)**2)

        sys.homogenize();
        sys.auto_patch();

        self.assertEqual(sys.is_patched(), 1)
        self.assertEqual(sys.is_homogeneous(), 1)

        td = ss.TotalDegree(sys);

        self.assertEqual(td.is_patched(), 1)
        self.assertEqual(td.is_homogeneous(), 1)

        gamma = Rational.rand();


        final_system = (1-t)*sys + gamma*t*td;
        final_system.add_path_variable(t);

        print(final_system)
        prec_config = AMPConfig(final_system);

        stepping_pref = SteppingConfig();
        newton_pref = NewtonConfig();



        tracker = AMPTracker(final_system);

        tracker.setup(Predictor.RK4, 1e-5, 1e5, stepping_pref, newton_pref);
        tracker.precision_setup(prec_config);

        num_paths_to_track = td.num_start_points();
        n = int(str(num_paths_to_track));

        t_start = mpfr_complex(1);
        t_endgame_boundary = mpfr_complex("0.1");
        t_final = mpfr_complex(0);

        bdry_points = [mi.VectorXmp() for i in range(n)]
        for i in range(n):
            default_precision(self.ambient_precision);
            final_system.precision(self.ambient_precision);
            start_point = td.start_point_mp(i);

            bdry_pt = mi.VectorXmp();
            track_success_code = tracker.track_path(bdry_pt,t_start, t_endgame_boundary, start_point);
            bdry_points[i] = bdry_pt;

            self.assertEqual(track_success_code, SuccessCode.Success)



        tracker.setup(Predictor.HeunEuler, 1e-6, 1e5, stepping_pref, newton_pref);
        my_endgame = AMPCauchyEG(tracker);


        final_homogenized_solutions = [mi.VectorXmp() for i in range(n)]
        for i in range(n):
            default_precision(bdry_points[i][0].precision());
            final_system.precision(bdry_points[i][0].precision());
            track_success_code = my_endgame.run(mpfr_complex(t_endgame_boundary),bdry_points[i]);
            final_homogenized_solutions[i] = my_endgame.final_approximation();
            print(final_system.dehomogenize_point(final_homogenized_solutions[i]));
            self.assertEqual(track_success_code, SuccessCode.Success)