Add files

This commit is contained in:
2025-01-14 01:15:48 +01:00
commit 2f9fcec55b
406 changed files with 87154 additions and 0 deletions

View File

@@ -0,0 +1,367 @@
//This file is part of Bertini 2.
//
//amp_criteria_test.cpp 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.
//
//amp_criteria_test.cpp 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 amp_criteria_test.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2021 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 wisconsin eau claire
#include <boost/test/unit_test.hpp>
#include <boost/multiprecision/mpfr.hpp>
#include "bertini2/mpfr_complex.hpp"
#include "bertini2/trackers/amp_criteria.hpp"
extern double threshold_clearance_d;
extern bertini::mpfr_float threshold_clearance_mp;
extern unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS;
BOOST_AUTO_TEST_SUITE(amp_criteria_tracking_basics)
using System = bertini::System;
using Variable = bertini::node::Variable;
using Var = std::shared_ptr<Variable>;
using VariableGroup = bertini::VariableGroup;
using mpq_rational = bertini::mpq_rational;
using dbl = std::complex<double>;
using mpfr = bertini::mpfr_complex;
using mpfr_float = bertini::mpfr_float;
template<typename NumType> using Vec = bertini::Vec<NumType>;
template<typename NumType> using Mat = bertini::Mat<NumType>;
BOOST_AUTO_TEST_CASE(AMP_criteriaA_double)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_1 has been set to 32000 to set off the AMPCriterionB condition.
*/
//Setting upt current space and time values for evaluation
Vec<dbl> current_space(2);
current_space << dbl(256185069753.4088,-387520022558.0519),
dbl(-0.021,-0.177);
dbl current_time(0,0);
dbl delta_t(.1,0);
current_time += delta_t;
//Defining the system and variables.
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
//For Criterion A to be checked we need Norm_J and inverse of Norm_J these were taken from Euler.hpp
Mat<dbl> dh_dx = sys.Jacobian(current_space, current_time);
auto LU = dh_dx.lu();
Vec<dbl> randy = Vec<dbl>::Random(sys.NumVariables());
Vec<dbl> temp_soln = LU.solve(randy);
auto norm_J = double(dh_dx.norm());
auto norm_J_inverse = double(temp_soln.norm());
//Setting up saftety digits to trigger AMP Criterion A failure.
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.safety_digits_1 = 32000;
auto CritA = bertini::tracking::amp::CriterionA<dbl>(norm_J,norm_J_inverse,AMP);
//Check to make sure we failed.
BOOST_CHECK_EQUAL(CritA,false);
}
BOOST_AUTO_TEST_CASE(AMP_criteriaA_mp)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_1 has been set to 32000 to set off the AMPCriterionB condition.
*/
//Setting upt current space and time values for evaluation
Vec<mpfr> current_space(2);
current_space << mpfr("256185069753.408853236449242927412","-387520022558.051912233172374487976"),
mpfr("-0.0212298348984663761753389403711889","-0.177814646531698303094367623155171");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
//Defining the system and variables.
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
//For Criterion A to be checked we need Norm_J and inverse of Norm_J these were taken from Euler.hpp
Mat<mpfr> dh_dx = sys.Jacobian(current_space, current_time);
auto LU = dh_dx.lu();
Vec<mpfr> randy = Vec<mpfr>::Random(sys.NumVariables());
Vec<mpfr> temp_soln = LU.solve(randy);
auto norm_J = double(dh_dx.norm());
auto norm_J_inverse = double(temp_soln.norm());
//Setting up saftety digits to trigger AMP Criterion A failure.
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.safety_digits_1 = 32000;
auto CritA = bertini::tracking::amp::CriterionA<mpfr>(norm_J,norm_J_inverse,AMP);
//Check to make sure we failed.
BOOST_CHECK_EQUAL(CritA,false);
}
BOOST_AUTO_TEST_CASE(AMP_criteriaB_double)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_1 has been set to 32000 to set off the AMPCriterionB condition.
*/
//Setting upt current space and time values for evaluation
Vec<dbl> current_space(2);
current_space << dbl(256185069753.4088,-387520022558.0519),
dbl(-0.021,-0.177);
dbl current_time(0,0);
dbl delta_t(.1,0);
current_time += delta_t;
//Defining the system and variables.
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
//For Criterion A to be checked we need Norm_J and inverse of Norm_J these were taken from Euler.hpp
auto f = sys.Eval(current_space, current_time);
Mat<dbl> dh_dx = sys.Jacobian(current_space, current_time);
auto LU = dh_dx.lu();
auto delta_z = LU.solve(-f);
Vec<dbl> randy = Vec<dbl>::Random(sys.NumVariables());
Vec<dbl> temp_soln = LU.solve(randy);
auto norm_J = double(dh_dx.norm());
auto norm_J_inverse = double(temp_soln.norm());
//Setting up saftety digits to trigger AMP Criterion B failure.
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.safety_digits_1 = 32000;
unsigned int num_newton_iterations_remaining = 1;
auto TrackTolBeforeEG = 1e-5; //Obtained from Bertini Book.
auto CritB = bertini::tracking::amp::CriterionB<dbl>(norm_J,norm_J_inverse,num_newton_iterations_remaining,TrackTolBeforeEG,delta_z.norm(),AMP);
//Check to make sure we failed.
BOOST_CHECK_EQUAL(CritB,false);
}
BOOST_AUTO_TEST_CASE(AMP_criteriaB_mp)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_1 has been set to 32000 to set off the AMPCriterionB condition.
*/
//Setting upt current space and time values for evaluation
Vec<mpfr> current_space(2);
current_space << mpfr("256185069753.408853236449242927412","-387520022558.051912233172374487976"),
mpfr("-0.0212298348984663761753389403711889","-0.177814646531698303094367623155171");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
//Defining the system and variables.
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
//For Criterion A to be checked we need Norm_J and inverse of Norm_J these were taken from Euler.hpp
auto f = sys.Eval(current_space, current_time);
Mat<mpfr> dh_dx = sys.Jacobian(current_space, current_time);
auto LU = dh_dx.lu();
Vec<mpfr> delta_z = LU.solve(-f);
Vec<mpfr> randy = Vec<mpfr>::Random(sys.NumVariables());
Vec<mpfr> temp_soln = LU.solve(randy);
auto norm_J = double(dh_dx.norm());
auto norm_J_inverse = double(temp_soln.norm());
//Setting up saftety digits to trigger AMP Criterion B failure.
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.safety_digits_1 = 32000;
unsigned int num_newton_iterations_remaining = 1;
double TrackTolBeforeEG = 1e-5; //Obtained from Bertini Book.
auto CritB = bertini::tracking::amp::CriterionB<mpfr>(norm_J,norm_J_inverse,num_newton_iterations_remaining,TrackTolBeforeEG,double(delta_z.norm()),AMP);
//Check to make sure we failed.
BOOST_CHECK_EQUAL(CritB,false);
}
BOOST_AUTO_TEST_CASE(AMP_criteriaC_double)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_1 has been set to 32000 to set off the AMPCriterionB condition.
*/
//Setting upt current space and time values for evaluation
Vec<dbl> current_space(2);
current_space << dbl(256185069753.4088,-387520022558.0519),
dbl(-0.021,-0.177);
dbl current_time(0,0);
dbl delta_t(.1,0);
current_time += delta_t;
//Defining the system and variables.
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
//For Criterion A to be checked we need Norm_J and inverse of Norm_J these were taken from Euler.hpp
Mat<dbl> dh_dx = sys.Jacobian(current_space, current_time);
auto LU = dh_dx.lu();
Vec<dbl> randy = Vec<dbl>::Random(sys.NumVariables());
Vec<dbl> temp_soln = LU.solve(randy);
auto norm_J_inverse = double(temp_soln.norm());
//Setting up saftety digits to trigger AMP Criterion C failure.
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.safety_digits_2 = 32000;
auto TrackTolBeforeEG = 1e-5; //Obtained from Bertini Book.
auto CritC = bertini::tracking::amp::CriterionC<dbl>(norm_J_inverse,current_space,TrackTolBeforeEG,AMP);
//Check to make sure we failed.
BOOST_CHECK_EQUAL(CritC,false);
}
BOOST_AUTO_TEST_CASE(AMP_criteriaC_mp)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_1 has been set to 32000 to set off the AMPCriterionB condition.
*/
//Setting upt current space and time values for evaluation
Vec<mpfr> current_space(2);
current_space << mpfr("256185069753.408853236449242927412","-387520022558.051912233172374487976"),
mpfr("-0.0212298348984663761753389403711889","-0.177814646531698303094367623155171");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
//Defining the system and variables.
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
//For Criterion A to be checked we need Norm_J and inverse of Norm_J these were taken from Euler.hpp
Mat<mpfr> dh_dx = sys.Jacobian(current_space, current_time);
auto LU = dh_dx.lu();
Vec<mpfr> randy = Vec<mpfr>::Random(sys.NumVariables());
Vec<mpfr> temp_soln = LU.solve(randy);
auto norm_J_inverse = double(temp_soln.norm());
//Setting up saftety digits to trigger AMP Criterion B failure.
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.safety_digits_2 = 32000;
double TrackTolBeforeEG = 1e-5; //Obtained from Bertini Book.
auto CritC = bertini::tracking::amp::CriterionC<mpfr>(norm_J_inverse,current_space,TrackTolBeforeEG,AMP);
//Check to make sure we failed.
BOOST_CHECK_EQUAL(CritC,false);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,953 @@
//This file is part of Bertini 2.
//
//tracker_test.cpp 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.
//
//tracker_test.cpp 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 tracker_test.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2021 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 wisconsin eau claire
#include <boost/test/unit_test.hpp>
#include "bertini2/system/start_systems.hpp"
#include "bertini2/trackers/tracker.hpp"
extern double threshold_clearance_d;
extern bertini::mpfr_float threshold_clearance_mp;
extern unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS;
BOOST_AUTO_TEST_SUITE(AMP_tracker_basics)
using System = bertini::System;
using Variable = bertini::node::Variable;
using Var = std::shared_ptr<Variable>;
using VariableGroup = bertini::VariableGroup;
using dbl = std::complex<double>;
using mpfr = bertini::mpfr_complex;
using mpfr_float = bertini::mpfr_float;
template<typename NumType> using Vec = bertini::Vec<NumType>;
template<typename NumType> using Mat = bertini::Mat<NumType>;
using bertini::DefaultPrecision;
BOOST_AUTO_TEST_CASE(minstepsize)
{
DefaultPrecision(30);
using namespace bertini::tracking;
mpfr_float remaining_time("1e-10");
BOOST_CHECK_EQUAL(MinStepSizeForPrecision(16, remaining_time),mpfr_float("1e-23"));
BOOST_CHECK_CLOSE(MinStepSizeForPrecision(40, remaining_time),mpfr_float("1e-47"), mpfr_float("1e-28"));
}
BOOST_AUTO_TEST_CASE(mindigits)
{
DefaultPrecision(30);
using namespace bertini::tracking;
mpfr_float remaining_time("1e-30");
mpfr_float min_stepsize("1e-35");
mpfr_float max_stepsize("1e-33");
auto digits = MinDigitsForStepsizeInterval(min_stepsize, max_stepsize, remaining_time);
BOOST_CHECK_EQUAL(digits, 8);
}
BOOST_AUTO_TEST_CASE(AMP_tracker_track_linear)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{y};
sys.AddFunction(y-t);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> y_start(1);
y_start << mpfr(1);
Vec<mpfr> y_end;
tracker.TrackPath(y_end,
t_start, t_end, y_start);
BOOST_CHECK_EQUAL(y_end.size(),1);
BOOST_CHECK(abs(y_end(0)-mpfr(0)) < 1e-5);
}
BOOST_AUTO_TEST_CASE(AMP_tracker_track_quadratic)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{y};
sys.AddFunction(y-pow(t,2));
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(-1);
Vec<mpfr> y_start(1);
y_start << mpfr(1);
Vec<mpfr> y_end;
tracker.TrackPath(y_end,
t_start, t_end, y_start);
BOOST_CHECK_EQUAL(y_end.size(),1);
BOOST_CHECK(abs(y_end(0)-mpfr(1)) < 1e-5);
}
BOOST_AUTO_TEST_CASE(AMP_tracker_track_decic)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{y};
sys.AddFunction(y-pow(t,10));
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(-2);
Vec<mpfr> y_start(1);
y_start << mpfr(1);
Vec<mpfr> y_end;
tracker.TrackPath(y_end,
t_start, t_end, y_start);
BOOST_CHECK_EQUAL(y_end.size(),1);
BOOST_CHECK(abs(y_end(0)-mpfr("1024.0")) < 1e-5);
}
BOOST_AUTO_TEST_CASE(AMP_tracker_track_square_root)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(x-t);
sys.AddFunction(pow(y,2)-x);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
start_point << mpfr(1), mpfr(1);
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-mpfr(0)) < 1e-5);
BOOST_CHECK(abs(end_point(1)-mpfr(0)) < 1e-5);
start_point << mpfr(1), mpfr(-1);
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-mpfr(0)) < 1e-5);
BOOST_CHECK(abs(end_point(1)-mpfr(0)) < 1e-5);
t_start = mpfr(-1);
start_point << mpfr(-1), mpfr(0,-1);
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-mpfr(0)) < 1e-5);
BOOST_CHECK(abs(end_point(1)-mpfr(0)) < 1e-5);
start_point << mpfr(-1), mpfr(0,1);
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-mpfr(0)) < 1e-5);
BOOST_CHECK(abs(end_point(1)-mpfr(0)) < 1e-5);
}
/*
1. Goal: Handle a singular start point?
Expected Behavior: Doesn't start tracking.
System:
f = x^2 + (1-t)*x;
g = y^2 + (1-t)*y;
Start t: 1
Start point: (0,0)
End t: 0
End point: N/A
*/
BOOST_AUTO_TEST_CASE(AMP_tracker_doesnt_start_from_singular_start_point)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(pow(x,2) + (1-t)*x);
sys.AddFunction(pow(y,2) + (1-t)*y);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
start_point << mpfr(0), mpfr(0);
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::SingularStartPoint);
BOOST_CHECK_EQUAL(end_point.size(),0);
}
BOOST_AUTO_TEST_CASE(AMP_tracker_tracking_DOES_SOMETHING_PREDICTABLE_from_near_to_singular_start_point)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(pow(x,2) + (1-t)*x);
sys.AddFunction(pow(y,2) + (1-t)*y);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
stepping_preferences.max_num_steps = 1e2;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
start_point << mpfr("1e-28"), mpfr("1e-28");
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success!=bertini::SuccessCode::Success && tracking_success!=bertini::SuccessCode::NeverStarted);
BOOST_CHECK_EQUAL(end_point.size(),0);
}
/*
2. Goal: Make sure we can handle a simple, mixed (x,y in both polynomials), nonhomogeneous system.
Expected Behavior: Success.
System:
f = x^2 + (1-t)*x - 1;
g = y^2 + (1-t)*x*y - 2;
Start t: 1
Start point: (1, 1.414)
End t: 0
End point: (6.180339887498949e-01, 1.138564265110173e+00)
(Using Bertini default tracking tolerances.)
*/
BOOST_AUTO_TEST_CASE(AMP_simple_nonhomogeneous_system_trackable_initialprecision16)
{
DefaultPrecision(16);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(pow(x,2) + (1-t)*x - 1);
sys.AddFunction(pow(y,2) + (1-t)*x*y - 2);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
start_point << mpfr(1), mpfr("1.41421356237309504880168872421");
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-mpfr("6.180339887498949e-01")) < 1e-5);
BOOST_CHECK(abs(end_point(1)-mpfr("1.138564265110173e+00")) < 1e-5);
}
BOOST_AUTO_TEST_CASE(AMP_simple_nonhomogeneous_system_trackable_initialprecision30_tighter_track_tol)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(pow(x,2) + (1-t)*x - 1);
sys.AddFunction(pow(y,2) + (1-t)*x*y - 2);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
newton_preferences.max_num_newton_iterations = 6;
tracker.Setup(Predictor::Euler,
1e-30,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
DefaultPrecision(30);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
start_point << mpfr(1), mpfr("1.41421356237309504880168872421");
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
DefaultPrecision(40);
Vec<mpfr> true_solution(2);
true_solution << mpfr("0.61803398874989484820458683436563811772030918"), mpfr("1.13856426511017256414753784441721594451116198");
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-true_solution(0)) < 1e-30);
BOOST_CHECK(abs(end_point(1)-true_solution(1)) < 1e-30);
BOOST_CHECK( (end_point - true_solution).norm() < 1e-30);
}
BOOST_AUTO_TEST_CASE(AMP_simple_nonhomogeneous_system_trackable_initialprecision30)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(pow(x,2) + (1-t)*x - 1);
sys.AddFunction(pow(y,2) + (1-t)*x*y - 2);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
tracker.PrecisionPreservation(true);
start_point << mpfr(1), mpfr("1.414");
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK_EQUAL(DefaultPrecision(),30);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-mpfr("6.180339887498949e-01")) < 1e-5);
BOOST_CHECK(abs(end_point(1)-mpfr("1.138564265110173e+00")) < 1e-5);
}
BOOST_AUTO_TEST_CASE(AMP_simple_nonhomogeneous_system_trackable_initialprecision100)
{
DefaultPrecision(100);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(pow(x,2) + (1-t)*x - 1);
sys.AddFunction(pow(y,2) + (1-t)*x*y - 2);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionPreservation(true);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
start_point << mpfr(1), mpfr("1.414");
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK_EQUAL(DefaultPrecision(),100);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(end_point.size(),2);
BOOST_CHECK(abs(end_point(0)-mpfr("6.180339887498949e-01")) < 1e-5);
BOOST_CHECK(abs(end_point(1)-mpfr("1.138564265110173e+00")) < 1e-5);
}
/*
5. Goal: Fail when running into a singularity.
Expected Behavior: Path failure near t=0.5.
Note: There's a parameter in this system, which depends on the path variable. This implicitly checks that functionality.
System:
s= -1*(1-t) + 1*t;
f = x^2-s;
g = y^2-s;
Start t: 1
Start point: (1,1)
End t: 0
End point: N/A (Path should fail at t=0.5)
*/
BOOST_AUTO_TEST_CASE(AMP_tracker_fails_with_singularity_on_path)
{
DefaultPrecision(30);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
auto s = -1*(1-t) + 1*t;
System sys;
VariableGroup v{x,y};
sys.AddFunction(pow(x,2) - s);
sys.AddFunction(pow(y,2) - s);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionPreservation(true);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
start_point << mpfr(1), mpfr(1);
bertini::SuccessCode tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
BOOST_CHECK(tracking_success!=bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(DefaultPrecision(),30);
}
// has two solutions:
//
// 1.
// x = -0.61803398874989484820458683
// y = 1.6180339887498948482045868
//
// 2.
// x = 0.16180339887498948482045868
// y = -0.6180339887498948482045868
BOOST_AUTO_TEST_CASE(AMP_track_total_degree_start_system)
{
using namespace bertini::tracking;
DefaultPrecision(30);
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddVariableGroup(v);
sys.AddFunction(x*y+1);
sys.AddFunction(x+y-1);
sys.Homogenize();
sys.AutoPatch();
BOOST_CHECK(sys.IsHomogeneous());
BOOST_CHECK(sys.IsPatched());
auto TD = bertini::start_system::TotalDegree(sys);
TD.Homogenize();
BOOST_CHECK(TD.IsHomogeneous());
BOOST_CHECK(TD.IsPatched());
auto final_system = (1-t)*sys + t*TD;
final_system.AddPathVariable(t);
auto tracker = AMPTracker(final_system);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5, 1e5,
stepping_preferences, newton_preferences);
tracker.PrecisionSetup(bertini::tracking::AMPConfigFrom(final_system));
tracker.PrecisionPreservation(true);
mpfr t_start(1), t_end(0);
std::vector<Vec<mpfr> > solutions;
for (unsigned ii = 0; ii < TD.NumStartPoints(); ++ii)
{
auto start_point = TD.StartPoint<mpfr>(ii);
Vec<mpfr> result;
bertini::SuccessCode tracking_success = tracker.TrackPath(result,t_start,t_end,start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(DefaultPrecision(),30);
solutions.push_back(final_system.DehomogenizePoint(result));
}
Vec<mpfr> solution_1(2);
solution_1 << mpfr("-0.61803398874989484820458683","0"), mpfr("1.6180339887498948482045868","0");
Vec<mpfr> solution_2(2);
solution_2 << mpfr("1.6180339887498948482045868","0"), mpfr("-0.6180339887498948482045868","0");
unsigned num_occurences(0);
for (auto s : solutions)
{
if ( (s-solution_1).norm() < mpfr_float("1e-5"))
num_occurences++;
}
BOOST_CHECK_EQUAL(num_occurences,1);
num_occurences = 0;
for (auto s : solutions)
{
if ( (s-solution_2).norm() < mpfr_float("1e-5"))
num_occurences++;
}
BOOST_CHECK_EQUAL(num_occurences,1);
}
std::vector<Vec<mpfr> > track_total_degree(bertini::tracking::AMPTracker const& tracker, bertini::start_system::TotalDegree const& TD)
{
auto initial_precision = DefaultPrecision();
using namespace bertini::tracking;
mpfr t_start(1), t_end(0);
std::vector<Vec<mpfr> > solutions;
for (unsigned ii = 0; ii < TD.NumStartPoints(); ++ii)
{
auto start_point = TD.StartPoint<mpfr>(ii);
Vec<mpfr> result;
bertini::SuccessCode tracking_success;
tracking_success = tracker.TrackPath(result,t_start,t_end,start_point);
BOOST_CHECK(tracking_success==bertini::SuccessCode::Success);
solutions.push_back(tracker.GetSystem().DehomogenizePoint(result));
}
return solutions;
}
BOOST_AUTO_TEST_CASE(AMP_track_TD_functionalized)
{
using namespace bertini::tracking;
DefaultPrecision(30);
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddVariableGroup(v);
sys.AddFunction(x*y+1);
sys.AddFunction(x+y-1);
sys.Homogenize();
sys.AutoPatch();
BOOST_CHECK(sys.IsHomogeneous());
BOOST_CHECK(sys.IsPatched());
auto TD = bertini::start_system::TotalDegree(sys);
TD.Homogenize();
BOOST_CHECK(TD.IsHomogeneous());
BOOST_CHECK(TD.IsPatched());
auto final_system = (1-t)*sys + t*TD;
final_system.AddPathVariable(t);
auto tracker = AMPTracker(final_system);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5, 1e5,
stepping_preferences, newton_preferences);
auto AMP = bertini::tracking::AMPConfigFrom(final_system);
tracker.PrecisionSetup(AMP);
tracker.PrecisionPreservation(true);
auto solutions = track_total_degree(tracker, TD);
BOOST_CHECK_EQUAL(DefaultPrecision(),30);
Vec<mpfr> solution_1(2);
solution_1 << mpfr("-0.61803398874989484820458683","0"), mpfr("1.6180339887498948482045868","0");
Vec<mpfr> solution_2(2);
solution_2 << mpfr("1.6180339887498948482045868","0"), mpfr("-0.6180339887498948482045868","0");
unsigned num_occurences(0);
for (auto s : solutions)
{
if ( (s-solution_1).norm() < mpfr_float("1e-5"))
num_occurences++;
}
BOOST_CHECK_EQUAL(num_occurences,1);
num_occurences = 0;
for (auto s : solutions)
{
if ( (s-solution_2).norm() < mpfr_float("1e-5"))
num_occurences++;
}
BOOST_CHECK_EQUAL(num_occurences,1);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,90 @@
//This file is part of Bertini 2.
//
//corrector_test.m 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.
//
//corrector_test.m 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 corrector_test.m. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2017 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:
// jeb collins, west texas A&M
// silviana amethyst, university of wisconsin eau claire
function corrector_test()
%% Test parameters
%corr_znp1 = [2.3+1i*0.2; 1.1+1i*1.87]; % Point in space at time t=t_n
%corr_znp1 = [vpa(329.200131365025965858932555654814) - vpa(0.0000000000000000627817514906492713836728689129202)*1i]
corr_znp1 = [ 0.000000000000001,
0.000000000000001];
% vpa(0)+vpa(0)*1i];
current_time = vpa(.9);
digits(33); %Precision used
N = 1; %Number of newton iterations in correction step
%% Homotopy system
num_vars = 2; % number of variables
z = sym('z',[num_vars,1]);
syms t
%%%%%%%%%%%%%%%%%%%% polynomials that make up the homotopy%%%%%%%%%%%%%%%%%%%
H(1) = 0 + vpa(1e-15)*z(1);
H(2) = 0 + vpa(1e-15)*z(2);
% H(1) = t*(z(1)^2-1) + (1-t)*(z(1)^2+z(2)^2-4);
% H(2) = t*(z(2)-1) + (1-t)*(2*z(1)+5*z(2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\frac{dH}{dt}
dHt = diff(H,t);
% Jacobian of H(z,t) w.r.t z
for ii = 1:num_vars
for jj = 1:num_vars
JH(ii,jj) = diff(H(ii),z(jj));
end
end
% Inverse of the Jacobian
JHinv = inv(JH);
%% Predictor Corrector step
% corr_znp1 = the corrected approximation of z_{n+1}
for ii = 1:N
corr_znp1 = corr_znp1 - vpa(subs(JHinv,[z;t],[corr_znp1;current_time]))*vpa(subs(H,[z;t],[corr_znp1;current_time])).';
display(corr_znp1);
residual = subs(H,[z;t],[corr_znp1;current_time])
end
residual = subs(H,[z;t],[corr_znp1;current_time]);
end

View File

@@ -0,0 +1,853 @@
//This file is part of Bertini 2.
//
//euler_test.cpp 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.
//
//euler_test.cpp 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 euler_test.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2021 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 wisconsin eau claire
#include <boost/test/unit_test.hpp>
#include <boost/multiprecision/mpfr.hpp>
#include "bertini2/mpfr_complex.hpp"
#include "bertini2/trackers/ode_predictors.hpp"
extern double threshold_clearance_d;
extern bertini::mpfr_float threshold_clearance_mp;
extern unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS;
BOOST_AUTO_TEST_SUITE(euler_predict_tracking_basics)
using System = bertini::System;
using Variable = bertini::node::Variable;
using Float = bertini::node::Float;
using ExplicitRKPredictor = bertini::tracking::predict::ExplicitRKPredictor;
using Var = std::shared_ptr<Variable>;
using VariableGroup = bertini::VariableGroup;
using dbl = std::complex<double>;
using mpfr = bertini::mpfr_complex;
using mpfr_float = bertini::mpfr_float;
template<typename NumType> using Vec = bertini::Vec<NumType>;
template<typename NumType> using Mat = bertini::Mat<NumType>;
using bertini::DefaultPrecision;
using bertini::Precision;
BOOST_AUTO_TEST_CASE(circle_line_euler_double)
{
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(2.3,0.2), dbl(1.1, 1.87);
// Starting time
dbl current_time(0.9);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double norm_J, norm_J_inverse, size_proportion;
Vec<dbl> predicted(2);
predicted << dbl(2.40310963516214640018253210912048,0.187706567388887830930493342816564),
dbl(0.370984337833979085688209698697074, 1.30889906180158745272421523674049);
Vec<dbl> euler_prediction_result;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(euler_prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(euler_prediction_result.size(),2);
for (unsigned ii = 0; ii < euler_prediction_result.size(); ++ii)
BOOST_CHECK(abs(euler_prediction_result(ii)-predicted(ii)) < threshold_clearance_d);
}
BOOST_AUTO_TEST_CASE(circle_line_euler_mp)
{
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("2.3","0.2"), mpfr("1.1", "1.87");
// Starting time
mpfr current_time("0.9");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double norm_J, norm_J_inverse, size_proportion;
Vec<mpfr> predicted(2);
predicted << mpfr("2.40310963516214640018253210912048","0.187706567388887830930493342816564"),
mpfr("0.370984337833979085688209698697074", "1.30889906180158745272421523674049");
Vec<mpfr> euler_prediction_result;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(euler_prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(euler_prediction_result.size(),2);
for (unsigned ii = 0; ii < euler_prediction_result.size(); ++ii)
BOOST_CHECK(abs(euler_prediction_result(ii)-predicted(ii)) < threshold_clearance_mp);
}
BOOST_AUTO_TEST_CASE(monodromy_euler_d)
{
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(4.641588833612776e-1), dbl(7.416198487095662e-1);
// Starting time
dbl current_time(0.7);
// Time step
dbl delta_t(-0.01);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,3)-1) + (1-t)*(pow(x,3) + 2) );
sys.AddFunction( t*(pow(y,2)-1) + (1-t)*(pow(y,2) + mpfr_float("0.5")) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 2;
Vec<dbl> predicted(2);
predicted << dbl(0.417742995025149735840732480384),
dbl(0.731506850772617663577442383933525);
Vec<dbl> euler_prediction_result;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(euler_prediction_result,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(euler_prediction_result.size(),2);
for (unsigned ii = 0; ii < euler_prediction_result.size(); ++ii)
BOOST_CHECK(abs(euler_prediction_result(ii)-predicted(ii)) < threshold_clearance_d);
}
BOOST_AUTO_TEST_CASE(monodromy_euler_mp)
{
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("0.464158883361277585510862309093"), mpfr("0.74161984870956629487113974408");
// Starting time
mpfr current_time("0.7");
// Time step
mpfr delta_t("-0.01");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,3)-1) + (1-t)*(pow(x,3) + 2) );
sys.AddFunction( t*(pow(y,2)-1) + (1-t)*(pow(y,2) + mpfr_float("0.5")) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 2;
Vec<mpfr> predicted(2);
predicted << mpfr("0.417742995025149735840732480384"),
mpfr("0.731506850772617663577442383934");
Vec<mpfr> euler_prediction_result;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(euler_prediction_result,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(euler_prediction_result.size(),2);
for (unsigned ii = 0; ii < euler_prediction_result.size(); ++ii)
BOOST_CHECK(abs(euler_prediction_result(ii)-predicted(ii)) < threshold_clearance_mp);
}
BOOST_AUTO_TEST_CASE(euler_predict_linear_algebra_fails_d)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(1.0), dbl(-4.0);
// Starting time
dbl current_time(.75+1e-13);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.coefficient_bound = 5;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_cond_num_est = 1;
unsigned freq_of_CN_estimation = 1;
Vec<dbl> prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(prediction_result,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_cond_num_est,
freq_of_CN_estimation,
tracking_tolerance);
BOOST_CHECK(success_code == bertini::SuccessCode::MatrixSolveFailureFirstPartOfPrediction);
}
BOOST_AUTO_TEST_CASE(euler_predict_linear_algebra_fails_mp)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("1.0"), mpfr("-4.0");
// Starting time
mpfr current_time(".7500000000000000000000000001");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
AMP.coefficient_bound = 5;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_cond_num_est = 1;
unsigned freq_of_CN_estimation = 1;
Vec<mpfr> prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(prediction_result,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_cond_num_est,
freq_of_CN_estimation,
tracking_tolerance);
BOOST_CHECK(success_code == bertini::SuccessCode::MatrixSolveFailureFirstPartOfPrediction);
}
BOOST_AUTO_TEST_CASE(euler_predict_linear_criterion_a_is_false_d)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(1.0), dbl(-4.0);
// Starting time
dbl current_time(.8);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_1 = 100;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_cond_num_est = 1;
unsigned freq_of_CN_estimation = 1;
Vec<dbl> prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_cond_num_est,
freq_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(euler_predict_linear_criterion_a_is_false_mp)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("1.0"), mpfr("-4.0");
// Starting time
mpfr current_time(".8");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_1 = 100;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_cond_num_est = 1;
unsigned freq_of_CN_estimation = 1;
Vec<mpfr> prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_cond_num_est,
freq_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(euler_predict_linear_criterion_c_is_false_d)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(1.0), dbl(-4.0);
// Starting time
dbl current_time(.8);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_2 = 100;
AMP.SetPhiPsiFromBounds();
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_cond_num_est = 1;
unsigned freq_of_CN_estimation = 1;
Vec<dbl> prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_cond_num_est,
freq_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(euler_predict_linear_criterion_c_is_false_mp)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("1.0"), mpfr("-4.0");
// Starting time
mpfr current_time(".8");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_2 = 100;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_cond_num_est = 1;
unsigned freq_of_CN_estimation = 1;
Vec<mpfr> prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_cond_num_est,
freq_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(circle_line_euler_change_precision)
{
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("2.3","0.2"), mpfr("1.1", "1.87");
// Starting time
mpfr current_time("0.9");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double norm_J, norm_J_inverse, size_proportion;
Vec<mpfr> predicted(2);
predicted << mpfr("2.40310963516214640018253210912048","0.187706567388887830930493342816564"),
mpfr("0.370984337833979085688209698697074", "1.30889906180158745272421523674049");
Vec<mpfr> euler_prediction_result;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::Euler,sys);
auto success_code = predictor->Predict(euler_prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(euler_prediction_result.size(),2);
for (unsigned ii = 0; ii < euler_prediction_result.size(); ++ii)
BOOST_CHECK(abs(euler_prediction_result(ii)-predicted(ii)) < threshold_clearance_mp);
bertini::DefaultPrecision(50);
Precision(current_space,50); assert(current_space(0).precision()==50);
current_time.precision(50);
delta_t.precision(50);
sys.precision(50);assert(sys.precision()==50);
Precision(predicted,50); assert(predicted(0).precision()==50);
Precision(euler_prediction_result,50); assert(euler_prediction_result(0).precision()==50);
predictor->ChangePrecision(50);
// Starting point in spacetime step
current_space << mpfr("2.3","0.2"), mpfr("1.1", "1.87");
// Starting time
current_time = mpfr("0.9");
// Time step
delta_t = mpfr("-0.1");
AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
predicted << mpfr("2.4031096351621464001825321091204810500227008230702","0.18770656738888783093049334281656388282191769240875"),
mpfr("0.37098433783397908568820969869707413571104273956141", "1.3088990618015874527242152367404908738825831867988");
success_code = predictor->Predict(euler_prediction_result,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(euler_prediction_result.size(),2);
for (unsigned ii = 0; ii < euler_prediction_result.size(); ++ii)
{
BOOST_CHECK(abs(euler_prediction_result(ii)-predicted(ii)) < 1e-47);
}
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,168 @@
//This file is part of Bertini 2.
//
//fixed_precision_tracker_test.cpp 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.
//
//fixed_precision_tracker_test.cpp 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 fixed_precision_tracker_test.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2021 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 wisconsin eau claire
#include <boost/test/unit_test.hpp>
#include "bertini2/system/start_systems.hpp"
#include "bertini2/trackers/fixed_precision_tracker.hpp"
#include "bertini2/trackers/observers.hpp"
extern double threshold_clearance_d;
extern bertini::mpfr_float threshold_clearance_mp;
extern unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS;
BOOST_AUTO_TEST_SUITE(fixed_precision_tracker_basics)
using System = bertini::System;
using Variable = bertini::node::Variable;
using Var = std::shared_ptr<Variable>;
using VariableGroup = bertini::VariableGroup;
using dbl = std::complex<double>;
using mpfr = bertini::mpfr_complex;
using mpfr_float = bertini::mpfr_float;
template<typename NumType> using Vec = bertini::Vec<NumType>;
template<typename NumType> using Mat = bertini::Mat<NumType>;
using bertini::DefaultPrecision;
BOOST_AUTO_TEST_CASE(double_tracker_track_linear)
{
using bertini::operator<<;
DefaultPrecision(100);
using namespace bertini::tracking;
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{y};
sys.AddFunction(y-t);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
bertini::tracking::DoublePrecisionTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
double(1e-5),
double(1e5),
stepping_preferences,
newton_preferences);
dbl t_start(1);
dbl t_end(0);
Vec<dbl> y_start(1);
y_start << dbl(1);
Vec<dbl> y_end;
auto obs = GoryDetailLogger<DoublePrecisionTracker>();
tracker.AddObserver(obs);
auto code = tracker.TrackPath(y_end, t_start, t_end, y_start);
BOOST_CHECK(code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(y_end.size(),1);
BOOST_CHECK(abs(y_end(0)-dbl(0)) < 1e-5);
}
BOOST_AUTO_TEST_CASE(multiple_100_tracker_track_linear)
{
DefaultPrecision(100);
using namespace bertini::tracking;
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{y};
sys.AddFunction(y-t);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
bertini::tracking::MultiplePrecisionTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
GoryDetailLogger<MultiplePrecisionTracker> tons_of_detail;
tracker.AddObserver(tons_of_detail);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> y_start(1);
y_start << mpfr(1);
Vec<mpfr> y_end;
tracker.TrackPath(y_end,
t_start, t_end, y_start);
BOOST_CHECK_EQUAL(y_end.size(),1);
BOOST_CHECK(abs(y_end(0)-mpfr(0)) < 1e-5);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,789 @@
//This file is part of Bertini 2.0.
//
//heun_test.cpp 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.
//
//heun_test.cpp 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 heun_test.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Heun_test.cpp
//
// copyright 2016
// James B. Collins
// West Texas A&M University
// Department of Mathematics
// Spring 2016
#include <boost/test/unit_test.hpp>
#include <boost/multiprecision/mpfr.hpp>
#include "bertini2/mpfr_complex.hpp"
#include "bertini2/trackers/ode_predictors.hpp"
extern double threshold_clearance_d;
extern bertini::mpfr_float threshold_clearance_mp;
extern unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS;
BOOST_AUTO_TEST_SUITE(heun_predict_tracking_basics)
using System = bertini::System;
using Variable = bertini::node::Variable;
using Float = bertini::node::Float;
using ExplicitRKPredictor = bertini::tracking::predict::ExplicitRKPredictor;
using Var = std::shared_ptr<Variable>;
using VariableGroup = bertini::VariableGroup;
using dbl = std::complex<double>;
using mpfr = bertini::mpfr_complex;
using mpfr_float = bertini::mpfr_float;
template<typename NumType> using Vec = bertini::Vec<NumType>;
template<typename NumType> using Mat = bertini::Mat<NumType>;
BOOST_AUTO_TEST_CASE(circle_line_heun_double)
{
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(2.3,0.2), dbl(1.1, 1.87);
// Starting time
dbl current_time(0.9);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double norm_J, norm_J_inverse, size_proportion, error_est;
Vec<dbl> predicted(2);
predicted << dbl(2.38948874619536140814029774733947,0.208678935223681033727262214382917),
dbl(0.524558056401030798191044945035673, 1.43029356995029310361616395235936);
double predicted_error = .197349645229023708608160063982175;
Vec<dbl> heun_prediction_result;
dbl next_time;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(heun_prediction_result.size(),2);
for (unsigned ii = 0; ii < heun_prediction_result.size(); ++ii)
{
BOOST_CHECK(abs(heun_prediction_result(ii)-predicted(ii)) < threshold_clearance_d);
}
BOOST_CHECK(fabs(error_est / predicted_error - 1) < threshold_clearance_d);
}
BOOST_AUTO_TEST_CASE(circle_line_heun_mp)
{
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("2.3","0.2"), mpfr("1.1", "1.87");
// Starting time
mpfr current_time("0.9");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double norm_J, norm_J_inverse, size_proportion, error_est;
Vec<mpfr> predicted(2);
predicted << mpfr("2.38948874619536140814029774733947","0.208678935223681033727262214382917"),
mpfr("0.524558056401030798191044945035673", "1.43029356995029310361616395235936");
double predicted_error = double(.197349645229023708608160063982175);
Vec<mpfr> heun_prediction_result;
mpfr next_time;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(heun_prediction_result.size(),2);
for (unsigned ii = 0; ii < heun_prediction_result.size(); ++ii)
BOOST_CHECK(abs(heun_prediction_result(ii)-predicted(ii)) < threshold_clearance_mp);
using std::abs;
BOOST_CHECK(abs(error_est - predicted_error) < std::numeric_limits<double>::epsilon());
}
BOOST_AUTO_TEST_CASE(monodromy_heun_d)
{
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(0.464158883361277585510862309093), dbl(0.74161984870956629487113974408);
// Starting time
dbl current_time(0.7);
// Time step
dbl delta_t(-0.01);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
std::shared_ptr<Float> half = Float::Make("0.5");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,3)-1) + (1-t)*(pow(x,3) + 2) );
sys.AddFunction( t*(pow(y,2)-1) + (1-t)*(pow(y,2) + half) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 2;
Vec<dbl> predicted(2);
predicted << dbl(0.412299156269677938503694812160886),
dbl(0.731436945256924470273568899877140);
double predicted_error = 0.00544428757292458409463632380167773;
Vec<dbl> heun_prediction_result;
double next_time;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(heun_prediction_result.size(),2);
for (unsigned ii = 0; ii < heun_prediction_result.size(); ++ii)
{
BOOST_CHECK(abs(heun_prediction_result(ii)-predicted(ii)) < threshold_clearance_d);
}
BOOST_CHECK(fabs(error_est / predicted_error - 1) < threshold_clearance_d);
}
BOOST_AUTO_TEST_CASE(monodromy_heun_mp)
{
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("0.464158883361277585510862309093"), mpfr("0.74161984870956629487113974408");
// Starting time
mpfr current_time("0.7");
// Time step
mpfr delta_t("-0.01");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
std::shared_ptr<Float> half = Float::Make("0.5");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,3)-1) + (1-t)*(pow(x,3) + 2) );
sys.AddFunction( t*(pow(y,2)-1) + (1-t)*(pow(y,2) + half) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 2;
double norm_J, norm_J_inverse, size_proportion, error_est;
Vec<mpfr> predicted(2);
predicted << mpfr("0.412299156269677938503694812160886"),
mpfr("0.731436945256924470273568899877140");
double predicted_error = double(0.00544428757292458409463632380167773);
Vec<mpfr> heun_prediction_result;
mpfr next_time;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(heun_prediction_result.size(),2);
for (unsigned ii = 0; ii < heun_prediction_result.size(); ++ii)
{
BOOST_CHECK(abs(heun_prediction_result(ii)-predicted(ii)) < threshold_clearance_mp);
}
using std::abs;
BOOST_CHECK(abs(error_est / predicted_error - 1) < std::numeric_limits<double>::epsilon());
}
BOOST_AUTO_TEST_CASE(heun_predict_linear_algebra_fails_d)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(1.0), dbl(-4.0);
// Starting time
dbl current_time(.75);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
Vec<dbl> heun_prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::MatrixSolveFailureFirstPartOfPrediction);
}
BOOST_AUTO_TEST_CASE(heun_predict_linear_algebra_fails_mp)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("1.0"), mpfr("-4.0");
// Starting time
mpfr current_time(".7500000000000000000000000001");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_cond_num_est = 1;
unsigned freq_of_CN_estimation = 1;
Vec<mpfr> heun_prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_cond_num_est,
freq_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::MatrixSolveFailureFirstPartOfPrediction);
}
BOOST_AUTO_TEST_CASE(heun_predict_linear_criterion_a_is_false_d)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(1.0), dbl(-4.0);
// Starting time
dbl current_time(.8);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_1 = 100;
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
Vec<dbl> heun_prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(heun_predict_linear_criterion_a_is_false_mp)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("1.0"), mpfr("-4.0");
// Starting time
mpfr current_time(".8");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_1 = 100;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
Vec<mpfr> heun_prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(heun_predict_linear_criterion_c_is_false_d)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(1.0), dbl(-4.0);
// Starting time
dbl current_time(.8);
// Time step
dbl delta_t(-0.1);
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_2 = 100;
AMP.SetPhiPsiFromBounds();
double tracking_tolerance(1e-5);
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
Vec<dbl> heun_prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(heun_predict_linear_criterion_c_is_false_mp)
{
// Circle line homotopy has singular point at (x,y) = (1,-4) and t = .75
bertini::DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("1.0"), mpfr("-4.0");
// Starting time
mpfr current_time(".8");
// Time step
mpfr delta_t("-0.1");
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x - 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
double norm_J, norm_J_inverse, size_proportion, error_est;
AMP.coefficient_bound = 5;
AMP.safety_digits_2 = 100;
double tracking_tolerance = 1e-5;
double condition_number_estimate;
unsigned num_steps_since_last_condition_number_computation = 1;
unsigned frequency_of_CN_estimation = 1;
Vec<mpfr> heun_prediction_result;
std::shared_ptr<ExplicitRKPredictor> predictor = std::make_shared< ExplicitRKPredictor >(bertini::tracking::Predictor::HeunEuler,sys);
auto success_code = predictor->Predict(heun_prediction_result,
error_est,
size_proportion,
norm_J, norm_J_inverse,
sys,
current_space, current_time,
delta_t,
condition_number_estimate,
num_steps_since_last_condition_number_computation,
frequency_of_CN_estimation,
tracking_tolerance,
AMP);
BOOST_CHECK(success_code == bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_SUITE_END()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,795 @@
//This file is part of Bertini 2.
//
//newton_correct_test.cpp 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.
//
//newton_correct_test.cpp 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 newton_correct_test.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2021 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 wisconsin eau claire
#include <boost/test/unit_test.hpp>
#include <boost/multiprecision/mpfr.hpp>
#include "bertini2/mpfr_complex.hpp"
#include "bertini2/trackers/newton_corrector.hpp"
extern double threshold_clearance_d;
extern bertini::mpfr_float threshold_clearance_mp;
extern unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS;
BOOST_AUTO_TEST_SUITE(newton_correct_tracking_basics)
using System = bertini::System;
using Variable = bertini::node::Variable;
using Var = std::shared_ptr<Variable>;
using VariableGroup = bertini::VariableGroup;
using NewtonCorrector = bertini::tracking::correct::NewtonCorrector;
using dbl = std::complex<double>;
using mpfr = bertini::mpfr_complex;
using mpfr_float = bertini::mpfr_float;
using mpq_rational = bertini::mpq_rational;
template<typename NumType> using Vec = bertini::Vec<NumType>;
template<typename NumType> using Mat = bertini::Mat<NumType>;
using bertini::DefaultPrecision;
BOOST_AUTO_TEST_CASE(circle_line_one_corrector_step_double)
{
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(2.3,0.2), dbl(1.1, 1.87);
// Starting time
dbl current_time(0.9);
// Time step
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1.0) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double tracking_tolerance(1e-5);
Vec<dbl> corrected(2);
corrected << dbl(1.36296628875178620892887063382866,0.135404746200380445814213878747082),
dbl(0.448147673035459113010161338024478, -0.0193435351714829208306019826781546);
Vec<dbl> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
for (unsigned ii = 0; ii < newton_correction_result.size(); ++ii)
BOOST_CHECK(abs(newton_correction_result(ii)-corrected(ii)) < threshold_clearance_d);
}
BOOST_AUTO_TEST_CASE(circle_line_one_corrector_step_mp)
{
DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("2.3","0.2"), mpfr("1.1", "1.87");
// Starting time
mpfr current_time("0.9");
// Time step
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double tracking_tolerance = 1e-5;
Vec<mpfr> corrected(2);
corrected << mpfr("1.36296628875178620892887063382866","0.135404746200380445814213878747082"),
mpfr("0.448147673035459113010161338024478", "-0.0193435351714829208306019826781546");
Vec<mpfr> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
for (unsigned ii = 0; ii < newton_correction_result.size(); ++ii)
BOOST_CHECK(abs(newton_correction_result(ii)-corrected(ii)) < threshold_clearance_mp);
}
BOOST_AUTO_TEST_CASE(circle_line_two_corrector_steps_double)
{
// Starting point in spacetime step
Vec<dbl> current_space(2);
current_space << dbl(2.3,0.2), dbl(1.1, 1.87);
// Starting time
dbl current_time(0.9);
// Time step
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double tracking_tolerance(1e-5);
Vec<dbl> corrected(2);
corrected << dbl(1.14542104415948767661671388923986, 0.0217584797792294631577151109622764),
dbl(0.47922556512007318905475515868002, -0.00310835425417563759395930156603948);
Vec<dbl> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 2;
unsigned min_num_newton_iterations = 2;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
for (unsigned ii = 0; ii < newton_correction_result.size(); ++ii)
{
BOOST_CHECK(abs(newton_correction_result(ii)-corrected(ii)) < threshold_clearance_d);
}
}
BOOST_AUTO_TEST_CASE(circle_line_two_corrector_steps_mp)
{
DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
// Starting point in spacetime step
Vec<mpfr> current_space(2);
current_space << mpfr("2.3","0.2"), mpfr("1.1", "1.87");
// Starting time
mpfr current_time("0.9");
// Time step
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
// Define homotopy system
sys.AddFunction( t*(pow(x,2)-1) + (1-t)*(pow(x,2) + pow(y,2) - 4) );
sys.AddFunction( t*(y-1) + (1-t)*(2*x + 5*y) );
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,2);
AMP.coefficient_bound = 5;
double tracking_tolerance = 1e-5;
Vec<mpfr> corrected(2);
corrected << mpfr("1.14542104415948767661671388923986", "0.0217584797792294631577151109622764"),
mpfr("0.47922556512007318905475515868002", "-0.00310835425417563759395930156603948");
Vec<mpfr> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 2;
unsigned min_num_newton_iterations = 2;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK(success_code==bertini::SuccessCode::Success);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
for (unsigned ii = 0; ii < newton_correction_result.size(); ++ii)
BOOST_CHECK(abs(newton_correction_result(ii)-corrected(ii)) < threshold_clearance_mp);
}
BOOST_AUTO_TEST_CASE(newton_step_amp_criterion_B_violated_double)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Have trimmed current_space to have 16 digits after decimal point. Also, saftey_digits_1 has been set to 32000
to set off the AMPCriterionB condition.
*/
Vec<dbl> current_space(2);
current_space << dbl(25.4088532364492429,-38.0519122331723744),
dbl(-0.0212298348984663,-0.1778146465316983);
dbl current_time(0);
dbl delta_t(.1);
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 5;
AMP.safety_digits_1 = 32000;
Vec<dbl> newton_correction_result;
double tracking_tolerance = double(10);
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(newton_step_amp_criterion_B_violated_mp)
{
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_1 has been set to 32000 to set off the AMPCriterionB condition.
*/
Vec<mpfr> current_space(2);
current_space << mpfr("25.408853236449242927412","-38.051912233172374487976"),
mpfr("-0.0212298348984663761753389403711889","-0.177814646531698303094367623155171");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 5;
AMP.safety_digits_1 = 32000;
double tracking_tolerance = 1e-5;
Vec<mpfr> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(newton_step_amp_criterion_C_violated_double)
{
DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Have trimmed current_space to have 16 digits after decimal point. Also, saftey_digits_2 has been set to 32000
to set off the AMPCriterionC condition.
*/
Vec<mpfr> current_space(2);
current_space << mpfr("256185069753.4088532364492429","-387520022558.0519122331723744"),
mpfr("-0.0212298348984663","-0.1778146465316983");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 5;
AMP.safety_digits_2 = 32000;
double tracking_tolerance = 1e-5;
Vec<mpfr> corrected(2);
corrected << mpfr("3701884101067.778","-5599679215240.413"),
mpfr("-1.043206463433583e25","-2.450083921191992e25");
Vec<mpfr> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(newton_step_amp_criterion_C_violated_mp)
{
DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
Also, saftey_digits_2 has been set to 32000 to set off the AMPCriterionC condition.
*/
Vec<mpfr> current_space(2);
current_space << mpfr("256185069753.408853236449242927412","-387520022558.051912233172374487976"),
mpfr("-0.0212298348984663761753389403711889","-0.177814646531698303094367623155171");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,3);
AMP.coefficient_bound = 5;
AMP.safety_digits_2 = 32000;
double tracking_tolerance = 1e-5;
Vec<mpfr> corrected(2);
corrected << mpfr("3701884101067.778","-5599679215240.413"),
mpfr("-1.043206463433583e25","-2.450083921191992e25");
Vec<mpfr> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::HigherPrecisionNecessary);
}
BOOST_AUTO_TEST_CASE(newton_step_linear_algebra_fails_double)
{
/*Test case checking to make sure a polynomial system that is 0 will fail when the newton correction step is done.
This test case differs from above as it has the precision type set to double.
*/
Vec<mpfr> current_space(2);
current_space << mpfr("0","0"),mpfr("0","0");
mpfr current_time("1");
mpfr delta_t("-.1");
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpfr("0","0")*x);
sys.AddFunction(mpfr("0","0")*y);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,1);
AMP.coefficient_bound = 5;
double tracking_tolerance = 1e-5;
Vec<mpfr> corrected(2);
corrected << mpfr("0","0"),mpfr("0","0");
Vec<mpfr> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::MatrixSolveFailure);
}
BOOST_AUTO_TEST_CASE(newton_step_linear_algebra_fails_mp)
{
/*Test case checking to make sure a polynomial system that is 0 will fail when the newton correction step is done.
This test case differs from above as it has the precision type set to adaptive.
*/
Vec<mpfr> current_space(2);
current_space << mpfr("0","0"),mpfr("0","0");
mpfr current_time("1");
mpfr delta_t("-.1");
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpfr("0","0")*x);
sys.AddFunction(mpfr("0","0")*y);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
BOOST_CHECK_EQUAL(AMP.degree_bound,1);
AMP.coefficient_bound = 5;
double tracking_tolerance = 1e-5;
Vec<mpfr> corrected(2);
corrected << mpfr("0","0"),mpfr("0","0");
Vec<mpfr> newton_correction_result;
tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations,
AMP);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::MatrixSolveFailure);
}
BOOST_AUTO_TEST_CASE(newton_step_diverging_to_infinity_fails_to_converge_d)
{
DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence.
*/
Vec<mpfr> current_space(2);
current_space << mpfr("256185069753.408853236449242927412","-387520022558.051912233172374487976"),
mpfr("-0.0212298348984663761753389403711889","-0.177814646531698303094367623155171");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
Vec<mpfr> corrected(2);
corrected << mpfr("3701884101067.778","-5599679215240.413"),
mpfr("-1.043206463433583e25","-2.450083921191992e25");
double tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
Vec<mpfr> newton_correction_result;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::FailedToConverge);
}
BOOST_AUTO_TEST_CASE(newton_step_diverging_to_infinity_fails_to_converge_mp)
{
DefaultPrecision(TRACKING_TEST_MPFR_DEFAULT_DIGITS);
/*
Using the Griewank Osborne example. Starting at t = 0 where there is a multiplicity 3 isolated solution. We predict
to .1 and try to correct back down. Anywhere except at t = 0, we will have divergence. The difference from this
and the above version is we will use PrecisionType = Adaptive.
*/
Vec<mpfr> current_space(2);
current_space << mpfr("256185069753.408853236449242927412","-387520022558.051912233172374487976"),
mpfr("-0.0212298348984663761753389403711889","-0.177814646531698303094367623155171");
mpfr current_time("0");
mpfr delta_t(".1");
current_time += delta_t;
bertini::System sys;
Var x = Variable::Make("x"), y = Variable::Make("y"), t = Variable::Make("t");
VariableGroup vars{x,y};
sys.AddVariableGroup(vars);
sys.AddPathVariable(t);
sys.AddFunction(mpq_rational(29,16)*pow(x,3) - 2*x*y + t);
sys.AddFunction(y - pow(x,2));
Vec<mpfr> corrected(2);
corrected << mpfr("3701884101067.778","-5599679215240.413"),
mpfr("-1.043206463433583e25","-2.450083921191992e25");
Vec<mpfr> newton_correction_result;
double tracking_tolerance = 1e1;
unsigned max_num_newton_iterations = 1;
unsigned min_num_newton_iterations = 1;
std::shared_ptr<NewtonCorrector> corrector = std::make_shared<NewtonCorrector>(sys);
auto success_code = corrector->Correct(newton_correction_result,
sys,
current_space,
current_time,
tracking_tolerance,
min_num_newton_iterations,
max_num_newton_iterations);
BOOST_CHECK_EQUAL(newton_correction_result.size(),2);
BOOST_CHECK(success_code==bertini::SuccessCode::FailedToConverge);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,236 @@
//This file is part of Bertini 2.
//
//path_observers.cpp 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.
//
//path_observers.cpp 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 path_observers.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2021 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 wisconsin eau claire
#include <boost/test/unit_test.hpp>
#include "bertini2/trackers/amp_tracker.hpp"
#include "bertini2/trackers/observers.hpp"
extern double threshold_clearance_d;
extern bertini::mpfr_float threshold_clearance_mp;
extern unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS;
BOOST_AUTO_TEST_SUITE(AMP_tracker_basics)
using System = bertini::System;
using Variable = bertini::node::Variable;
using Var = std::shared_ptr<Variable>;
using VariableGroup = bertini::VariableGroup;
using dbl = std::complex<double>;
using mpfr = bertini::mpfr_complex;
using mpfr_float = bertini::mpfr_float;
template<typename NumType> using Vec = bertini::Vec<NumType>;
template<typename NumType> using Mat = bertini::Mat<NumType>;
using bertini::DefaultPrecision;
BOOST_AUTO_TEST_CASE(accumulate_single_path_square_root)
{
DefaultPrecision(16);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(x-t);
sys.AddFunction(pow(y,2)-x);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
AMPPathAccumulator<AMPTracker> path_accumulator;
PrecisionAccumulator<AMPTracker> precision_accumulator;
tracker.AddObserver(path_accumulator);
tracker.AddObserver(precision_accumulator);
start_point << mpfr(1), mpfr(1);
bertini::SuccessCode tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
}
BOOST_AUTO_TEST_CASE(some_other_thing_square_root)
{
DefaultPrecision(16);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(x-t);
sys.AddFunction(pow(y,2)-x);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
Vec<mpfr> end_point;
bertini::SuccessCode tracking_success;
GoryDetailLogger<AMPTracker> tons_of_detail;
tracker.AddObserver(tons_of_detail);
start_point << mpfr(1), mpfr(1);
tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
}
BOOST_AUTO_TEST_CASE(union_of_observers)
{
DefaultPrecision(16);
using namespace bertini::tracking;
Var x = Variable::Make("x");
Var y = Variable::Make("y");
Var t = Variable::Make("t");
System sys;
VariableGroup v{x,y};
sys.AddFunction(x-t);
sys.AddFunction(pow(y,2)-x);
sys.AddPathVariable(t);
sys.AddVariableGroup(v);
auto AMP = bertini::tracking::AMPConfigFrom(sys);
bertini::tracking::AMPTracker tracker(sys);
SteppingConfig stepping_preferences;
NewtonConfig newton_preferences;
tracker.Setup(Predictor::Euler,
1e-5,
1e5,
stepping_preferences,
newton_preferences);
tracker.PrecisionSetup(AMP);
mpfr t_start(1);
mpfr t_end(0);
Vec<mpfr> start_point(2);
start_point << mpfr(1), mpfr(1);
Vec<mpfr> end_point;
bertini::MultiObserver<AMPTracker, GoryDetailLogger> agglomeration;
tracker.AddObserver(agglomeration);
bertini::SuccessCode tracking_success = tracker.TrackPath(end_point,
t_start, t_end, start_point);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,140 @@
//This file is part of Bertini 2.
//
//predictor_test.m 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.
//
//predictor_test.m 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 predictor_test.m. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2017 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:
// jeb collins, west texas a&m
// silviana amethyst, university of wisconsin eau claire
function predictor_test()
%% Test parameters
digits(30); %Precision used
%% Homotopy system
% Circle cuts Line example
% zn = vpa([2.3 + i*.2; 1.1 + i*1.87]); % Point in space at time t=t_n
% tn = 0.9; dt = -.1; tnp1 = tn + dt; %Starting time t_n, and time step dt
%
% num_vars = 2; % number of variables
% z = sym('z',[num_vars,1]);
% syms t
%
% %%%%%%%%%%%%%%%%%%%% polynomials that make up the homotopy%%%%%%%%%%%%%%%%%%%
%
% H(1) = t*(z(1)^3-1) + (1-t)*(z(1)^3+2);
% H(2) = t*(z(2)^2-1) + (1-t)*(z(2)^2+.5);
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Monodromy Example
zn = vpa([4.641588833612776e-1; 7.416198487095662e-1]); % Point in space at time t=t_n
tn = 0.7; dt = -.01; tnp1 = tn + dt; %Starting time t_n, and time step dt
num_vars = 2; % number of variables
z = sym('z',[num_vars,1]);
syms t
%%%%%%%%%%%%%%%%%%%% polynomials that make up the homotopy%%%%%%%%%%%%%%%%%%%
H(1) = t*(z(1)^3-1) + (1-t)*(z(1)^3+2);
H(2) = t*(z(2)^2-1) + (1-t)*(z(2)^2+.5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\frac{dH}{dt}
dHt = diff(H,t);
% Jacobian of H(z,t) w.r.t z
for ii = 1:num_vars
for jj = 1:num_vars
JH(ii,jj) = diff(H(ii),z(jj));
end
end
% Inverse of the Jacobian
JHinv = inv(JH);
%\frac{dH}{dt}(z_n, t_n)
z
zn
dHtn = vpa(subs(dHt,[z], [zn])).';
% Inverse of Jacobian at (zn,tn)
JHinvn = vpa(subs(JHinv, [z;t], [zn;tn]));
%% Predictor Corrector step
% pred_znp1 = the prediction step approximation of z_{n+1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -1 = Constant(no predictor)
% 0 = Forward Euler
% 1 = Heun
% 2 = RK4
% 3 = Heun Prediction with 1st order Euler for error estimation
% 4 = Runge-Kutta-Norsett
% 5 = RK fehlburg
% 6 = RK-Cash-Karp
% 7 = RK-Dormand-Prince
% 8 = RK-Verner
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ODEPredictor = 0;
switch(ODEPredictor)
case 0
% Forward Euler
pred_znp1 = zn - dt*JHinvn*dHtn;
end
display(pred_znp1);
end

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
//This file is part of Bertini 2.
//
//tracking_basics_test.cpp 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.
//
//tracking_basics_test.cpp 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 tracking_basics_test.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2021 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 wisconsin eau claire
#define BOOST_TEST_DYN_LINK
//this #define MUST appear before #include <boost/test/unit_test.hpp>
#define BOOST_TEST_MODULE "Bertini 2 Tracking Basics Testing"
#include <boost/test/unit_test.hpp>
#include "bertini2/mpfr_extensions.hpp"
#define BERTINI_TEST_MODULE "tracking_basics"
#include "test/utility/enable_logging.hpp"
double threshold_clearance_d(1e-15);
bertini::mpfr_float threshold_clearance_mp("1e-28");
unsigned TRACKING_TEST_MPFR_DEFAULT_DIGITS(30);
// deliberately left blank. link other files with this one.