ANIMA  4.0
animaBracketAndSolveRootFindingAlgorithm.cxx
Go to the documentation of this file.
2 #include <boost/math/tools/roots.hpp>
3 
4 namespace anima
5 {
6 
8 {
9  unsigned int numParameters = this->GetRootFindingFunction()->GetNumberOfParameters();
10  if (numParameters > 1)
11  throw itk::ExceptionObject(__FILE__, __LINE__, "Bracket and solve root algorithm does not implement multi-dimensional optimization. Only one parameter allowed.");
12 
14  throw itk::ExceptionObject(__FILE__, __LINE__, "You need to provide the function value in at least one of the bounds because the bracket and solve root algorithm needs to know whether the function is rising or falling.");
15 
16  RootFindingFunctionBoostBridge boostFunction;
17  boostFunction.SetRootFindingFunction(this->GetRootFindingFunction());
18 
19  boost::uintmax_t maximumNumberOfIterations = this->GetMaximumNumberOfIterations();
20 
21  RootToleranceBoostBridge rootTolerance;
23 
24  bool risingValue = true;
25 
27  risingValue = this->GetFunctionValueAtInitialLowerBound() < 0.0;
28  else
29  risingValue = this->GetFunctionValueAtInitialUpperBound() > 0.0;
30 
31  std::pair <double,double> r = boost::math::tools::bracket_and_solve_root(boostFunction, (this->GetLowerBound() + this->GetUpperBound()) / 2.0, 2.0, risingValue, rootTolerance, maximumNumberOfIterations);
32 
33  return (r.first + r.second) / 2.0;
34 }
35 
36 } // end namespace anima
void SetRootFindingFunction(BaseCostFunctionType *f)