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;
178 MN_INFO_VAL2(
"MnHesse: 2nd derivative zero for Parameter ", name);
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;
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;
250 unsigned int endParIndexOffDiagonal = mpiprocOffDiagonal.
EndElementIndex();
252 unsigned int offsetVect = 0;
253 for (
unsigned int in = 0; in<startParIndexOffDiagonal; in++)
254 if ((in+offsetVect)%(n-1)==0) offsetVect += (in+offsetVect)/(n-1);
256 for (
unsigned int in = startParIndexOffDiagonal;
257 in<endParIndexOffDiagonal; in++) {
259 int i = (in+offsetVect)/(n-1);
260 if ((in+offsetVect)%(n-1)==0) offsetVect += i;
261 int j = (in+offsetVect)%(n-1)+1;
263 if ((i+1)==j || in==startParIndexOffDiagonal)
268 double fs1 = mfcn(x);
269 double elem = (fs1 + amin - yy(i) - yy(j))/(dirin(i)*dirin(j));
274 if (j%(n-1)==0 || in==endParIndexOffDiagonal-1)
284 std::cout <<
"Original error matrix " << vhmat << std::endl;
290 std::cout <<
"Original error matrix " << vhmat << std::endl;
296 std::cout <<
"PosDef error matrix " << vhmat << std::endl;
300 int ifail =
Invert(vhmat);
305 MN_INFO_MSG(
"MnHesse fails and will return diagonal matrix.");
309 for(
unsigned int j = 0; j <
n; j++) {
310 double tmp =
g2(j) < prec.
Eps2() ? 1. : 1./
g2(j);
311 tmpsym(j,j) = tmp < prec.
Eps2() ? 1. : tmp;
323 double edm = estim.
Estimate(gr, err);
325 MN_INFO_MSG(
"MnHesse: matrix was forced pos. def. ");
332 double edm = estim.
Estimate(gr, err);
335 std::cout <<
"\nHesse is ACCURATE. New state from MnHesse " << std::endl;
336 std::cout <<
"Gradient " << grd << std::endl;
337 std::cout <<
"Second Deriv " << g2 << std::endl;
338 std::cout <<
"Gradient step " << gst << std::endl;
339 std::cout <<
"Error " << vhmat << std::endl;
340 std::cout <<
"edm " << edm << std::endl;
void Add(const MinimumState &state)
virtual double Up() const =0
Error definition of the function.
#define MN_INFO_VAL2(loc, x)
int Invert(LASymMatrix &)
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
MnUserParameterState operator()(const FCNBase &, const std::vector< double > &, const std::vector< double > &, unsigned int maxcalls=0) const
low-level API
void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
unsigned int Ncycles() const
forward interface of MnStrategy
unsigned int VariableParameters() const
bool IsAnalytical() const
Force the covariance matrix to be positive defined by adding extra terms in the diagonal.
unsigned int size() const
Class describing a symmetric matrix of size n.
unsigned int Nrow() const
const MnUserParameterState & UserState() const
determines the relative floating point arithmetic precision.
const FunctionGradient & Gradient() const
const MnUserTransformation & Trafo() const
LASymMatrix MnAlgebraicSymMatrix
unsigned int NFcn() const
unsigned int StartElementIndex() const
class performing the numerical gradient calculation
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
const MnAlgebraicVector & Vec() const
Wrapper class to FCNBase interface used internally by Minuit.
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
const MnAlgebraicVector & Vec() const
const MinimumState & State() const
HessianGradientCalculator: class to calculate Gradient for Hessian.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
double Eps2() const
eps2 returns 2*sqrt(eps)
bool IsMadePosDef() const
class which holds the external user and/or internal Minuit representation of the parameters and error...
double Estimate(const FunctionGradient &, const MinimumError &) const
const std::vector< double > & IntParameters() const
unsigned int Strategy() const
Wrapper used by Minuit of FCN interface containing a reference to the transformation object...
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
const MnAlgebraicVector & Gstep() const
const MnAlgebraicSymMatrix & InvHessian() const
const MinimumParameters & Parameters() const
const MnAlgebraicVector & Grad() const
unsigned int EndElementIndex() const
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
MinimumError keeps the inv.
bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix)
unsigned int NumOfCalls() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
const MnAlgebraicVector & G2() const
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...