163template<
typename PrecT>
165 public virtual EndgameBase<PowerSeriesEndgame<PrecT>, PrecT>
234 template<
typename ComplexT>
238 const auto num_sample_points = this->
EndgameSettings().num_sample_points;
245 template<
typename ComplexT>
249 const auto num_sample_points = this->
EndgameSettings().num_sample_points;
265 template<
typename ComplexT>
268 std::get<TimeCont<ComplexT> >(
times_).clear();
269 std::get<SampCont<ComplexT> >(
samples_).clear();
271 std::get<TimeCont<ComplexT> >(
c_over_k_).clear();
278 template<
typename ComplexT>
284 template<
typename ComplexT>
311 template<
typename ComplexT>
317 template<
typename ComplexT>
323 template<
typename ComplexT>
328 for (
int ii = 0; ii < size; ++ii)
343 template<
typename... Ts >
362 template<
typename ComplexT>
365 using RealT =
typename Eigen::NumTraits<ComplexT>::Real;
366 using std::log;
using std::abs;
368 const auto& samples = std::get<SampCont<ComplexT> >(
samples_);
372 auto num_samples = samples.size();
379 const auto& rand_vector = std::get<Vec<ComplexT> >(
rand_vector_);
380 ComplexT rand_sum1 = ((sample1 - sample0).transpose()*rand_vector).sum();
381 ComplexT rand_sum2 = ((sample2 - sample1).transpose()*rand_vector).sum();
383 if ( abs(rand_sum1)==0 || abs(rand_sum2)==0)
389 RealT estimate = log(
static_cast<RealT
>(this->
EndgameSettings().sample_factor))/log(abs(rand_sum2/rand_sum1));
402 RealT amplified = round(estimate) *
static_cast<RealT
>(ps_config.cycle_number_amplification);
403 if (!(amplified <
static_cast<RealT
>(ps_config.max_cycle_number)))
430 template<
typename ComplexT>
433 using RealT =
typename Eigen::NumTraits<ComplexT>::Real;
435 const auto& samples = std::get<SampCont<ComplexT> >(
samples_);
436 const auto& times = std::get<TimeCont<ComplexT> >(
times_);
441 const ComplexT& most_recent_time = times.back();
448 if (samples.size() > this->EndgameSettings().num_sample_points)
454 auto min_found_difference = Eigen::NumTraits<RealT>::highest();
469 RealT cand_power{1/
static_cast<RealT
>(candidate)};
471 pow((most_recent_time-t0)/(times[0]-t0),cand_power),
474 most_recent_sample).
template lpNorm<Eigen::Infinity>();
476 if (curr_diff < min_found_difference)
478 min_found_difference = curr_diff;
501 template<
typename ComplexT>
504 auto& samples = std::get<SampCont<ComplexT> >(
samples_);
505 auto& times = std::get<TimeCont<ComplexT> >(
times_);
506 auto& derivatives = std::get<SampCont<ComplexT> >(
derivatives_);
508 assert((samples.size() == times.size()) &&
"must have same number of times and samples");
512 auto max_precision = this->EnsureAtUniformPrecision(times, samples);
516 derivatives.clear(); derivatives.resize(samples.size());
517 for(
unsigned ii = 0; ii < samples.size(); ++ii)
519 derivatives[ii] = -this->GetSystem().Jacobian(samples[ii],times[ii]).lu().solve(this->GetSystem().TimeDerivative(samples[ii],times[ii]));
534 template <
typename ComplexT>
538 throw std::runtime_error(
"cannot transform to s plane with cycle number 0");
542 using RealT =
typename Eigen::NumTraits<ComplexT>::Real;
544 const auto& times = std::get<TimeCont<ComplexT> >(
times_);
545 const auto& derivatives = std::get<SampCont<ComplexT> >(
derivatives_);
547 RealT c =
static_cast<RealT
>(cycle_num);
548 RealT one_over_c = 1/c;
550 size_t offset_t, offset_d;
553 offset_t = times.size()-num_pts;
554 offset_d = derivatives.size()-num_pts;
557 offset_t = offset_d = 0;
563 ComplexT time_shift = times[offset_t] - t0;
565 for(
unsigned ii = 0; ii < num_pts; ++ii){
566 s_times[ii] =
pow((times[ii+offset_t]-t0)/time_shift, one_over_c);
567 s_derivatives[ii] = derivatives[ii+offset_d]*( c*
pow(s_times[ii],cycle_num-1))*time_shift;
570 return std::make_tuple(s_times, s_derivatives);
591 template<
typename ComplexT>
632 template<
typename ComplexT>
635 using RealT =
typename Eigen::NumTraits<ComplexT>::Real;
637 auto& samples = std::get<SampCont<ComplexT> >(
samples_);
638 auto& times = std::get<TimeCont<ComplexT> >(
times_);
643 ComplexT next_time = (times.back() + target_time) *
static_cast<RealT
>(this->
EndgameSettings().sample_factor);
645 if (abs(next_time - target_time) < this->
EndgameSettings().min_track_time)
653 return tracking_success;
658 if (this->adaptive_numeric_type_active_ &&
659 this->GetTracker().GetCurrentPrecision() > this->current_endgame_precision_)
662 this->EnsureAtPrecision(next_time,
Precision(next_sample));
665 times.push_back(next_time);
666 samples.push_back(next_sample);
671 auto refine_success = this->
RefineSample(samples.back(), next_sample, times.back(),
672 this->FinalTolerance() * this->EndgameSettings().sample_point_refinement_factor,
673 this->EndgameSettings().max_num_refinements);
679 if (this->adaptive_numeric_type_active_ &&
687 return refine_success;
690 this->EnsureAtPrecision(times.back(),
Precision(samples.back()));
699 if constexpr (std::is_same<ComplexT, BCT>::value)
703 Vec<BCT> ev_pt(samples.back().size());
704 for (Eigen::Index i = 0; i < samples.back().size(); ++i) ev_pt(i) =
BCT(samples.back()(i));
705 BCT ev_t(times.back());
710 if (times.size() > this->EndgameSettings().num_sample_points+1)
738 template<
typename ComplexT>
744 auto const needed = this->
EndgameSettings().num_needed_for_stabilization;
745 auto& c_over_k = std::get<TimeCont<ComplexT> >(
c_over_k_);
747 while (c_over_k.size() > needed + 1)
748 c_over_k.pop_front();
750 if (c_over_k.size() > needed && this->CheckForCOverKStabilization(c_over_k))
774 template<
typename ComplexT>
777 if (start_point.size()!=
static_cast<Eigen::Index
>(this->GetSystem().NumVariables()))
779 std::stringstream err_msg;
780 err_msg <<
"number of variables in start point for PSEG, " << start_point.size() <<
", must match the number of variables in the system, " << this->GetSystem().NumVariables();
781 throw std::runtime_error(err_msg.str());
787 using RealT =
typename Eigen::NumTraits<ComplexT>::Real;
793 auto& samples = std::get<SampCont<ComplexT> >(
samples_);
794 auto& times = std::get<TimeCont<ComplexT> >(
times_);
802 auto initial_sample_success = this->
ComputeInitialSamples(start_time, target_time, start_point, times, samples);
807 return initial_sample_success;
816 latest_approx = prev_approx;
819 return extrapolation_code;
821 RealT norm_of_dehom_of_latest_approx(0);
822 RealT norm_of_dehom_of_prev_approx(0);
824 norm_of_dehom_of_prev_approx = this->GetSystem().InfinityNormOfDehomogenized(prev_approx);
847 return extrapolation_code;
850 approx_error =
static_cast<NumErrorT>((latest_approx - prev_approx).template lpNorm<Eigen::Infinity>());
856 norm_of_dehom_of_latest_approx = this->GetSystem().InfinityNormOfDehomogenized(latest_approx);
862 norm_of_dehom_of_prev_approx = norm_of_dehom_of_latest_approx;
881 prev_approx = latest_approx;
898 template<
typename Dummy =
void>
902 using RealT =
typename Eigen::NumTraits<BCT>::Real;
904 if (start_point.size()!=
static_cast<Eigen::Index
>(this->GetSystem().NumVariables()))
906 std::stringstream err_msg;
907 err_msg <<
"number of variables in start point for PSEG, " << start_point.size() <<
", must match the number of variables in the system, " << this->GetSystem().NumVariables();
908 throw std::runtime_error(err_msg.str());
911 this->adaptive_numeric_type_active_ =
true;
912 struct Disarmer {
bool& flag; ~Disarmer(){ flag =
false; } } disarm{this->adaptive_numeric_type_active_};
928 :
SetupSegmentT<complex_mp>(this->AtActivePrecisionScalar(start_time), this->AtActivePrecisionVec(start_point), this->AtActivePrecisionScalar(target_time));
931 auto const previous_precision = this->current_endgame_precision_;
932 this->current_endgame_precision_ = this->NextEscalatedPrecision();
937 NotifyObservers(SamplesRecomputedAtHigherPrecision<EmitterType>(*
this));
946 RealT norm_prev(0), norm_latest(0);
978 norm_prev = norm_latest;
1004 template<
typename ComplexT>
1010 auto& samples = std::get<SampCont<ComplexT> >(
samples_);
1011 auto& times = std::get<TimeCont<ComplexT> >(
times_);
1017 if (this->GetTracker().GetCurrentPrecision() > this->current_endgame_precision_)
1036 template<
typename Dummy =
void>
1055 template<
typename Dummy =
void>
1074 template<
typename Dummy =
void>
1084 template<
typename Dummy =
void>
1106 template<
typename Dummy =
void>
1112 this->CrossTimesUp(
times_, newprec);
1113 this->CrossSampsUp(
samples_, newprec);
1123 if (rv.size() > 0)
Precision(rv, newprec);
Contains parent class, Endgame, the parent class for all endgames.
bool HasObservers() const
Definition observable.hpp:204
void NotifyObservers(AnyEvent const &e) const
Definition observable.hpp:185
A new sample point on the path was computed, adding one point to the sequence of the endgame's approa...
Definition events.hpp:118
bool BeyondSecurityMaxNorm(RealT const &norm) const
Definition base_endgame.hpp:521
SuccessCode EndgameTrackPath(Vec< ComplexT > &result, ComplexT const &start_time, ComplexT const &end_time, Vec< ComplexT > const &start_point) const
Definition base_endgame.hpp:446
typename PrecT::TrackerType TrackerType
The path-tracker type.
Definition base_endgame.hpp:93
auto ComputeCOverK(SampCont< ComplexT > const &samples) const -> typename Eigen::NumTraits< ComplexT >::Real
Definition base_endgame.hpp:237
NumErrorT approximate_error_
Definition base_endgame.hpp:140
typename NeededTypes::template ToTupleOfCont< SampCont > TupleOfSamps
A tuple of sample containers, one per numeric type.
Definition base_endgame.hpp:127
const auto & SecuritySettings() const
Definition base_endgame.hpp:511
SuccessCode ComputeInitialSamples(const ComplexT &start_time, const ComplexT &target_time, const Vec< ComplexT > &x_endgame_start, TimeCont< ComplexT > ×, SampCont< ComplexT > &samples)
Definition base_endgame.hpp:656
Vec< BCT > previous_approximation_
Definition base_endgame.hpp:133
SuccessCode EscalateAndMigrate(unsigned guard)
Definition base_endgame.hpp:481
SuccessCode RefineSample(Vec< ComplexT > &result, Vec< ComplexT > const ¤t_sample, ComplexT const ¤t_time, NumErrorT tol, unsigned max_iterations) const
Definition base_endgame.hpp:422
EndgameBase(TrackerType const &tr, const ConfigsAsTuple &settings)
Definition base_endgame.hpp:528
SuccessCode RefineAllSamples(SampCont< ComplexT > &samples, TimeCont< ComplexT > ×)
Definition base_endgame.hpp:390
typename tracking::TrackerTraits< TrackerType >::BaseComplexT BaseComplexT
The complex number type.
Definition base_endgame.hpp:95
Vec< BCT > final_approximation_
Definition base_endgame.hpp:132
typename NeededTypes::template ToTupleOfCont< TimeCont > TupleOfTimes
A tuple of time containers, one per numeric type.
Definition base_endgame.hpp:126
const auto & EndgameSettings() const
Definition base_endgame.hpp:504
typename NeededTypes::ToTupleOfVec TupOfVec
A tuple of vector containers, one per numeric type.
Definition base_endgame.hpp:124
const auto & FinalTolerance() const
Definition base_endgame.hpp:552
unsigned int cycle_number_
Definition base_endgame.hpp:134
typename tracking::TrackerTraits< TrackerType >::BaseRealT BaseRealT
The real number type.
Definition base_endgame.hpp:96
A common base type for various precision types, fixed and adaptive.
Definition prec_base.hpp:40
const auto & GetSamples() const
Function to get the space values used for the Power Series endgame.
Definition powerseries.hpp:318
void MigrateContainersToPrecision(unsigned newprec)
Widen this flavor's PowerSeries containers from the complex_dbl slot up to complex_mp at the new prec...
Definition powerseries.hpp:1107
SuccessCode RefineAllSamplesAMP()
Refine all retained samples at the active numeric type, migrating-and-retrying in mpfr on escalation.
Definition powerseries.hpp:1056
SuccessCode RunImplAMP(BCT const &start_time, Vec< BCT > const &start_point, BCT const &target_time)
Run the power-series endgame via the double-first adaptive-numeric-type driver, migrating up to mpfr ...
Definition powerseries.hpp:899
void NoteWhetherInOperatingZone(SampCont< ComplexT > const &samples) const
Watch the c/k estimates settle, and say so once when they have.
Definition powerseries.hpp:739
TupleOfSamps derivatives_
Definition powerseries.hpp:209
BCT latest_time_cache_
Definition powerseries.hpp:288
typename BaseEGT::TupOfVec TupOfVec
Definition powerseries.hpp:183
BaseComplexT BCT
Definition powerseries.hpp:185
const BCT & LatestTimeImpl() const
Definition powerseries.hpp:291
typename BaseEGT::BaseComplexT BaseComplexT
Definition powerseries.hpp:172
virtual ~PowerSeriesEndgame()=default
TupleOfTimes times_
Definition powerseries.hpp:199
PowerSeriesEndgame< EGPrecT > EmitterType
Definition powerseries.hpp:175
SuccessCode RunImpl(const ComplexT &start_time, const Vec< ComplexT > &start_point, ComplexT const &target_time)
Primary function running the Power Series endgame.
Definition powerseries.hpp:775
void AssertSizesTimeSpace() const
Debug-assert that the stored time and sample containers have consistent, sufficient sizes.
Definition powerseries.hpp:235
typename BaseEGT::TrackerType TrackerType
Definition powerseries.hpp:170
unsigned ComputeBoundOnCycleNumber()
Computes an upper bound on the cycle number.
Definition powerseries.hpp:363
PowerSeriesEndgame(TrackerType const &tr, const Ts &... ts)
Construct the power-series endgame for a tracker, with configs given in any order.
Definition powerseries.hpp:345
void ComputeAllDerivativesAMP()
Compute all sample derivatives at the active numeric type.
Definition powerseries.hpp:1075
const auto & GetTimes() const
Function to get the times used for the Power Series endgame.
Definition powerseries.hpp:285
SuccessCode ComputeApproxAMP(BCT const &target_time)
Compute the power-series extrapolation at the active numeric type, writing into final_approximation_ ...
Definition powerseries.hpp:1085
TupleOfSamps samples_
Definition powerseries.hpp:204
SuccessCode ComputeApproximationOfXAtT0(Vec< ComplexT > &result, const ComplexT &t0)
This function computes an approximation of the space value at the time time_t0.
Definition powerseries.hpp:592
void ClearTimesAndSamples()
Function that clears all samples and times from data members for the Power Series endgame.
Definition powerseries.hpp:266
TupleOfTimes c_over_k_
Definition powerseries.hpp:218
auto UpperBoundOnCycleNumber() const
Definition powerseries.hpp:259
unsigned ComputeCycleNumber(ComplexT const &t0)
This function computes the cycle number using an exhaustive search up the upper bound computed by the...
Definition powerseries.hpp:431
void ComputeAllDerivatives()
Compute a set of derivatives using internal data to the endgame.
Definition powerseries.hpp:502
BaseRealT BRT
Definition powerseries.hpp:186
SuccessCode AdvanceTimeAMP(BCT const &target_time)
Advance time at the active numeric type, migrating-and-retrying in mpfr on escalation.
Definition powerseries.hpp:1037
void SetSamples(SampCont< ComplexT > const &samples_to_set)
Function to set the space values used for the Power Series endgame.
Definition powerseries.hpp:312
PowerSeriesEndgame(TrackerType const &tr, const ConfigsAsTuple &settings)
Construct the power-series endgame for a tracker, with its configuration as a tuple.
Definition powerseries.hpp:337
PowerSeriesEndgame< EGPrecT > FinalEGT
Definition powerseries.hpp:169
typename AlgoTraits< FinalEGT >::NeededConfigs Configs
Definition powerseries.hpp:188
bool announced_operating_zone_
Definition powerseries.hpp:222
void AssertSizesTimeSpaceDeriv() const
Debug-assert that the time, sample, and derivative containers have consistent, sufficient sizes.
Definition powerseries.hpp:246
SuccessCode SetupSegmentT(ComplexT const &start_time, Vec< ComplexT > const &start_point, ComplexT const &target_time)
Definition powerseries.hpp:1005
typename BaseEGT::TupleOfSamps TupleOfSamps
Definition powerseries.hpp:182
unsigned upper_bound_on_cycle_number_
Definition powerseries.hpp:194
std::tuple< TimeCont< ComplexT >, SampCont< ComplexT > > TransformToSPlane(int cycle_num, ComplexT const &t0, unsigned num_pts, ContStart shift_from)
Transform the stored times and derivatives into the S-plane, scaled by the cycle number.
Definition powerseries.hpp:535
typename BaseEGT::BaseRealT BaseRealT
Definition powerseries.hpp:173
TupOfVec rand_vector_
Definition powerseries.hpp:231
EndgameBase< PowerSeriesEndgame< EGPrecT >, EGPrecT > BaseEGT
Definition powerseries.hpp:168
void SetTimes(TimeCont< ComplexT > const ×_to_set)
Function to set the times used for the Power Series endgame.
Definition powerseries.hpp:279
void SetRandVec(int size)
Function to set the times used for the Power Series endgame.
Definition powerseries.hpp:324
SuccessCode AdvanceTime(const ComplexT &target_time)
The samples used in the power series endgame are collected by advancing time to t = 0,...
Definition powerseries.hpp:633
typename BaseEGT::TupleOfTimes TupleOfTimes
Definition powerseries.hpp:181
typename Configs::ToTuple ConfigsAsTuple
Definition powerseries.hpp:189
Event emitted when the endgame's working precision changes.
Definition events.hpp:220
Definition endgames.hpp:44
Vec< ComplexT > HermiteInterpolateAndSolve(ComplexT const &target_time, const unsigned int num_sample_points, const TimeCont< ComplexT > ×, const SampCont< ComplexT > &samples, const SampCont< ComplexT > &derivatives, ContStart shift_from=ContStart::Back)
Estimates the root to interpolating polynomial.
Definition interpolation.hpp:60
Definition configIni_parse.hpp:78
void SetPrecision(SampCont< complex_mp > &samples, unsigned prec)
Sets the precision of each space sample to be of input precision.
Definition adaptive_precision_utilities.hpp:44
Definition algorithm_builder.hpp:36
constexpr unsigned DoublePrecision()
The number of digits considered "double precision" (16).
Definition num_traits.hpp:152
std::complex< double > complex_dbl
The double-precision complex number type.
Definition double_extensions.hpp:47
Eigen::Matrix< NumT, Eigen::Dynamic, 1 > Vec
A dynamically-sized column vector of NumT.
Definition eigen_extensions.hpp:296
T RandomUnit()
Get a random complex number of unit modulus, in number type T.
std::deque< Vec< T > > SampCont
Definition config.hpp:33
complex_dbl pow(const complex_dbl &z, int power)
Compute +,- integral powers of a std::complex<double> number.
Definition double_extensions.hpp:92
void SetThreadPrecision(unsigned prec)
Set the precision (digits) for the current thread only (does not touch the global default).
Definition mpfr_complex.hpp:176
ContStart
Definition config.hpp:36
@ Back
Definition config.hpp:38
@ Front
Definition config.hpp:37
double NumErrorT
The numeric type used to hold error/tolerance magnitudes throughout Bertini2 – tracking tolerances,...
Definition num_traits.hpp:48
std::deque< T > TimeCont
Definition config.hpp:34
SuccessCode
Definition config.hpp:42
@ FailedToConverge
Definition config.hpp:55
@ Success
Definition config.hpp:51
@ MinTrackTimeReached
Definition config.hpp:64
@ HigherPrecisionNecessary
Definition config.hpp:52
@ SecurityMaxNormReached
Definition config.hpp:65
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object.
Definition eigen_extensions.hpp:339
std::tuple< const UnpermutedT &... > Unpermute(const PermutedPresentT &... present_permuted_args)
Reorder a set of present arguments into the declared UnpermutedT order, default-constructing any abse...
Definition enable_permuted_arguments.hpp:117
bool ContainsNaN(Eigen::MatrixBase< Derived > const &v)
True when any entry of a complex-valued Eigen object has a NaN real or imaginary part.
Definition eigen_extensions.hpp:321
Definition config.hpp:176
Trait lookup mapping a tracker type to its numeric types, event-emitter type, precision config,...
Definition config.hpp:387