9#ifndef BERTINI_NEWTON_CORRECTOR_HPP
10#define BERTINI_NEWTON_CORRECTOR_HPP
71 newton_config_ = newton_settings;
92 auto& probe = std::get< Vec<complex_mp> >(rand_temp_);
93 probe = probe_as_drawn_;
97 std::get< linalg::PartialPivLU<complex_mp> >(LU_).
ChangePrecision(new_precision);
99 current_precision_ = new_precision;
106 return current_precision_;
118 numVariables_ =
static_cast<unsigned>(S.
NumVariables());
119 std::get< Mat<complex_dbl> >(J_temp_).resize(numTotalFunctions_, numVariables_);
120 std::get< Mat<complex_mp> >(J_temp_).resize(numTotalFunctions_, numVariables_);
121 std::get< Vec<complex_dbl> >(f_temp_).resize(numTotalFunctions_);
122 std::get< Vec<complex_mp> >(f_temp_).resize(numTotalFunctions_);
123 std::get< Vec<complex_dbl> >(step_temp_).resize(numTotalFunctions_);
124 std::get< Vec<complex_mp> >(step_temp_).resize(numTotalFunctions_);
125 std::get< Vec<complex_dbl> >(solve_temp_).resize(numVariables_);
126 std::get< Vec<complex_mp> >(solve_temp_).resize(numVariables_);
127 std::get< linalg::PartialPivLU<complex_dbl> >(LU_).ChangeSize(numVariables_);
128 std::get< linalg::PartialPivLU<complex_mp> >(LU_).ChangeSize(numVariables_);
147 std::get< Vec<complex_mp> >(rand_temp_) = probe_as_drawn_;
159 return { std::get< Vec<complex_dbl> >(rand_temp_), probe_as_drawn_ };
186 template <
typename ComplexT>
191 ComplexT
const& current_time,
193 unsigned min_num_newton_iterations,
194 unsigned max_num_newton_iterations,
197 #ifndef BERTINI_DISABLE_ASSERTS
198 assert(max_num_newton_iterations >= min_num_newton_iterations &&
"max number newton iterations must be at least the min.");
201 Vec<ComplexT>& step_ref = std::get< Vec<ComplexT> >(step_temp_);
203 next_space = current_space;
204 for (
unsigned ii = 0; ii < max_num_newton_iterations; ++ii)
207 auto success_code = EvalIterationStep(step_ref, S, next_space, current_time);
211 next_space -= step_ref;
214 if (AMP_config ==
nullptr)
216 if ( (step_ref.template lpNorm<Eigen::Infinity>() < tracking_tolerance) && (ii >= (min_num_newton_iterations-1)) )
222 Mat<ComplexT>& J_temp_ref = std::get< Mat<ComplexT> >(J_temp_);
233 Vec<ComplexT>& rand_ref = std::get< Vec<ComplexT> >(rand_temp_);
234 Vec<ComplexT>& solve_ref = std::get< Vec<ComplexT> >(solve_temp_);
235 LU_ref.Solve(rand_ref, solve_ref);
240 if ( (meta.
norm_delta_z < tracking_tolerance) && (ii >= (min_num_newton_iterations-1)) )
273 template<
typename ComplexT,
typename Derived>
276 const Eigen::MatrixBase<Derived>& current_space,
const ComplexT& current_time)
278 Vec<ComplexT>& f_temp_ref = std::get< Vec<ComplexT> >(f_temp_);
279 Mat<ComplexT>& J_temp_ref = std::get< Mat<ComplexT> >(J_temp_);
283 S.
SetAndReset<ComplexT>(current_space, current_time);
295 LU_ref.Solve(f_temp_ref, newton_step);
309 unsigned numTotalFunctions_;
310 unsigned numVariables_;
321 unsigned current_precision_;
Provides the Adaptive Multiple Precision criteria functions.
The fundamental polynomial system class for Bertini2.
Definition system.hpp:106
void SetAndReset(Vec< T > const &new_space, T const &new_time) const
Stage the system's current point (variables and path value) for a subsequent Eval/Jacobian.
Definition system.hpp:964
void EvalInPlace(Vec< T > &function_values) const
Evaluate the system using the previously set variable (and time) values, in place.
Definition system.hpp:213
void JacobianInPlace(Mat< T > &J) const
Evaluate the Jacobian matrix of the system, using the previous space and time values,...
Definition system.hpp:413
size_t NumVariables() const
Get the total number of variables in this system, including homogenizing variables.
size_t NumTotalFunctions() const
Get the total number of functions, including patches.
Stateful partial-pivot LU factor/solve with preallocated, precision-adjustable banks.
Definition lu_solver.hpp:58
std::tuple< Vec< complex_dbl >, Vec< complex_mp > > ConditionProbe() const
The condition-number probe direction as drawn (both precisions), so the tracker can share the SAME pe...
Definition newton_corrector.hpp:157
void RefreshRandomDirection()
(Re)draw the random probe direction used to estimate ||J^{-1}|| (the condition number) from this thre...
Definition newton_corrector.hpp:143
void Settings(const NewtonConfig &newton_settings)
Sets the Newton configuration settings.
Definition newton_corrector.hpp:69
void ChangeSystem(const System &S)
Change the system(number of total functions) that the predictor uses.
Definition newton_corrector.hpp:115
NewtonCorrector(const System &S)
Construct a Newton corrector for a system, at the current default precision.
Definition newton_corrector.hpp:51
unsigned precision() const
Get the corrector's current working precision.
Definition newton_corrector.hpp:104
void ChangePrecision(unsigned new_precision)
Change the precision of the predictor variables and reassign the Butcher table variables.
Definition newton_corrector.hpp:84
SuccessCode Correct(Vec< ComplexT > &next_space, StepMetadata &meta, System const &S, Vec< ComplexT > const ¤t_space, ComplexT const ¤t_time, NumErrorT const &tracking_tolerance, unsigned min_num_newton_iterations, unsigned max_num_newton_iterations, AdaptiveMultiplePrecisionConfig const *AMP_config=nullptr)
Run Newton's method, optionally with adaptive multiple precision.
Definition newton_corrector.hpp:187
A stateful partial-pivot LU solver that owns precision-adjustable temporary banks.
bool CriterionB(double const &norm_J, double const &norm_J_inverse, unsigned num_newton_iterations_remaining, NumErrorT const &tracking_tolerance, double const &norm_of_latest_newton_residual, AdaptiveMultiplePrecisionConfig const &_config)
Check AMP Criterion B.
Definition amp_criteria.hpp:128
bool CriterionC(double const &norm_J_inverse, const Eigen::MatrixBase< Derived > &z, NumErrorT tracking_tolerance, AdaptiveMultiplePrecisionConfig const &_config)
Check AMP Criterion C.
Definition amp_criteria.hpp:202
Definition newton_corrector.hpp:20
Definition adaptive_precision_utilities.hpp:35
Definition algorithm_builder.hpp:36
@ Success
The decomposition looks healthy.
Definition eigen_extensions.hpp:465
Eigen::Matrix< NumT, Eigen::Dynamic, 1 > Vec
A dynamically-sized column vector of NumT.
Definition eigen_extensions.hpp:296
Mat< NumberType > RandomOfUnits(unsigned int rows, unsigned int cols)
Make a random matrix of units (numbers with norm 1).
Definition eigen_extensions.hpp:565
Eigen::Matrix< NumT, Eigen::Dynamic, Eigen::Dynamic > Mat
A dynamically-sized matrix of NumT.
Definition eigen_extensions.hpp:298
double NumErrorT
The numeric type used to hold error/tolerance magnitudes throughout Bertini2 – tracking tolerances,...
Definition num_traits.hpp:48
auto DefaultPrecision()
Get the global default precision (digits) for multiprecision numbers.
Definition mpfr_complex.hpp:135
SuccessCode
Definition config.hpp:42
@ FailedToConverge
Definition config.hpp:55
@ Success
Definition config.hpp:51
@ MatrixSolveFailure
Definition config.hpp:56
@ HigherPrecisionNecessary
Definition config.hpp:52
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object.
Definition eigen_extensions.hpp:339
Holds the program parameters with respect to Adaptive Multiple Precision.
Definition config.hpp:214
Settings governing the Newton corrector's iteration bounds.
Definition config.hpp:119
Provides the bertini::System class.
Configs and settings for tracking.