35 max_size(default_max_size),
36 automatic_size(false),
52 OLD_ASSERT(bound_a != bound_b,
"Bounds overlap.");
53 OLD_ASSERT(bound_a < bound_b,
"a must be lower and b must be upper bound.");
69 OLD_ASSERT(size >0,
"Size of interpolation table must be positive number!.");
85 OLD_ASSERT(init_size >0,
"Maximal size of interpolation table must be positive number!.");
86 OLD_ASSERT(max_size >= init_size,
"Maximal size of interpolation table is smaller than initial size.");
115 bool reinterpolate =
false;
119 reinterpolate =
true;
124 reinterpolate =
true;
129 MessageOut() <<
"Interpolation: Reinterpolating...\n";
160 interpolate_derivative(false)
183 f[i] = f[i] * this->
fact(i);
192 unsigned int result = 10;
239 MessageOut().fmt(
"Interpolation: Size of the table set automaticaly to: {} after {} cycles.\n",
size_, k);
258 WarningOut().fmt(
"Interpolation: User defined tolerance {} has not been satisfied with size of interpolation table {}).\n",
275 MessageOut().fmt(
"Interpolation: Interpolation error estimate is: {}.\n",
error_);
350 for(
unsigned int i = 0; i <
size_; i++)
354 f_vec[i] = value.first;
365 for(
unsigned int i = 0; i <
size_; i++)
377 double new_size = 2*
size_;
387 for(
unsigned int i=0; i!=
size_; i++)
389 swap_f_vec.push_back(
f_vec[i]);
390 swap_f_vec.push_back(f[i]);
392 swap_f_vec.push_back(
f_vec.back());
398 for(
unsigned int i=0; i!=
size_; i++)
400 swap_df_vec.push_back(
df_vec[i]);
401 swap_df_vec.push_back(df[i]);
403 swap_df_vec.push_back(
df_vec.back());
418 double temp_x = temp_a;
426 for(
unsigned int i = 0; i !=
size_; i++)
428 temp_x = temp_a +
step*i;
430 f.push_back(value.first);
431 df.push_back(value.second);
435 tot_err = std::max( tot_err,
436 std::abs(value.first - int_value.first) / (std::abs(value.first) + tol)
437 + std::abs(value.second - int_value.second) / (std::abs(value.second) + tol)
444 for(
unsigned int i = 0; i !=
size_; i++)
446 temp_x = temp_a +
step*i;
447 f.push_back(
f_val(temp_x));
448 tot_err = std::max( tot_err,
449 std::abs(f.back() -
val_p1(temp_x)) / (std::abs(f.back()) + tol)
518 for(
unsigned long i = 0; i <
size_; i++ )
529 tot_err = std::pow(tot_err, 1.0/exponent);
544 explicit_interpolant(NULL),
566 return func_u->operator()(u);
FunctorBase< B< double > > * func_diff
Pointer to original functor with FADBAD B type.
bool automatic_size
Is true if step/size should be chosen automatically.
ErrorNorm::Type norm_type
Type of norm used to compute error of the interpolation.
double bound_b() const
Returns right boundary of the interval.
void compute_values()
Creates table of nodes and function values.
double a_div_step
bound_ divided by step - precomputed value for evaluation
double f_diffn(double x, unsigned int n)
static const double simpson_tolerance
Tolerance in Adaptive Simpson intergration.
unsigned int n_nodes
Number of nodes in the interval .
static const unsigned int default_max_size
Default maximal size of the interpolation table.
unsigned int interval_miss_b
counts right misses of the interval
#define MessageOut()
Macro defining 'message' record of log.
InterpolantImplicit()
constructor
void check_stats_and_reinterpolate(double percentage=0.3)
Can be called to check automatically the evaluation statistics and possibly reinterpolate.
void set_interval(double bound_a, double bound_b)
Sets the interpolation interval boundaries.
virtual ~InterpolantBase()
Destructor.
void fix_variable(IFixVariable::Type fix, double value)
unsigned int total_calls
counts total calls of evaluation
double user_tol
User set tolerance which is used during automatic step choice.
InterpolantBase()
Default constructor.
std::vector< double > df_vec
Vector of function derivatives values at nodes.
FunctorBase< T< double > > * func_diffn
Pointer to original functor with FADBAD T type.
std::pair< double, double > DiffValue
void compute_error(double tol, std::vector< double > &f, std::vector< double > &df)
Creates piecewise linear interpolation.
double f_val(double x)
Returns value of the original functor.
Base class for interpolation.
std::vector< double > f_vec
Vector of function values at nodes.
double error_
Error of the interpolation.
virtual int interpolate()=0
Creates piecewise polynomial interpolation.
unsigned int size() const
Returns the size of the interpolation table.
IFunctorBase< B< double > > * func_diff
Interpolant * explicit_interpolant
double max
maximal x for which the evaluation was called outside the interval ((initially is equal the right bou...
virtual ~InterpolantImplicit(void)
destructor
DiffValue diff_p1(double x)
Finds interval on which x lies.
long fact(long x)
Recursive factorial function (used in Taylor row expansion in n-th derivative computation).
void set_size_automatic(double user_tol, unsigned int init_size, unsigned int max_size=default_max_size)
Sets automatic choice of the size of the table.
double val_p1(double x)
Do NOT use, unless you are 100% sure.
unsigned int max_size
Maximal size of the interpolation table.
FunctorBase< double > * func
Pointer to original functor with double type.
double step
Chosen interpolation step.
void set_size(unsigned int size)
Sets size of the interpolation table. It is also equal to the number of intervals.
void set_norm(ErrorNorm::Type norm_type=ErrorNorm::max, double p=2)
Sets the type of norm used for computing estimate of the error of the interpolation.
double f_val(double x, double y)
Returns interpolated value of the derivation.
std::vector< bool > checks
Vector of boolean values telling us which parameters are set or not.
EvalStatistics stats
Structure which keeps evaluation statistics. See InterpolantBase::eval_statistics.
Extrapolation::Type extrapolation
void interpolate_p1()
Creates piecewise linear interpolation.
void set_extrapolation(Extrapolation::Type extrapolation)
Sets the type of extrapolation. Functor type is default.
IFunctorBase< T< double > > * func_diffn
virtual int interpolate()
Creates piecewise interpolation with polynomials of selected degree.
static double AdaptSimpson(FunctorBase< double > &func, const double &a, const double &b, const double &tol)
main method that starts the evaluation and calls the recursion
virtual int interpolate()
Creates piecewise interpolation with polynomials of selected degree.
#define WarningOut()
Macro defining 'warning' record of log.
double bound_a() const
Returns left boundary of the interval.
IFunctorBase< double > * func
double bound_a_
Left interval boundary.
unsigned int interval_miss_a
counts left misses of the interval
double val(double u)
Returns interpolated value.
FuncExplicit< double > * func_u
bool interpolate_derivative
Is true if we want to interpolate the derivative too.
DiffValue f_diff(double x)
Returns 1st derivative of original functor using FADBAD.
double bound_b_
Right interval boundary.
void check_all()
Checks that the parameters are set before interpolation.
static const unsigned int n_derivatives
Defines how many derivatives we allow to be returned from Taylor's coeficients.
Interpolant()
Default constructor.
double p
Exponent used in norms and when computing error.
double min
minimal x for which the evaluation was called outside the interval (initially is equal the left bound...
virtual ~Interpolant(void)
Destructor.
void swap_middle_values(std::vector< double > &f, std::vector< double > &df)
void reset_stat()
Resets all measured statistics.
#define DebugOut()
Macro defining 'debug' record of log.
unsigned int size_
Number of dividing intervals.