CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
CascadeMinimizer Class Reference

#include <CascadeMinimizer.h>

Classes

struct  Algo
 compact information about an algorithm More...
 

Public Types

enum  Mode { Constrained, Unconstrained }
 

Public Member Functions

 CascadeMinimizer (RooAbsReal &nll, Mode mode, RooRealVar *poi=0, int initialStrategy=0)
 
bool improve (int verbose=0, bool cascade=true)
 
bool minimize (int verbose=0, bool cascade=true)
 
RooMinimizerOptminimizer ()
 
RooFitResult * save ()
 
void setErrorLevel (float errorLevel)
 
void setStrategy (int strategy)
 
void trivialMinimize (const RooAbsReal &nll, RooRealVar &r, int points=100) const
 

Static Public Member Functions

static void applyOptions (const boost::program_options::variables_map &vm)
 
static void initOptions ()
 
static const
boost::program_options::options_description & 
options ()
 

Protected Member Functions

bool improveOnce (int verbose)
 

Protected Attributes

RooMinimizerOpt minimizer_
 
Mode mode_
 
RooAbsReal & nll_
 
RooRealVar * poi_
 
int strategy_
 

Static Protected Attributes

static std::vector< Algofallbacks_
 list of algorithms to run if the default one fails More...
 
static bool oldFallback_ = true
 don't do old fallback using robustMinimize More...
 
static
boost::program_options::options_description 
options_
 options configured from command line More...
 
static bool poiOnlyFit_
 do first a fit of only the POI More...
 
static bool preScan_
 do a pre-scan More...
 
static bool setZeroPoint_ = true
 do first a fit of only the POI More...
 
static bool singleNuisFit_
 do first a minimization of each nuisance individually More...
 

Detailed Description

Definition at line 11 of file CascadeMinimizer.h.

Member Enumeration Documentation

Enumerator
Constrained 
Unconstrained 

Definition at line 13 of file CascadeMinimizer.h.

Constructor & Destructor Documentation

CascadeMinimizer::CascadeMinimizer ( RooAbsReal &  nll,
Mode  mode,
RooRealVar *  poi = 0,
int  initialStrategy = 0 
)

Definition at line 20 of file CascadeMinimizer.cc.

20  :
21  nll_(nll),
23  mode_(mode),
24  strategy_(initialStrategy),
25  poi_(poi)
26 {
27 }
RooMinimizerOpt minimizer_
RooAbsReal & nll_
RooRealVar * poi_

Member Function Documentation

void CascadeMinimizer::applyOptions ( const boost::program_options::variables_map &  vm)
static

Definition at line 118 of file CascadeMinimizer.cc.

References algo, gather_cfg::cout, CascadeMinimizer::Algo::default_strategy(), CascadeMinimizer::Algo::default_tolerance(), fallbacks_, min, poiOnlyFit_, preScan_, setZeroPoint_, and singleNuisFit_.

119 {
120  using namespace std;
121 
122  preScan_ = vm.count("cminPreScan");
123  poiOnlyFit_ = vm.count("cminPoiOnlyFit");
124  singleNuisFit_ = vm.count("cminSingleNuisFit");
125  setZeroPoint_ = vm.count("cminSetZeroPoint");
126  if (vm.count("cminFallbackAlgo")) {
127  vector<string> falls(vm["cminFallbackAlgo"].as<vector<string> >());
128  for (vector<string>::const_iterator it = falls.begin(), ed = falls.end(); it != ed; ++it) {
129  std::string algo = *it;
130  float tolerance = Algo::default_tolerance();
131  int strategy = Algo::default_strategy();
132  string::size_type idx = std::min(algo.find(";"), algo.find(":"));
133  if (idx != string::npos && idx < algo.length()) {
134  tolerance = atof(algo.substr(idx+1).c_str());
135  algo = algo.substr(0,idx); // DON'T SWAP THESE TWO LINES
136  }
137  idx = algo.find(",");
138  if (idx != string::npos && idx < algo.length()) {
139  // if after the comma there's a number, then it's a strategy
140  if ( '0' <= algo[idx+1] && algo[idx+1] <= '9' ) {
141  strategy = atoi(algo.substr(idx+1).c_str());
142  algo = algo.substr(0,idx); // DON'T SWAP THESE TWO LINES
143  } else {
144  // otherwise, it could be Name,subname,strategy
145  idx = algo.find(",",idx+1);
146  if (idx != string::npos && idx < algo.length()) {
147  strategy = atoi(algo.substr(idx+1).c_str());
148  algo = algo.substr(0,idx); // DON'T SWAP THESE TWO LINES
149  }
150  }
151  }
152  fallbacks_.push_back(Algo(algo, tolerance, strategy));
153  std::cout << "Configured fallback algorithm " << fallbacks_.back().algo <<
154  ", strategy " << fallbacks_.back().strategy <<
155  ", tolerance " << fallbacks_.back().tolerance << std::endl;
156  }
157  }
158  //if (vm.count("cminDefaultIntegratorEpsAbs")) RooAbsReal::defaultIntegratorConfig()->setEpsAbs(vm["cminDefaultIntegratorEpsAbs"].as<double>());
159  //if (vm.count("cminDefaultIntegratorEpsRel")) RooAbsReal::defaultIntegratorConfig()->setEpsRel(vm["cminDefaultIntegratorEpsRel"].as<double>());
160  //if (vm.count("cminDefaultIntegrator1D")) setDefaultIntegrator(RooAbsReal::defaultIntegratorConfig()->method1D(), vm["cminDefaultIntegrator1D"].as<std::string>());
161  //if (vm.count("cminDefaultIntegrator1DOpen")) setDefaultIntegrator(RooAbsReal::defaultIntegratorConfig()->method1DOpen(), vm["cminDefaultIntegrator1DOpen"].as<std::string>());
162  //if (vm.count("cminDefaultIntegrator2D")) setDefaultIntegrator(RooAbsReal::defaultIntegratorConfig()->method2D(), vm["cminDefaultIntegrator2D"].as<std::string>());
163  //if (vm.count("cminDefaultIntegrator2DOpen")) setDefaultIntegrator(RooAbsReal::defaultIntegratorConfig()->method2DOpen(), vm["cminDefaultIntegrator2DOpen"].as<std::string>());
164  //if (vm.count("cminDefaultIntegratorND")) setDefaultIntegrator(RooAbsReal::defaultIntegratorConfig()->methodND(), vm["cminDefaultIntegratorND"].as<std::string>());
165  //if (vm.count("cminDefaultIntegratorNDOpen")) setDefaultIntegrator(RooAbsReal::defaultIntegratorConfig()->methodNDOpen(), vm["cminDefaultIntegratorNDOpen"].as<std::string>());
166 }
static bool poiOnlyFit_
do first a fit of only the POI
static bool preScan_
do a pre-scan
static float default_tolerance()
static int default_strategy()
#define min(a, b)
Definition: mlp_lapack.h:161
uint16_t size_type
static bool singleNuisFit_
do first a minimization of each nuisance individually
static bool setZeroPoint_
do first a fit of only the POI
static std::vector< Algo > fallbacks_
list of algorithms to run if the default one fails
tuple cout
Definition: gather_cfg.py:121
LimitAlgo * algo
Definition: Combine.cc:60
Definition: fakeMenu.h:4
bool CascadeMinimizer::improve ( int  verbose = 0,
bool  cascade = true 
)

Definition at line 29 of file CascadeMinimizer.cc.

References dtNoiseDBValidation_cfg::cerr, cacheutils::CachingSimNLL::clearZeroPoint(), CascadeMinimizer::Algo::default_strategy(), CascadeMinimizer::Algo::default_tolerance(), fallbacks_, improveOnce(), minimizer_, nll_, setZeroPoint_, and strategy_.

Referenced by FitterAlgoBase::doFit(), FitterAlgoBase::findCrossing(), Asymptotic::findExpectedLimitFromCrossing(), Asymptotic::getCLs(), minimize(), ProfileLikelihood::significanceBruteForce(), and ProfileLikelihood::significanceFromScan().

30 {
31  minimizer_.setPrintLevel(verbose-2);
32  minimizer_.setStrategy(strategy_);
33  bool outcome = improveOnce(verbose-2);
34  if (cascade && !outcome && !fallbacks_.empty()) {
35  std::string nominalType(ROOT::Math::MinimizerOptions::DefaultMinimizerType());
36  std::string nominalAlgo(ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo());
37  float nominalTol(ROOT::Math::MinimizerOptions::DefaultTolerance());
38  int nominalStrat(strategy_);
39  if (verbose > 0) std::cerr << "Failed minimization with " << nominalType << "," << nominalAlgo << " and tolerance " << nominalTol << std::endl;
40  for (std::vector<Algo>::const_iterator it = fallbacks_.begin(), ed = fallbacks_.end(); it != ed; ++it) {
41  ProfileLikelihood::MinimizerSentry minimizerConfig(it->algo, it->tolerance != Algo::default_tolerance() ? it->tolerance : nominalTol);
42  int myStrategy = it->strategy; if (myStrategy == Algo::default_strategy()) myStrategy = nominalStrat;
43  if (nominalType != ROOT::Math::MinimizerOptions::DefaultMinimizerType() ||
44  nominalAlgo != ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo() ||
45  nominalTol != ROOT::Math::MinimizerOptions::DefaultTolerance() ||
46  myStrategy != nominalStrat) {
47  if (verbose > 0) std::cerr << "Will fallback to minimization using " << it->algo << ", strategy " << myStrategy << " and tolerance " << it->tolerance << std::endl;
48  minimizer_.setStrategy(myStrategy);
49  outcome = improveOnce(verbose-2);
50  if (outcome) break;
51  }
52  }
53  }
54  if (setZeroPoint_) {
55  cacheutils::CachingSimNLL *simnll = dynamic_cast<cacheutils::CachingSimNLL *>(&nll_);
56  if (simnll) simnll->clearZeroPoint();
57  }
58  return outcome;
59 }
bool improveOnce(int verbose)
static float default_tolerance()
static int default_strategy()
static bool setZeroPoint_
do first a fit of only the POI
RooMinimizerOpt minimizer_
Setup Minimizer configuration on creation, reset the previous one on destruction. ...
RooAbsReal & nll_
static std::vector< Algo > fallbacks_
list of algorithms to run if the default one fails
bool CascadeMinimizer::improveOnce ( int  verbose)
protected

Definition at line 61 of file CascadeMinimizer.cc.

References cacheutils::CachingSimNLL::clearZeroPoint(), minimizer_, nll_, oldFallback_, nllutils::robustMinimize(), cacheutils::CachingSimNLL::setZeroPoint(), setZeroPoint_, and ntuplemaker::status.

Referenced by improve().

62 {
63  std::string myType(ROOT::Math::MinimizerOptions::DefaultMinimizerType());
64  std::string myAlgo(ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo());
65  if (setZeroPoint_) {
66  cacheutils::CachingSimNLL *simnll = dynamic_cast<cacheutils::CachingSimNLL *>(&nll_);
67  if (simnll) {
68  simnll->setZeroPoint();
69  }
70  }
71  bool outcome = false;
72  if (oldFallback_){
74  } else {
75  int status = minimizer_.minimize(myType.c_str(), myAlgo.c_str());
76  outcome = (status == 0);
77  }
78  if (setZeroPoint_) {
79  cacheutils::CachingSimNLL *simnll = dynamic_cast<cacheutils::CachingSimNLL *>(&nll_);
80  if (simnll) simnll->clearZeroPoint();
81  }
82  return outcome;
83 }
bool robustMinimize(RooAbsReal &nll, RooMinimizerOpt &minimizer, int verbosity=0)
static bool oldFallback_
don&#39;t do old fallback using robustMinimize
static bool setZeroPoint_
do first a fit of only the POI
RooMinimizerOpt minimizer_
RooAbsReal & nll_
tuple status
Definition: ntuplemaker.py:245
void CascadeMinimizer::initOptions ( )
static

Definition at line 98 of file CascadeMinimizer.cc.

References oldFallback_, options_, setZeroPoint_, and relativeConstraints::value.

99 {
100  options_.add_options()
101  ("cminPoiOnlyFit", "Do first a fit floating only the parameter of interest")
102  ("cminPreScan", "Do a scan before first minimization")
103  ("cminSingleNuisFit", "Do first a minimization of each nuisance parameter individually")
104  ("cminFallbackAlgo", boost::program_options::value<std::vector<std::string> >(), "Fallback algorithms if the default minimizer fails (can use multiple ones). Syntax is algo[,subalgo][,strategy][:tolerance]")
105  ("cminSetZeroPoint", boost::program_options::value<bool>(&setZeroPoint_)->default_value(setZeroPoint_), "Change the reference point of the NLL to be zero during minimization")
106  ("cminOldRobustMinimize", boost::program_options::value<bool>(&oldFallback_)->default_value(oldFallback_), "Use the old 'robustMinimize' logic in addition to the cascade")
107  //("cminDefaultIntegratorEpsAbs", boost::program_options::value<double>(), "RooAbsReal::defaultIntegratorConfig()->setEpsAbs(x)")
108  //("cminDefaultIntegratorEpsRel", boost::program_options::value<double>(), "RooAbsReal::defaultIntegratorConfig()->setEpsRel(x)")
109  //("cminDefaultIntegrator1D", boost::program_options::value<std::string>(), "RooAbsReal::defaultIntegratorConfig()->method1D().setLabel(x)")
110  //("cminDefaultIntegrator1DOpen", boost::program_options::value<std::string>(), "RooAbsReal::defaultIntegratorConfig()->method1DOpen().setLabel(x)")
111  //("cminDefaultIntegrator2D", boost::program_options::value<std::string>(), "RooAbsReal::defaultIntegratorConfig()->method2D().setLabel(x)")
112  //("cminDefaultIntegrator2DOpen", boost::program_options::value<std::string>(), "RooAbsReal::defaultIntegratorConfig()->method2DOpen().setLabel(x)")
113  //("cminDefaultIntegratorND", boost::program_options::value<std::string>(), "RooAbsReal::defaultIntegratorConfig()->methodND().setLabel(x)")
114  //("cminDefaultIntegratorNDOpen", boost::program_options::value<std::string>(), "RooAbsReal::defaultIntegratorConfig()->methodNDOpen().setLabel(x)")
115  ;
116 }
static bool oldFallback_
don&#39;t do old fallback using robustMinimize
static bool setZeroPoint_
do first a fit of only the POI
static boost::program_options::options_description options_
options configured from command line
bool CascadeMinimizer::minimize ( int  verbose = 0,
bool  cascade = true 
)

Definition at line 85 of file CascadeMinimizer.cc.

References improve(), minimizer_, mode_, nll_, poi_, poiOnlyFit_, preScan_, strategy_, trivialMinimize(), and Unconstrained.

Referenced by MultiDimFit::doContour2D(), FitterAlgoBase::doFit(), MultiDimFit::doGrid(), MultiDimFit::doRandomPoints(), Asymptotic::findExpectedLimitFromCrossing(), BestFitSigmaTestStat::minNLL(), ProfiledLikelihoodTestStatOpt::minNLL(), Asymptotic::runLimit(), ProfileLikelihood::significanceBruteForce(), and ProfileLikelihood::significanceFromScan().

86 {
87  minimizer_.setPrintLevel(verbose-2);
88  minimizer_.setStrategy(strategy_);
89  if (preScan_) minimizer_.minimize("Minuit2","Scan");
90  // FIXME can be made smarter than this
91  if (mode_ == Unconstrained && poiOnlyFit_) {
92  trivialMinimize(nll_, *poi_, 200);
93  }
94  return improve(verbose, cascade);
95 }
static bool poiOnlyFit_
do first a fit of only the POI
static bool preScan_
do a pre-scan
bool improve(int verbose=0, bool cascade=true)
RooMinimizerOpt minimizer_
RooAbsReal & nll_
void trivialMinimize(const RooAbsReal &nll, RooRealVar &r, int points=100) const
RooRealVar * poi_
RooMinimizerOpt& CascadeMinimizer::minimizer ( )
inline

Definition at line 19 of file CascadeMinimizer.h.

References minimizer_.

Referenced by FitterAlgoBase::doFit(), Asymptotic::findExpectedLimitFromCrossing(), and save().

19 { return minimizer_; }
RooMinimizerOpt minimizer_
static const boost::program_options::options_description& CascadeMinimizer::options ( )
inlinestatic

Definition at line 25 of file CascadeMinimizer.h.

References options_.

Referenced by betterConfigParser.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::checkInput(), DOTExport.DotExport::export(), and DOTExport.DotExport::write_output().

25 { return options_; }
static boost::program_options::options_description options_
options configured from command line
RooFitResult* CascadeMinimizer::save ( )
inline
void CascadeMinimizer::setErrorLevel ( float  errorLevel)
inline

Definition at line 22 of file CascadeMinimizer.h.

References minimizer_.

Referenced by FitterAlgoBase::doFit(), and Asymptotic::findExpectedLimitFromCrossing().

22 { minimizer_.setErrorLevel(errorLevel); }
RooMinimizerOpt minimizer_
void CascadeMinimizer::setStrategy ( int  strategy)
inline
void CascadeMinimizer::trivialMinimize ( const RooAbsReal &  nll,
RooRealVar &  r,
int  points = 100 
) const

Definition at line 183 of file CascadeMinimizer.cc.

References i, vdt::x, and detailsBasic3DVector::y.

Referenced by minimize().

183  {
184  double rMin = r.getMin(), rMax = r.getMax(), rStep = (rMax-rMin)/(points-1);
185  int iMin = -1; double minnll = 0;
186  for (int i = 0; i < points; ++i) {
187  double x = rMin + (i+0.5)*rStep;
188  r.setVal(x);
189  double y = nll.getVal();
190  if (iMin == -1 || y < minnll) { minnll = y; iMin = i; }
191  }
192  r.setVal( rMin + (iMin+0.5)*rStep );
193 }
int i
Definition: DBlmapReader.cc:9
x
Definition: VDTMath.h:216

Member Data Documentation

std::vector< CascadeMinimizer::Algo > CascadeMinimizer::fallbacks_
staticprotected

list of algorithms to run if the default one fails

Definition at line 47 of file CascadeMinimizer.h.

Referenced by applyOptions(), and improve().

RooMinimizerOpt CascadeMinimizer::minimizer_
protected

Definition at line 29 of file CascadeMinimizer.h.

Referenced by improve(), improveOnce(), minimize(), minimizer(), and setErrorLevel().

Mode CascadeMinimizer::mode_
protected

Definition at line 30 of file CascadeMinimizer.h.

Referenced by minimize().

RooAbsReal& CascadeMinimizer::nll_
protected

Definition at line 28 of file CascadeMinimizer.h.

Referenced by improve(), improveOnce(), and minimize().

bool CascadeMinimizer::oldFallback_ = true
staticprotected

don't do old fallback using robustMinimize

Definition at line 57 of file CascadeMinimizer.h.

Referenced by improveOnce(), and initOptions().

boost::program_options::options_description CascadeMinimizer::options_
staticprotected

options configured from command line

Definition at line 37 of file CascadeMinimizer.h.

Referenced by initOptions(), options(), and valtools.webpage::parseArgs().

RooRealVar* CascadeMinimizer::poi_
protected

Definition at line 32 of file CascadeMinimizer.h.

Referenced by minimize().

bool CascadeMinimizer::poiOnlyFit_
staticprotected

do first a fit of only the POI

Definition at line 51 of file CascadeMinimizer.h.

Referenced by applyOptions(), and minimize().

bool CascadeMinimizer::preScan_
staticprotected

do a pre-scan

Definition at line 49 of file CascadeMinimizer.h.

Referenced by applyOptions(), and minimize().

bool CascadeMinimizer::setZeroPoint_ = true
staticprotected

do first a fit of only the POI

Definition at line 55 of file CascadeMinimizer.h.

Referenced by applyOptions(), improve(), improveOnce(), and initOptions().

bool CascadeMinimizer::singleNuisFit_
staticprotected

do first a minimization of each nuisance individually

Definition at line 53 of file CascadeMinimizer.h.

Referenced by applyOptions().

int CascadeMinimizer::strategy_
protected

Definition at line 31 of file CascadeMinimizer.h.

Referenced by improve(), minimize(), and setStrategy().