22#ifndef BERTINI_BASE_ENDGAME_HPP
23#define BERTINI_BASE_ENDGAME_HPP
86template<
class FlavorT,
class PrecT>
124 using TupOfVec =
typename NeededTypes::ToTupleOfVec;
126 using TupleOfTimes =
typename NeededTypes::template ToTupleOfCont<TimeCont>;
127 using TupleOfSamps =
typename NeededTypes::template ToTupleOfCont<SampCont>;
177 for (
unsigned ii = 0; ii < size; ++ii)
179 std::apply([](
auto&... working){ (working.resize(0), ...); },
c_over_k_probe_);
195 template<
typename ComplexT>
203 bool stale =
static_cast<unsigned>(probe.size()) != size;
204 if constexpr (!std::is_same<ComplexT, complex_dbl>::value)
205 stale = stale ||
Precision(probe) != prec;
209 for (
unsigned ii = 0; ii < size; ++ii)
211 if constexpr (!std::is_same<ComplexT, complex_dbl>::value)
236 template<
typename ComplexT>
239 using RealT =
typename Eigen::NumTraits<ComplexT>::Real;
243 assert(samples.size()>=3);
253 RealT estimate = abs(log(abs((((sample2 - sample1).transpose()*rand_vector).
template lpNorm<Eigen::Infinity>())/(((sample1 - sample0).transpose()*rand_vector).
template lpNorm<Eigen::Infinity>()))));
254 estimate = abs(log(RealT(this->
EndgameSettings().sample_factor)))/estimate;
278 using RealT =
typename Eigen::NumTraits<T>::Real;
281 assert(c_over_k_array.size()>=this->EndgameSettings().num_needed_for_stabilization);
282 for(
unsigned ii = 1; ii < this->
EndgameSettings().num_needed_for_stabilization ; ++ii)
284 RealT a = abs(c_over_k_array[ii-1]);
285 RealT b = abs(c_over_k_array[ii]);
293 if(divide < this->
EndgameSettings().minimum_for_c_over_k_stabilization)
308 return dynamic_cast<const FlavorT&
>(*this);
316 return dynamic_cast<FlavorT&
>(*this);
356 return this->
AsFlavor().template RunImplAMP<>(t, start_point, t0);
358 return this->
AsFlavor().RunImpl(t, start_point, t0);
374 template<
typename ComplexT>
377 if constexpr (std::is_same<ComplexT, BCT>::value)
382 for (Eigen::Index i = 0; i < sample.size(); ++i) ev_pt(i) =
BCT(sample(i));
389 template<
typename ComplexT>
392 for (
size_t ii=0; ii<samples.size(); ++ii)
394 auto refine_success = this->
RefineSample(samples[ii], samples[ii], times[ii],
400 return refine_success;
407 auto max_precision = this->EnsureAtUniformPrecision(times, samples);
421 template<
typename ComplexT>
424 return this->RefineSampleImpl(result, current_sample, current_time, tol, max_iterations);
445 template<
typename ComplexT>
448 if constexpr (std::is_same<ComplexT, BCT>::value)
450 return this->GetTracker().TrackPath(result, start_time, end_time, start_point);
455 Vec<BCT> mp_start(start_point.size());
456 for (Eigen::Index i = 0; i < start_point.size(); ++i) mp_start(i) =
BCT(start_point(i));
462 Vec<BCT> mp_result(start_point.size());
463 auto code = this->GetTracker().TrackPath(mp_result, mp_t0, mp_t1, mp_start);
467 result.resize(mp_result.size());
468 for (Eigen::Index i = 0; i < mp_result.size(); ++i) result(i) =
complex_dbl(mp_result(i));
480 template<
typename Dummy =
void>
485 unsigned newprec = this->NextEscalatedPrecision();
486 this->
AsFlavor().template MigrateContainersToPrecision<>(newprec);
487 this->current_endgame_precision_ = newprec;
520 template<
typename RealT>
534 template<
typename... Ts >
579 template<
typename ComplexT>
589 template<
typename ComplexT>
655 template<
typename ComplexT>
658 using RealT =
typename Eigen::NumTraits<ComplexT>::Real;
659 assert(this->
template Get<EndgameConfig>().num_sample_points>0 &&
"number of sample points must be positive");
663 assert(
Precision(start_time)==
Precision(x_endgame_start) &&
"Computing initial samples requires input time and space with uniform precision");
669 samples.push_back(x_endgame_start);
670 times.push_back(start_time);
678 auto num_vars = this->GetSystem().NumVariables();
682 times.emplace_back((times[ii-1] + target_time) * RealT(this->
template Get<EndgameConfig>().sample_factor));
685 auto tracking_success = this->
EndgameTrackPath(samples[ii],times[ii-1],times[ii],samples[ii-1]);
686 this->EnsureAtPrecision(times[ii],
Precision(samples[ii]));
689 return tracking_success;
Functions for dealing with precisions of objects, particularly in the context of adaptive precision.
bool HasObservers() const
Whether anyone is currently observing (conservative).
Definition observable.hpp:204
void NotifyObservers(AnyEvent const &e) const
Sends an event to observers that subscribed to its exact dynamic type, then to all catch-all (untyped...
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
void SetFinalTolerance(NumErrorT const &ft)
Setter for the final tolerance.
Definition base_endgame.hpp:563
SuccessCode Run(Vec< BCT > const &start_point)
Run the endgame from the stored boundary time to the stored target time.
Definition base_endgame.hpp:338
EndgameBase(TrackerType const &tr, const Ts &... ts)
Construct the endgame for a tracker, with configs given in any order.
Definition base_endgame.hpp:536
const Vec< ComplexT > & FinalApproximation() const
Get the most-recent approximation.
Definition base_endgame.hpp:581
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
Track through the tracker, adapting at the numeric-type boundary.
Definition base_endgame.hpp:446
void CycleNumber(unsigned c)
Set the cycle number.
Definition base_endgame.hpp:543
void SetBoundaryTime(BCT const &t)
Set the endgame boundary (start) time.
Definition base_endgame.hpp:322
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
An estimate of c/k from the three most recent geometric samples.
Definition base_endgame.hpp:237
bool CheckForCOverKStabilization(std::deque< T > const &c_over_k_array) const
Have the last few c/k estimates settled to within the user's threshold?
Definition base_endgame.hpp:276
NumErrorT approximate_error_
Definition base_endgame.hpp:140
const FlavorT & AsFlavor() const
convert the base endgame into the derived type.
Definition base_endgame.hpp:306
void EmitComputedSample(Vec< ComplexT > const &sample, ComplexT const &time)
Announce a completed sample point on the path, as a ComputedSamplePoint.
Definition base_endgame.hpp:375
const BCT & LatestTime() const
Get the latest time at which a point on the path was computed.
Definition base_endgame.hpp:610
unsigned CycleNumber() const
Definition base_endgame.hpp:541
NumErrorT ApproximateError() const
Get the most recent accuracy estimate.
Definition base_endgame.hpp:600
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
BCT start_time_
Definition base_endgame.hpp:145
SuccessCode ComputeInitialSamples(const ComplexT &start_time, const ComplexT &target_time, const Vec< ComplexT > &x_endgame_start, TimeCont< ComplexT > ×, SampCont< ComplexT > &samples)
Get the system being tracked on, which is referred to by the tracker.
Definition base_endgame.hpp:656
FlavorT & AsFlavor()
Non-const version of AsFlavor.
Definition base_endgame.hpp:314
void SetTargetTime(BCT const &t)
Set the final target time.
Definition base_endgame.hpp:324
Vec< BCT > previous_approximation_
Definition base_endgame.hpp:133
typename Configs::ToTuple ConfigsAsTuple
The configuration structs as a tuple.
Definition base_endgame.hpp:114
Vec< ComplexT > const & GetCOverKProbe(unsigned size, unsigned prec) const
The fixed random direction the c/k estimate is projected along.
Definition base_endgame.hpp:196
detail::Configured< typename AlgoTraits< FlavorT >::NeededConfigs > Configured
The Configured base type.
Definition base_endgame.hpp:112
void IncrementCycleNumber(unsigned inc)
Increase the cycle number by the given increment.
Definition base_endgame.hpp:545
BaseRealT BRT
The real number type.
Definition base_endgame.hpp:109
BaseComplexT BCT
The complex number type.
Definition base_endgame.hpp:108
BCT target_time_
Definition base_endgame.hpp:146
detail::Configured< typename AlgoTraits< FlavorT >::NeededConfigs > Config
The configuration bundle this endgame reads, public so that generic machinery which works in terms of...
Definition base_endgame.hpp:104
TupOfVec c_over_k_probe_
Definition base_endgame.hpp:160
virtual ~EndgameBase()=default
SuccessCode EscalateAndMigrate(unsigned guard)
Raise the endgame to the next precision and migrate the containers' complex_dbl slot up to complex_mp...
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
A function passed off to the precision-specific endgame part.
Definition base_endgame.hpp:422
EndgameBase(TrackerType const &tr, const ConfigsAsTuple &settings)
Construct the endgame for a tracker, with its configuration as a tuple.
Definition base_endgame.hpp:528
SuccessCode RefineAllSamples(SampCont< ComplexT > &samples, TimeCont< ComplexT > ×)
Refine every sample point to the endgame's refinement tolerance.
Definition base_endgame.hpp:390
BCT const & TargetTime() const
Definition base_endgame.hpp:328
BCT const & BoundaryTime() const
Definition base_endgame.hpp:326
typename AlgoTraits< FlavorT >::NeededConfigs Configs
The configuration bundle (Configured base).
Definition base_endgame.hpp:113
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
This function is inferior to the templated Get<ConfigT> function provided.
Definition base_endgame.hpp:504
typename NeededTypes::ToTupleOfVec TupOfVec
A tuple of vector containers, one per numeric type.
Definition base_endgame.hpp:124
void RefreshCOverKProbe(unsigned size) const
Draw the c/k probe direction for a run.
Definition base_endgame.hpp:174
const auto & FinalTolerance() const
Get the final tolerance to which we are tracking the solution.
Definition base_endgame.hpp:552
const Vec< ComplexT > & PreviousApproximation() const
Get the second-most-recent approximation.
Definition base_endgame.hpp:591
typename NeededTypes::ToTupleOfReal TupOfReal
A tuple of real values, one per numeric type.
Definition base_endgame.hpp:125
unsigned int cycle_number_
Definition base_endgame.hpp:134
typename tracking::TrackerTraits< TrackerType >::NeededTypes NeededTypes
Arithmetic types this endgame may compute in (sourced from the tracker).
Definition base_endgame.hpp:123
typename tracking::TrackerTraits< TrackerType >::BaseRealT BaseRealT
The real number type.
Definition base_endgame.hpp:96
FlavorT EmitterType
The event-emitter type.
Definition base_endgame.hpp:98
Vec< complex_dbl > c_over_k_probe_as_drawn_
Definition base_endgame.hpp:156
A common base type for various precision types, fixed and adaptive.
Definition prec_base.hpp:40
Contains helper templates, based on and refined from SO post https://stackoverflow....
Configs and settings for endgames.
Contains the endgames/events base types.
Contains interpolation and extrapolation functions used in the endgames for estimating singular (and ...
Logging in Bertini using Boost.Log.
The main multiprecision complex number type.
Definition endgames.hpp:44
Definition configIni_parse.hpp:78
Definition algorithm_builder.hpp:36
bool isnan(std::complex< double > const &z)
an overload of isnan, for std::complex<double>
Definition double_extensions.hpp:63
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
std::deque< Vec< T > > SampCont
Definition config.hpp:33
void SetThreadPrecision(unsigned prec)
Set the precision (digits) for the current thread only (does not touch the global default).
Definition mpfr_complex.hpp:176
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
@ Success
Definition config.hpp:51
@ HigherPrecisionNecessary
Definition config.hpp:52
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
complex_dbl RandomUnit< complex_dbl >()
Get a random double-precision complex number of unit modulus.
Definition num_traits.hpp:241
Definition config.hpp:176
Trait lookup mapping a tracker type to its numeric types, event-emitter type, precision config,...
Definition config.hpp:387
Provides the bertini::System class.
Configs and settings for tracking.