24#if defined(DEBUG) || defined(WARNINGMSG)
27#if defined(DEBUG) && !defined(WARNINGMSG)
70 double amin = mfcn(
x);
94 double amin = mfcn(st.
Vec());
100 if(maxcalls == 0) maxcalls = 200 + 100*
n + 5*
n*
n;
123 std::cout <<
"\nMnHesse " << std::endl;
124 std::cout <<
" x " <<
x << std::endl;
125 std::cout <<
" amin " << amin <<
" " << st.
Fval() << std::endl;
126 std::cout <<
" grd " << grd << std::endl;
127 std::cout <<
" gst " << gst << std::endl;
128 std::cout <<
" g2 " << g2 << std::endl;
133 for(
unsigned int i = 0; i <
n; i++) {
137 double d =
fabs(gst(i));
138 if(
d < dmin)
d = dmin;
141 std::cout <<
"\nDerivative parameter " << i <<
" d = " <<
d <<
" dmin = " << dmin << std::endl;
145 for(
unsigned int icyc = 0; icyc <
Ncycles(); icyc++) {
149 for(
unsigned int multpy = 0; multpy < 5; multpy++) {
155 sag = 0.5*(fs1+fs2-2.*amin);
158 std::cout <<
"cycle " << icyc <<
" mul " << multpy <<
"\t sag = " << sag <<
" d = " <<
d << std::endl;
161 if (sag != 0)
goto L30;
163 if(
d > 0.5)
goto L26;
165 if(
d > 0.5)
d = 0.51;
179 MN_INFO_MSG(
"MnHesse fails and will return diagonal matrix ");
183 for(
unsigned int j = 0; j <
n; j++) {
184 double tmp = g2(j) < prec.
Eps2() ? 1. : 1./g2(j);
185 vhmat(j,j) = tmp < prec.
Eps2() ? 1. : tmp;
191 double g2bfor = g2(i);
192 g2(i) = 2.*sag/(
d*
d);
193 grd(i) = (fs1-fs2)/(2.*
d);
200 if(
d < dmin)
d = dmin;
203 std::cout <<
"\t g1 = " << grd(i) <<
" g2 = " << g2(i) <<
" step = " << gst(i) <<
" d = " <<
d
204 <<
" diffd = " <<
fabs(
d-dlast)/
d <<
" diffg2 = " <<
fabs(g2(i)-g2bfor)/g2(i) << std::endl;
211 d = std::min(
d, 10.*dlast);
212 d = std::max(
d, 0.1*dlast);
219 MN_INFO_MSG(
"MnHesse: maximum number of allowed function calls exhausted.");
220 MN_INFO_MSG(
"MnHesse fails and will return diagonal matrix ");
223 for(
unsigned int j = 0; j <
n; j++) {
224 double tmp = g2(j) < prec.
Eps2() ? 1. : 1./g2(j);
225 vhmat(j,j) = tmp < prec.
Eps2() ? 1. : tmp;
234 std::cout <<
"\n Second derivatives " << g2 << std::endl;
251 unsigned int endParIndexOffDiagonal = mpiprocOffDiagonal.
EndElementIndex();
253 unsigned int offsetVect = 0;
254 for (
unsigned int in = 0; in<startParIndexOffDiagonal; in++)
255 if ((in+offsetVect)%(
n-1)==0) offsetVect += (in+offsetVect)/(
n-1);
257 for (
unsigned int in = startParIndexOffDiagonal;
258 in<endParIndexOffDiagonal; in++) {
260 int i = (in+offsetVect)/(
n-1);
261 if ((in+offsetVect)%(
n-1)==0) offsetVect += i;
262 int j = (in+offsetVect)%(
n-1)+1;
264 if ((i+1)==j || in==startParIndexOffDiagonal)
269 double fs1 = mfcn(
x);
270 double elem = (fs1 + amin - yy(i) - yy(j))/(dirin(i)*dirin(j));
275 if (j%(
n-1)==0 || in==endParIndexOffDiagonal-1)
286 std::cout <<
"Original error matrix " << vhmat << std::endl;
292 std::cout <<
"Original error matrix " << vhmat << std::endl;
298 std::cout <<
"PosDef error matrix " << vhmat << std::endl;
302 int ifail =
Invert(vhmat);
307 MN_INFO_MSG(
"MnHesse fails and will return diagonal matrix.");
311 for(
unsigned int j = 0; j <
n; j++) {
312 double tmp = g2(j) < prec.
Eps2() ? 1. : 1./g2(j);
313 tmpsym(j,j) = tmp < prec.
Eps2() ? 1. : tmp;
327 MN_INFO_MSG(
"MnHesse: matrix was forced pos. def. ");
337 std::cout <<
"\nHesse is ACCURATE. New state from MnHesse " << std::endl;
338 std::cout <<
"Gradient " << grd << std::endl;
339 std::cout <<
"Second Deriv " << g2 << std::endl;
340 std::cout <<
"Gradient step " << gst << std::endl;
341 std::cout <<
"Error " << vhmat << std::endl;
342 std::cout <<
"edm " << edm << std::endl;
#define MN_INFO_VAL2(loc, x)
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
virtual double Up() const =0
Error definition of the function.
bool IsAnalytical() const
const MnAlgebraicVector & Gstep() const
const MnAlgebraicVector & Grad() const
const MnAlgebraicVector & G2() const
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
void Add(const MinimumState &state)
const MnUserParameterState & UserState() const
const MinimumState & State() const
HessianGradientCalculator: class to calculate Gradient for Hessian.
Class describing a symmetric matrix of size n.
unsigned int Nrow() const
unsigned int size() const
unsigned int StartElementIndex() const
bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix)
unsigned int EndElementIndex() const
MinimumError keeps the inv.
const MnAlgebraicSymMatrix & InvHessian() const
bool IsMadePosDef() const
const MnAlgebraicVector & Vec() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
const MnAlgebraicVector & Vec() const
const MinimumParameters & Parameters() const
const FunctionGradient & Gradient() const
Wrapper class to FCNBase interface used internally by Minuit.
unsigned int NumOfCalls() const
unsigned int Ncycles() const
forward interface of MnStrategy
MnUserParameterState operator()(const FCNBase &, const std::vector< double > &, const std::vector< double > &, unsigned int maxcalls=0) const
low-level API
determines the relative floating point arithmetic precision.
double Eps2() const
eps2 returns 2*sqrt(eps)
Force the covariance matrix to be positive defined by adding extra terms in the diagonal.
unsigned int Strategy() const
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
Wrapper used by Minuit of FCN interface containing a reference to the transformation object.
class which holds the external user and/or internal Minuit representation of the parameters and error...
unsigned int NFcn() const
unsigned int VariableParameters() const
const std::vector< double > & IntParameters() const
const MnUserTransformation & Trafo() const
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
class performing the numerical gradient calculation
double Estimate(const FunctionGradient &, const MinimumError &) const
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
int Invert(LASymMatrix &)
LASymMatrix MnAlgebraicSymMatrix
Namespace for new ROOT classes and functions.