Add files
This commit is contained in:
0
python/test/tracking/__init__.py
Normal file
0
python/test/tracking/__init__.py
Normal file
245
python/test/tracking/amptracking_test.py
Normal file
245
python/test/tracking/amptracking_test.py
Normal file
@@ -0,0 +1,245 @@
|
||||
# This file is part of Bertini 2.
|
||||
#
|
||||
# python/test/system_test.py is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# python/test/system_test.py is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with python/test/system_test.py. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
#
|
||||
# See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
# as well as COPYING. Bertini2 is provided with permitted
|
||||
# additional terms in the b2/licenses/ directory.
|
||||
|
||||
# individual authors of this file include:
|
||||
#
|
||||
# James Collins
|
||||
# West Texas A&M University
|
||||
# Spring 2016
|
||||
#
|
||||
# silviana amethyst
|
||||
# UWEC
|
||||
# Spring, Summer 2018
|
||||
#
|
||||
|
||||
|
||||
|
||||
__author__ = 'James Collins'
|
||||
|
||||
from pybertini import *
|
||||
from pybertini.function_tree.symbol import *
|
||||
from pybertini.function_tree.root import *
|
||||
from pybertini.function_tree import *
|
||||
from pybertini.tracking import *
|
||||
from pybertini.tracking.config import *
|
||||
|
||||
import unittest
|
||||
import numpy as np
|
||||
import pdb
|
||||
|
||||
import pybertini.multiprec as mp
|
||||
from pybertini.multiprec import Float as mpfr_float
|
||||
from pybertini.multiprec import Complex as mpfr_complex
|
||||
|
||||
|
||||
class AMPTrackingTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.toldbl = 1e-15;
|
||||
self.x = Variable("x");
|
||||
self.y = Variable("y");
|
||||
self.z = Variable("z");
|
||||
self.t = Variable("t");
|
||||
self.a = Float("4.897", "1.23")
|
||||
#
|
||||
self.f = Function(self.x*self.y);
|
||||
self.g = Function(pow(self.x,2)*self.y - self.a*self.z*self.x);
|
||||
|
||||
|
||||
|
||||
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 = np.array([mpfr_complex(1)]);
|
||||
|
||||
y_end = np.array(np.zeros(shape=(s.num_variables()), dtype=np.int64),dtype=mpfr_complex);
|
||||
|
||||
tracker.track_path(y_end, t_start, t_end, y_start);
|
||||
|
||||
self.assertEqual(y_end.shape, (s.num_variables(),))
|
||||
self.assertLessEqual(mp.abs(y_end[0]-mpfr_complex(0)), 1e-5)
|
||||
|
||||
|
||||
|
||||
|
||||
def test_tracker_quad(self):
|
||||
default_precision(30);
|
||||
y = self.y; t = self.t;
|
||||
s = System();
|
||||
|
||||
vars = VariableGroup();
|
||||
vars.append(y);
|
||||
s.add_function(y-t**2);
|
||||
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(-1)
|
||||
|
||||
y_start = np.array([mpfr_complex(1)]);
|
||||
|
||||
y_end = np.array(np.zeros(shape=(s.num_variables()), dtype=np.int64),dtype=mpfr_complex);
|
||||
|
||||
tracker.track_path(y_end, t_start, t_end, y_start);
|
||||
|
||||
self.assertEqual(y_end.shape, (s.num_variables(),))
|
||||
self.assertLessEqual(mp.abs(y_end[0]-mpfr_complex(0)), 1e-5)
|
||||
|
||||
|
||||
|
||||
def test_tracker_sqrt(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-t);
|
||||
s.add_function(y**2 - x)
|
||||
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 = np.array([mpfr_complex(1), mpfr_complex(1)]);
|
||||
|
||||
y_end = np.array(np.zeros(shape=(s.num_variables()), dtype=np.int64),dtype=mpfr_complex);
|
||||
|
||||
track_success = tracker.track_path(y_end, t_start, t_end, y_start);
|
||||
|
||||
self.assertTrue(track_success == SuccessCode.Success)
|
||||
self.assertEqual(y_end.shape, (s.num_variables(),))
|
||||
self.assertLessEqual(mp.abs(y_end[0]-mpfr_complex(0)), 1e-5)
|
||||
self.assertLessEqual(mp.abs(y_end[1]-mpfr_complex(0)), 1e-5)
|
||||
|
||||
y_start = np.array([mpfr_complex(1), mpfr_complex(-1)]);
|
||||
|
||||
tracker.track_path(y_end, t_start, t_end, y_start);
|
||||
|
||||
self.assertEqual(y_end.shape, (s.num_variables(),))
|
||||
self.assertLessEqual(mp.abs(y_end[0]-mpfr_complex(0)), 1e-5)
|
||||
self.assertLessEqual(mp.abs(y_end[1]-mpfr_complex(0)), 1e-5)
|
||||
|
||||
|
||||
y_start = np.array([mpfr_complex(-1), mpfr_complex(-1)]);
|
||||
|
||||
tracker.track_path(y_end, t_start, t_end, y_start);
|
||||
|
||||
self.assertEqual(y_end.shape, (s.num_variables(),))
|
||||
self.assertLessEqual(mp.abs(y_end[0]-mpfr_complex(0)), 1e-5)
|
||||
self.assertLessEqual(mp.abs(y_end[1]-mpfr_complex(0)), 1e-5)
|
||||
|
||||
|
||||
y_start = np.array([mpfr_complex(-1), mpfr_complex(0,1)]);
|
||||
|
||||
track_success = tracker.track_path(y_end, t_start, t_end, y_start);
|
||||
|
||||
|
||||
self.assertTrue(track_success == SuccessCode.Success)
|
||||
self.assertEqual(y_end.shape, (s.num_variables(),))
|
||||
self.assertLessEqual(mp.abs(y_end[0]-mpfr_complex(0)), 1e-5)
|
||||
self.assertLessEqual(mp.abs(y_end[1]-mpfr_complex(0)), 1e-5)
|
||||
|
||||
|
||||
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 = np.array([mpfr_complex(0), mpfr_complex(0)]);
|
||||
|
||||
|
||||
y_end = np.empty(shape=(s.num_variables(),),dtype=mpfr_complex);
|
||||
|
||||
track_success = tracker.track_path(y_end, t_start, t_end, y_start);
|
||||
|
||||
self.assertTrue(track_success == SuccessCode.SingularStartPoint)
|
||||
self.assertEqual(y_end.shape, (s.num_variables(),))
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main();
|
||||
|
||||
|
||||
166
python/test/tracking/endgame_test.py
Normal file
166
python/test/tracking/endgame_test.py
Normal file
@@ -0,0 +1,166 @@
|
||||
# This file is part of Bertini 2.
|
||||
#
|
||||
# python/test/endgame_test.py is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# python/test/endgame_test.py is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with python/test/endgame_test.py. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
#
|
||||
# See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
# as well as COPYING. Bertini2 is provided with permitted
|
||||
# additional terms in the b2/licenses/ directory.
|
||||
|
||||
# individual authors of this file include:
|
||||
#
|
||||
# silviana amethyst
|
||||
# University of Notre Dame
|
||||
#
|
||||
# silviana amethyst
|
||||
# UWEC
|
||||
# Spring 2018
|
||||
#
|
||||
|
||||
|
||||
|
||||
__author__ = 'ofloveandhate'
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_tests = True
|
||||
else:
|
||||
run_tests = False
|
||||
|
||||
|
||||
from pybertini import *
|
||||
from pybertini.function_tree.symbol import *
|
||||
from pybertini.function_tree.root import *
|
||||
from pybertini.function_tree import *
|
||||
from pybertini.tracking import *
|
||||
from pybertini.tracking.config import *
|
||||
from pybertini.endgame import *
|
||||
from pybertini.endgame.config import *
|
||||
|
||||
import unittest
|
||||
import numpy as np
|
||||
import pdb
|
||||
|
||||
import pybertini.system.start_system as ss
|
||||
import pybertini.multiprec as mp
|
||||
from pybertini.multiprec import Float as mpfr_float
|
||||
from pybertini.multiprec import Complex as mpfr_complex
|
||||
|
||||
|
||||
class EndgameTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.ambient_precision = 50;
|
||||
|
||||
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);
|
||||
|
||||
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)); # this line sucks, wtf.
|
||||
|
||||
t_start = mpfr_complex(1);
|
||||
t_endgame_boundary = mpfr_complex("0.1");
|
||||
t_final = mpfr_complex(0);
|
||||
|
||||
bdry_points = []
|
||||
|
||||
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 = np.array( np.zeros( (3)).astype(np.int64),dtype=mpfr_complex)
|
||||
|
||||
track_success_code = tracker.track_path(bdry_pt,t_start, t_endgame_boundary, start_point);
|
||||
bdry_points.append(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 = [np.empty(dtype=mpfr_complex, shape=(3,)) 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());
|
||||
|
||||
bdry_time = mpfr_complex(t_endgame_boundary)
|
||||
|
||||
track_success_code = my_endgame.run(bdry_time,bdry_points[i]); # should be bdry_pts[i], not XXX
|
||||
|
||||
|
||||
final_homogenized_solutions[i] = my_endgame.final_approximation();
|
||||
|
||||
self.assertEqual(track_success_code, SuccessCode.Success)
|
||||
|
||||
dehomogenized_solns = [sys.dehomogenize_point(soln) for soln in final_homogenized_solutions]
|
||||
|
||||
exact_soln = np.array([1,1])
|
||||
|
||||
for soln in dehomogenized_solns:
|
||||
assert np.sqrt(np.sum((exact_soln - soln)**2)) < 1e-10
|
||||
|
||||
|
||||
|
||||
if run_tests:
|
||||
|
||||
pgnm = 'this_argument_is_ignored_but_necessary'
|
||||
unittest.main(argv=[pgnm], exit=False)
|
||||
40
python/test/tracking/test_tracking.py
Normal file
40
python/test/tracking/test_tracking.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# This file is part of Bertini 2.
|
||||
#
|
||||
# python/test/b2_class_test.py is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# python/test/b2_class_test.py is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with python/test/b2_class_test.py. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Copyright(C) 2016-2018 by Bertini2 Development Team
|
||||
#
|
||||
# See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
# as well as COPYING. Bertini2 is provided with permitted
|
||||
# additional terms in the b2/licenses/ directory.
|
||||
|
||||
# individual authors of this file include:
|
||||
#
|
||||
# James Collins
|
||||
# West Texas A&M University
|
||||
# Spring 2016
|
||||
#
|
||||
|
||||
import tracking.amptracking_test as amptracking_test
|
||||
import tracking.endgame_test as endgame_test
|
||||
import unittest
|
||||
|
||||
|
||||
mods = (amptracking_test,endgame_test)
|
||||
suite = unittest.TestSuite();
|
||||
for tests in mods:
|
||||
thissuite = unittest.TestLoader().loadTestsFromModule(tests);
|
||||
suite.addTests(thissuite)
|
||||
#
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
Reference in New Issue
Block a user