46 result.push_back(state);
53 MnPrint::PrintState(std::cout, result.back(),
"VariableMetric: Iteration # ",result.size()-1);
73 std::cout<<
"VariableMetricBuilder convergence when edm < "<<edmval<<std::endl;
88 MN_INFO_MSG(
"VariableMetricBuilder: initial matrix not pos.def.");
94 std::vector<MinimumState>
result;
103 std::cout <<
"VariableMetric: start iterating until Edm is < " << edmval << std::endl;
111 int maxfcn_eff = maxfcn;
120 std::cout <<
"start iterating... " << std::endl;
121 if (ipass > 0) std::cout <<
"continue iterating... " << std::endl;
124 min =
Minimum(fcn, gc, seed, result, maxfcn_eff, edmval);
127 if ( min.HasReachedCallLimit() ) {
129 MN_INFO_MSG(
"VariableMetricBuilder: FunctionMinimum is invalid, reached the function call limit");
138 MN_INFO_MSG(
"VariableMetricBuilder: FunctionMinimum is invalid after second try");
145 edm = result.back().Edm();
149 (strategy.
Strategy() == 1 && min.Error().Dcovar() > 0.05) ) {
152 std::cout<<
"MnMigrad will verify convergence and Error matrix. "<< std::endl;
153 std::cout<<
"dcov is = "<< min.Error().Dcovar() << std::endl;
158 if (printLevel > 1) {
166 std::cout <<
"edm after Hesse calculation " << edm <<
" requested " << edmval << std::endl;
171 if (edm >= machineLimit) {
174 MN_INFO_MSG(
"VariableMetricBuilder: Tolerance is not sufficient, continue the minimization");
181 MN_INFO_MSG(
"VariableMetricBuilder: Stop the minimization - reached machine accuracy limit");
182 MN_INFO_VAL2(
"Edm is smaller than machine accuracy",machineLimit);
198 if (ipass == 0) maxfcn_eff = int(maxfcn*1.3);
205 if (edm > 10*edmval) {
208 MN_INFO_VAL2(
"VariableMetricBuilder: INVALID function minimum - edm is above tolerance,",edm);
209 MN_INFO_VAL2(
"VariableMetricBuilder: Required tolerance is 10 x edmval ",edmval);
215 if ( min.IsAboveMaxEdm() ) {
216 MN_INFO_MSG(
"VariableMetricBuilder: Edm has been re-computed after Hesse");
217 MN_INFO_VAL2(
"new value is now smaller than the required tolerance,",edm);
220 min.Add( result.back() );
224 std::cout <<
"Obtained function minimum " << min << std::endl;
246 double edm = initialState.
Edm();
250 std::cout <<
"\n\nDEBUG Variable Metric Builder \nInitial State: " 251 <<
" Parameter " << initialState.
Vec()
254 <<
" edm = " << initialState.
Edm() << std::endl;
267 assert(s0.IsValid() );
273 step = -1.*s0.Error().InvHessian()*s0.Gradient().Vec();
276 std::cout <<
"\n\n---> Iteration - " << result.size()
277 <<
"\nFval = " << s0.Fval() <<
" numOfCall = " << fcn.
NumOfCalls()
278 <<
"\nInternal Parameter values " << s0.Vec()
279 <<
" Newton step " << step << std::endl;
283 if (
inner_product(s0.Gradient().Vec(),s0.Gradient().Vec() ) <= 0 ) {
285 std::cout <<
"VariableMetricBuilder: all derivatives are zero - return current status" << std::endl;
294 std::cout <<
" gdel = " << gdel << std::endl;
300 MN_INFO_MSG(
"VariableMetricBuilder: matrix not pos.def, gdel > 0");
323 if(
fabs(pp.Y() - s0.Fval()) <=
fabs(s0.Fval())*prec.
Eps() ) {
325 MN_INFO_MSG(
"VariableMetricBuilder: no improvement in line search");
329 if (result.size() <= 1 )
341 std::cout <<
"Result after line search : \nx = " << pp.X()
342 <<
"\nOld Fval = " << s0.Fval()
343 <<
"\nNew Fval = " << pp.Y()
344 <<
"\nNFcalls = " << fcn.
NumOfCalls() << std::endl;
358 MN_INFO_MSG(
"VariableMetricBuilder: matrix not pos.def. : edm is < 0. Make pos def...");
365 MN_INFO_MSG(
"VariableMetricBuilder: matrix still not pos.def. : exit iterations ");
375 std::cout <<
"Updated new point: \n " 376 <<
" Parameter " << p.Vec()
377 <<
" Gradient " << g.Vec()
378 <<
" InvHessian " << e.
Matrix()
379 <<
" Hessian " << e.Hessian()
380 <<
" edm = " << edm << std::endl << std::endl;
392 edm *= (1. + 3.*e.Dcovar());
395 std::cout <<
"Dcovar = " << e.Dcovar() <<
"\tCorrected edm = " << edm << std::endl;
400 }
while(edm > edmval && fcn.
NumOfCalls() < maxfcn);
403 if ( ! result.back().IsValid() )
409 MN_INFO_MSG(
"VariableMetricBuilder: call limit exceeded.");
415 if(edm <
fabs(prec.
Eps2()*result.back().Fval())) {
417 MN_INFO_MSG(
"VariableMetricBuilder: machine accuracy limits further improvement.");
420 }
else if(edm < 10*edmval) {
424 MN_INFO_MSG(
"VariableMetricBuilder: iterations finish without convergence.");
434 std::cout <<
"Exiting successfully Variable Metric Builder \n" 436 <<
"\nFval = " << result.back().Fval()
437 <<
"\nedm = " << edm <<
" requested = " << edmval << std::endl;
#define MN_INFO_VAL2(loc, x)
int iterate(rng_state_t *X)
double Estimate(const FunctionGradient &, const MinimumError &) const
Namespace for new ROOT classes and functions.
const MnAlgebraicVector & Vec() const
double Eps() const
eps returns the smallest possible number so that 1.+eps > 1.
Force the covariance matrix to be positive defined by adding extra terms in the diagonal.
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
unsigned int Strategy() const
const MnAlgebraicVector & Vec() const
double inner_product(const LAVector &, const LAVector &)
const MnMachinePrecision & Precision() const
determines the relative floating point arithmetic precision.
unsigned int NumOfCalls() const
const MinimumState & State() const
const MinimumParameters & Parameters() const
virtual FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, const MnStrategy &, unsigned int, double) const
const FunctionGradient & Gradient() const
const DavidonErrorUpdator & ErrorUpdator() const
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
API class for calculating the numerical covariance matrix (== 2x Inverse Hessian == 2x Inverse 2nd de...
static void PrintState(std::ostream &os, const MinimumState &state, const char *msg, int iter=-1)
Wrapper class to FCNBase interface used internally by Minuit.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
MnAlgebraicSymMatrix Matrix() const
unsigned int size() const
void AddResult(std::vector< MinimumState > &result, const MinimumState &state) const
const MinimumError & Error() const
virtual MinimumError Update(const MinimumState &, const MinimumParameters &, const FunctionGradient &) const
const MnAlgebraicVector & Grad() const
double Eps2() const
eps2 returns 2*sqrt(eps)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
MinimumError keeps the inv.
void TraceIteration(int iter, const MinimumState &state) const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Implements a 1-dimensional minimization along a given direction (i.e.
const VariableMetricEDMEstimator & Estimator() const
interface class for gradient calculators
const MnAlgebraicVector & Vec() const
const MnAlgebraicSymMatrix & InvHessian() const