24 #if defined(DEBUG) || defined(WARNINGMSG) 27 #if defined(DEBUG) && !defined(WARNINGMSG) 69 for(
unsigned int i = 0; i < n; i++)
x(i) = state.
IntParameters()[i];
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;
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;
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 &)
double Estimate(const FunctionGradient &, const MinimumError &) const
Namespace for new ROOT classes and functions.
const MnAlgebraicVector & Vec() const
Force the covariance matrix to be positive defined by adding extra terms in the diagonal.
Class describing a symmetric matrix of size n.
unsigned int Strategy() const
unsigned int EndElementIndex() const
const std::vector< double > & IntParameters() const
unsigned int NFcn() const
determines the relative floating point arithmetic precision.
unsigned int NumOfCalls() const
LASymMatrix MnAlgebraicSymMatrix
unsigned int VariableParameters() const
bool IsAnalytical() const
class performing the numerical gradient calculation
const FunctionGradient & Gradient() const
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
unsigned int StartElementIndex() const
const MnAlgebraicVector & G2() const
const MinimumState & State() const
Wrapper class to FCNBase interface used internally by Minuit.
const MnUserTransformation & Trafo() const
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
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)
unsigned int Nrow() const
class which holds the external user and/or internal Minuit representation of the parameters and error...
unsigned int size() const
const MnAlgebraicVector & Gstep() const
* x
Deprecated and error prone model selection interface.
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 MinimumParameters & Parameters() const
const MnAlgebraicVector & Grad() const
double Eps2() const
eps2 returns 2*sqrt(eps)
MinimumError keeps the inv.
MnUserParameterState operator()(const FCNBase &, const std::vector< double > &, const std::vector< double > &, unsigned int maxcalls=0) const
low-level API
bool SyncSymMatrixOffDiagonal(ROOT::Minuit2::MnAlgebraicSymMatrix &mnmatrix)
bool IsMadePosDef() const
unsigned int Ncycles() const
forward interface of MnStrategy
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
const MnUserParameterState & UserState() const
const MnAlgebraicVector & Vec() const
const MnAlgebraicSymMatrix & InvHessian() const
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...