/usr/include/root/Math/GSLMultiRootFinder.h is in libroot-math-mathmore-dev 5.34.14-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | // @(#)root/mathmore:$Id$
// Author: L. Moneta 03/2011
/**********************************************************************
* *
* Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this library (see file COPYING); if not, write *
* to the Free Software Foundation, Inc., 59 Temple Place, Suite *
* 330, Boston, MA 02111-1307 USA, or contact the author. *
* *
**********************************************************************/
// Header file for class GSLMultiRootFinder
//
#ifndef ROOT_Math_GSLMultiRootFinder
#define ROOT_Math_GSLMultiRootFinder
#ifndef ROOT_Math_IFunction
#include "Math/IFunction.h"
#endif
#ifndef ROOT_Math_WrappedFunction
#include "Math/WrappedFunction.h"
#endif
#include <vector>
#include <iostream>
namespace ROOT {
namespace Math {
class GSLMultiRootBaseSolver;
//________________________________________________________________________________________________________
/**
Class for Multidimensional root finding algorithms bassed on GSL. This class is used to solve a
non-linear system of equations:
f1(x1,....xn) = 0
f2(x1,....xn) = 0
..................
fn(x1,....xn) = 0
See the GSL <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Root_002dFinding.html"> online manual</A> for
information on the GSL MultiRoot finding algorithms
The available GSL algorithms require the derivatives of the supplied functions or not (they are
computed internally by GSL). In the first case the user needs to provide a list of multidimensional functions implementing the
gradient interface (ROOT::Math::IMultiGradFunction) while in the second case it is enough to supply a list of
functions impelmenting the ROOT::Math::IMultiGenFunction interface.
The available algorithms requiring derivatives (see also the GSL
<A HREF="http://www.gnu.org/software/gsl/manual/html_node/Algorithms-using-Derivatives.html">documentation</A> )
are the followings:
<ul>
<li><tt>ROOT::Math::GSLMultiRootFinder::kHybridSJ</tt> with name <it>"HybridSJ"</it>: modified Powell's hybrid
method as implemented in HYBRJ in MINPACK
<li><tt>ROOT::Math::GSLMultiRootFinder::kHybridJ</tt> with name <it>"HybridJ"</it>: unscaled version of the
previous algorithm</li>
<li><tt>ROOT::Math::GSLMultiRootFinder::kNewton</tt> with name <it>"Newton"</it>: Newton method </li>
<li><tt>ROOT::Math::GSLMultiRootFinder::kGNewton</tt> with name <it>"GNewton"</it>: modified Newton method </li>
</ul>
The algorithms without derivatives (see also the GSL
<A HREF="http://www.gnu.org/software/gsl/manual/html_node/Algorithms-without-Derivatives.html">documentation</A> )
are the followings:
<ul>
<li><tt>ROOT::Math::GSLMultiRootFinder::kHybridS</tt> with name <it>"HybridS"</it>: same as HybridSJ but using
finate difference approximation for the derivatives</li>
<li><tt>ROOT::Math::GSLMultiRootFinder::kHybrid</tt> with name <it>"Hybrid"</it>: unscaled version of the
previous algorithm</li>
<li><tt>ROOT::Math::GSLMultiRootFinder::kDNewton</tt> with name <it>"DNewton"</it>: discrete Newton algorithm </li>
<li><tt>ROOT::Math::GSLMultiRootFinder::kBroyden</tt> with name <it>"Broyden"</it>: Broyden algorithm </li>
</ul>
@ingroup MultiRoot
*/
class GSLMultiRootFinder {
public:
/**
enumeration specifying the types of GSL multi root finders
requiring the derivatives
@ingroup MultiRoot
*/
enum EDerivType {
kHybridSJ,
kHybridJ,
kNewton,
kGNewton
};
/**
enumeration specifying the types of GSL multi root finders
which do not require the derivatives
@ingroup MultiRoot
*/
enum EType {
kHybridS,
kHybrid,
kDNewton,
kBroyden
};
/// create a multi-root finder based on an algorithm not requiring function derivative
GSLMultiRootFinder(EType type);
/// create a multi-root finder based on an algorithm requiring function derivative
GSLMultiRootFinder(EDerivType type);
/*
create a multi-root finder using a string.
The names are those defined in the GSL manuals
after having remived the GSL prefix (gsl_multiroot_fsolver).
Default algorithm is "hybrids" (without derivative).
*/
GSLMultiRootFinder(const char * name = 0);
/// destructor
virtual ~GSLMultiRootFinder();
private:
// usually copying is non trivial, so we make this unaccessible
GSLMultiRootFinder(const GSLMultiRootFinder &);
GSLMultiRootFinder & operator = (const GSLMultiRootFinder &);
public:
/// set the type for an algorithm without derivatives
void SetType(EType type) {
fType = type; fUseDerivAlgo = false;
}
/// set the type of algorithm using derivatives
void SetType(EDerivType type) {
fType = type; fUseDerivAlgo = true;
}
/// set the type using a string
void SetType(const char * name);
/*
add the list of functions f1(x1,..xn),...fn(x1,...xn). The list must contain pointers of
ROOT::Math::IMultiGenFunctions. The method requires the
the begin and end of the list iterator.
The list can be any stl container or a simple array of ROOT::Math::IMultiGenFunctions* or
whatever implementing an iterator.
If using a derivative type algorithm the function pointers must implement the
ROOOT::Math::IMultiGradFunction interface
*/
template<class FuncIterator>
bool SetFunctionList( FuncIterator begin, FuncIterator end) {
bool ret = true;
for (FuncIterator itr = begin; itr != end; ++itr) {
const ROOT::Math::IMultiGenFunction * f = *itr;
ret &= AddFunction( *f);
}
return ret;
}
/*
add (set) a single function fi(x1,...xn) which is part of the system of
specifying the begin and end of the iterator.
If using a derivative type algorithm the function must implement the
ROOOT::Math::IMultiGradFunction interface
Return the current number of function in the list and 0 if failed to add the function
*/
int AddFunction( const ROOT::Math::IMultiGenFunction & func);
/// same method as before but using any function implementing
/// the operator(), so can be wrapped in a IMultiGenFunction interface
template <class Function>
int AddFunction( Function & f, int ndim) {
// no need to care about lifetime of wfunc. It will be cloned inside AddFunction
WrappedMultiFunction<Function &> wfunc(f, ndim);
return AddFunction(wfunc);
}
/**
return the number of sunctions set in the class.
The number must be equal to the dimension of the functions
*/
unsigned int Dim() const { return fFunctions.size(); }
/// clear list of functions
void Clear();
/// return the root X values solving the system
const double * X() const;
/// return the function values f(X) solving the system
/// i.e. they must be close to zero at the solution
const double * FVal() const;
/// return the last step size
const double * Dx() const;
/**
Find the root starting from the point X;
Use the number of iteration and tolerance if given otherwise use
default parameter values which can be defined by
the static method SetDefault...
*/
bool Solve(const double * x, int maxIter = 0, double absTol = 0, double relTol = 0);
/// Return number of iterations
int Iterations() const {
return fIter;
}
/// Return the status of last root finding
int Status() const { return fStatus; }
/// Return the algorithm name
const char * Name() const;
/*
set print level
level = 0 quiet (no messages print)
= 1 print only the result
= 3 max debug. Print result at each iteration
*/
void SetPrintLevel(int level) { fPrintLevel = level; }
/// return the print level
int PrintLevel() const { return fPrintLevel; }
//-- static methods to set configurations
/// set tolerance (absolute and relative)
/// relative tolerance is only use to verify the convergence
/// do it is a minor parameter
static void SetDefaultTolerance(double abstol, double reltol = 0 );
/// set maximum number of iterations
static void SetDefaultMaxIterations(int maxiter);
/// print iteration state
void PrintState(std::ostream & os = std::cout);
protected:
// return type given a name
std::pair<bool,int> GetType(const char * name);
// clear list of functions
void ClearFunctions();
private:
int fIter; // current numer of iterations
int fStatus; // current status
int fPrintLevel; // print level
// int fMaxIter; // max number of iterations
// double fAbsTolerance; // absolute tolerance
// double fRelTolerance; // relative tolerance
int fType; // type of algorithm
bool fUseDerivAlgo; // algorithm using derivative
GSLMultiRootBaseSolver * fSolver;
std::vector<ROOT::Math::IMultiGenFunction *> fFunctions; //! transient Vector of the functions
};
// use typedef for most sensible name
typedef GSLMultiRootFinder MultiRootFinder;
} // namespace Math
} // namespace ROOT
#endif /* ROOT_Math_GSLMultiRootFinder */
|