Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
trackers/config.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//trackers/include/bertini2/trackers/config.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//trackers/include/bertini2/trackers/config.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with tracking/include/bertini2/trackers/config.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2015 - 2021 by Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22// individual authors of this file include:
23// silviana amethyst, university of wisconsin eau claire
24// Tim Hodges, Colorado State University
25
26#ifndef BERTINI_TRACKING_CONFIG_HPP
27#define BERTINI_TRACKING_CONFIG_HPP
28
38
39#include "bertini2/common/config.hpp"
40
41
42namespace bertini
43{
44
45namespace tracking{
46
47
48 enum class PrecisionType //E.2.1
49 {
50 Fixed,
51 Adaptive
52 };
53
54
55 enum class Predictor //E.4.3
56 {
57 Constant,
58 Euler,
59 Heun,
60 RK4,
61 HeunEuler,
62 RKNorsett34,
63 RKF45,
64 RKCashKarp45,
65 RKDormandPrince56,
66 RKVerner67
67 };
68
69
70
71
72
73
74
75 struct SteppingConfig
76 {
77 using T = mpq_rational;
78
79 T initial_step_size = T(1)/T(10);
80 T max_step_size = T(1)/T(10);
81 T min_step_size = T(1)/T(1e100);
82
83 T step_size_success_factor = T(2);
84 T step_size_fail_factor = T(1)/T(2);
85
86 unsigned consecutive_successful_steps_before_stepsize_increase = 5;
87
88 unsigned min_num_steps = 1;
89 unsigned max_num_steps = 1e5;
90
91 unsigned frequency_of_CN_estimation = 1;
92 };
93
94
95
96 struct NewtonConfig
97 {
98 unsigned max_num_newton_iterations = 2; //MaxNewtonIts
99 unsigned min_num_newton_iterations = 1;
100 };
101
102
103
104
105
106
107
108
109 struct FixedPrecisionConfig
110 {
111 using RealType = double;
112
116 explicit
117 FixedPrecisionConfig(System const& sys)
118 { }
119
120 FixedPrecisionConfig() = default;
121 };
122
123
124 inline
125 std::ostream& operator<<(std::ostream & out, FixedPrecisionConfig const& fpc)
126 {
127 return out;
128 }
129
130
153 struct AdaptiveMultiplePrecisionConfig
154 {
156 NumErrorT degree_bound;
157
158 NumErrorT epsilon;
159 // rename to linear_solve_error_bound.
160
161 NumErrorT Phi;
162 // \f$\Phi\f$ is error in Jacobian evaluation divided by the unit roundoff error, \f$10^{-P}\f$
163 // rename to jacobian_eval_error_bound
164
165 NumErrorT Psi;
166 // Error in function evaluation, divided by the precision-dependent unit roundoff error.
167 // rename to function_eval_error_bound
168
171 unsigned int maximum_precision = 300;
172
173 unsigned consecutive_successful_steps_before_precision_decrease = 10;
174
176
177
186 {
187 using std::pow;
188
189 epsilon = pow(NumErrorT(sys.NumVariables()),2);
190 degree_bound = sys.DegreeBound();
191 coefficient_bound = sys.CoefficientBound<dbl>();
192 }
193
194
202 {
204 Psi = degree_bound*coefficient_bound; //Psi from the AMP paper.
205 }
206
207 void SetAMPConfigFrom(System const& sys)
208 {
211 }
212
213 AdaptiveMultiplePrecisionConfig() : coefficient_bound(1000), degree_bound(5), safety_digits_1(1), safety_digits_2(1), maximum_precision(300)
214 {}
215
216 explicit
217 AdaptiveMultiplePrecisionConfig(System const& sys) : AdaptiveMultiplePrecisionConfig()
218 {
219 SetAMPConfigFrom(sys);
220 }
221 }; // re: AdaptiveMultiplePrecisionConfig
222
223 inline
224 std::ostream& operator<<(std::ostream & out, AdaptiveMultiplePrecisionConfig const& AMP)
225 {
226 out << "coefficient_bound: " << AMP.coefficient_bound << "\n";
227 out << "degree_bound: " << AMP.degree_bound << "\n";
228 out << "epsilon: " << AMP.epsilon << "\n";
229 out << "Phi: " << AMP.Phi << "\n";
230 out << "Psi: " << AMP.Psi << "\n";
231 out << "safety_digits_1: " << AMP.safety_digits_1 << "\n";
232 out << "safety_digits_2: " << AMP.safety_digits_2 << "\n";
233 out << "consecutive_successful_steps_before_precision_decrease" << AMP.consecutive_successful_steps_before_precision_decrease << "\n";
234 return out;
235 }
236
237
247 inline
248 static
249 AdaptiveMultiplePrecisionConfig AMPConfigFrom(System const& sys)
250 {
252 AMP.SetAMPConfigFrom(sys);
253 return AMP;
254 }
255
256 // forward declarations
257 template<class D>
258 class Tracker;
259 template<class D>
260 class FixedPrecisionTracker;
261 class MultiplePrecisionTracker;
262 class DoublePrecisionTracker;
263
264
265// now for the TrackerTraits structs, which enable lookup of correct settings objects and types, etc.
266 template<class T>
267 struct TrackerTraits
268 {};
269
270
271
272
273 template<>
274 struct TrackerTraits<DoublePrecisionTracker>
275 {
276 using BaseComplexType = dbl;
277 using BaseRealType = double;
278 using EventEmitterType = FixedPrecisionTracker<DoublePrecisionTracker>;
279 using PrecisionConfig = FixedPrecisionConfig;
280 enum {
281 IsFixedPrec = 1,
282 IsAdaptivePrec = 0
283 };
284
285 using NeededTypes = detail::TypeList<dbl>;
286 using NeededConfigs = detail::TypeList<
287 SteppingConfig,
288 NewtonConfig,
289 PrecisionConfig
290 >;
291 };
292
293
294 template<>
295 struct TrackerTraits<MultiplePrecisionTracker>
296 {
297 using BaseComplexType = mpfr_complex;
298 using BaseRealType = mpfr_float;
299 using EventEmitterType = FixedPrecisionTracker<MultiplePrecisionTracker>;
300 using PrecisionConfig = FixedPrecisionConfig;
301
302 enum {
303 IsFixedPrec = 1,
304 IsAdaptivePrec = 0
305 };
306
307 using NeededTypes = detail::TypeList<mpfr_complex>;
308
309 using NeededConfigs = detail::TypeList<
310 SteppingConfig,
311 NewtonConfig,
312 PrecisionConfig
313 >;
314 };
315
316
317 class AMPTracker; // forward declare
318 template<>
319 struct TrackerTraits<AMPTracker>
320 {
321 using BaseComplexType = mpfr_complex;
322 using BaseRealType = mpfr_float;
323 using EventEmitterType = AMPTracker;
324 using PrecisionConfig = AdaptiveMultiplePrecisionConfig;
325
326 enum {
327 IsFixedPrec = 0,
328 IsAdaptivePrec = 1
329 };
330
331 using NeededTypes = detail::TypeList<dbl, mpfr_complex>;
332
333 using NeededConfigs = detail::TypeList<
334 SteppingConfig,
335 NewtonConfig,
336 PrecisionConfig
337 >;
338 };
339
340
341
342
343 template<class D>
344 struct TrackerTraits<FixedPrecisionTracker<D> > : public TrackerTraits<D>
345 {
346 using BaseComplexType = typename TrackerTraits<D>::BaseComplexType;
347 using BaseRealType = typename TrackerTraits<D>::BaseRealType;
348 using EventEmitterType = typename TrackerTraits<D>::EventEmitterType;
349 using PrecisionConfig = typename TrackerTraits<D>::PrecisionConfig;
350
351 enum {
352 IsFixedPrec = 0,
353 IsAdaptivePrec = 1
354 };
355
356 using NeededTypes = typename TrackerTraits<D>::NeededTypes;
357 using NeededConfigs = typename TrackerTraits<D>::NeededConfigs;
358 };
359
360} // re: namespace tracking
361} // re: namespace bertini
362
363
364#endif
double D(double const &norm_J, double const &norm_J_inverse, AdaptiveMultiplePrecisionConfig const &AMP_config)
Compute the expression from the AMP papers amp1, amp2.
Definition amp_criteria.hpp:88
The fundamental polynomial system class for Bertini2.
Definition system/system.hpp:99
size_t NumVariables() const
Functor-like class for tracking paths on a system.
Definition amp_tracker.hpp:346
Base tracker class for trackers offered in Bertini2.
Definition base_tracker.hpp:141
dbl pow(const dbl &z, int power)
Definition double_extensions.hpp:88
Bertini extensions of the Eigen linear algebra library.
Extensions to the Boost.Multiprecision library.
Definition trackers/config.hpp:154
NumErrorT coefficient_bound
User-defined bound on the sum of the abs vals of the coeffs for any polynomial in the system (for ada...
Definition trackers/config.hpp:155
unsigned int maximum_precision
User-chosed setting for the maximum allowable precision. Paths will die if their precision is request...
Definition trackers/config.hpp:171
void SetPhiPsiFromBounds()
Definition trackers/config.hpp:201
int safety_digits_2
User-chosen setting for the number of safety digits used during Criterion C.
Definition trackers/config.hpp:170
int safety_digits_1
User-chosen setting for the number of safety digits used during Criteria A & B.
Definition trackers/config.hpp:169
NumErrorT Phi
Bound on (an error bound). Used for AMP criteria A, B.
Definition trackers/config.hpp:161
NumErrorT Psi
Bound on (an error bound). Used for AMP criterion C.
Definition trackers/config.hpp:165
unsigned max_num_precision_decreases
The maximum number of times precision can be lowered during tracking of a segment of path.
Definition trackers/config.hpp:175
NumErrorT epsilon
Bound on growth in error from linear solves. This is in amp1, amp2, and is used for AMP criteria A a...
Definition trackers/config.hpp:158
void SetBoundsAndEpsilonFrom(System const &sys)
Set epsilon, degree bound, and coefficient bound from system.
Definition trackers/config.hpp:185
NumErrorT degree_bound
User-set bound on degrees of polynomials in the system - tricky to compute for factored polys,...
Definition trackers/config.hpp:156
Provides the bertini::System class.
Contains the detail/typelist helper type, for templated getting/setting/storage of config structs.