1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-09-19 21:25:36 +01:00

minimiser interface improvement

This commit is contained in:
Antonin Portelli 2016-04-01 21:39:49 +01:00
parent c294553991
commit ca73ef1269
4 changed files with 50 additions and 26 deletions

View File

@ -49,9 +49,13 @@ void Minimizer::resize(const Index dim)
} }
} }
// limits //////////////////////////////////////////////////////////////////////
double Minimizer::getHighLimit(const Index i) const double Minimizer::getHighLimit(const Index i) const
{ {
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return highLimit_(i); return highLimit_(i);
} }
@ -62,6 +66,11 @@ const DVec & Minimizer::getHighLimit(const PlaceHolder ph __dumb) const
double Minimizer::getLowLimit(const Index i) const double Minimizer::getLowLimit(const Index i) const
{ {
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return lowLimit_(i); return lowLimit_(i);
} }
@ -72,11 +81,21 @@ const DVec & Minimizer::getLowLimit(const PlaceHolder ph __dumb) const
bool Minimizer::hasHighLimit(const Index i) const bool Minimizer::hasHighLimit(const Index i) const
{ {
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return hasHighLimit_(i); return hasHighLimit_(i);
} }
bool Minimizer::hasLowLimit(const Index i) const bool Minimizer::hasLowLimit(const Index i) const
{ {
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return hasLowLimit_(i); return hasLowLimit_(i);
} }
@ -84,7 +103,7 @@ void Minimizer::setHighLimit(const Index i, const double l)
{ {
if (i >= getDim()) if (i >= getDim())
{ {
LATAN_ERROR(Size, "invalid limit index"); resize(i + 1);
} }
else else
{ {
@ -97,7 +116,7 @@ void Minimizer::setHighLimit(const PlaceHolder ph __dumb, const DVec &l)
{ {
if (l.size() != getDim()) if (l.size() != getDim())
{ {
LATAN_ERROR(Size, "invalid limit vector size"); resize(l.size());
} }
else else
{ {
@ -110,7 +129,7 @@ void Minimizer::setLowLimit(const Index i, const double l)
{ {
if (i >= getDim()) if (i >= getDim())
{ {
LATAN_ERROR(Size, "invalid limit index"); resize(i + 1);
} }
else else
{ {
@ -123,7 +142,7 @@ void Minimizer::setLowLimit(const PlaceHolder ph __dumb, const DVec &l)
{ {
if (l.size() != getDim()) if (l.size() != getDim())
{ {
LATAN_ERROR(Size, "invalid limit vector size"); resize(l.size());
} }
else else
{ {
@ -136,7 +155,7 @@ void Minimizer::useHighLimit(const Index i, const bool use)
{ {
if (i >= getDim()) if (i >= getDim())
{ {
LATAN_ERROR(Size, "invalid limit index"); resize(i + 1);
} }
else else
{ {
@ -153,7 +172,7 @@ void Minimizer::useLowLimit(const Index i, const bool use)
{ {
if (i >= getDim()) if (i >= getDim())
{ {
LATAN_ERROR(Size, "invalid limit index"); resize(i + 1);
} }
else else
{ {
@ -165,3 +184,13 @@ void Minimizer::useLowLimit(const PlaceHolder ph __dumb, const bool use)
{ {
hasLowLimit_.fill(use); hasLowLimit_.fill(use);
} }
unsigned int Minimizer::getMaxPass(void) const
{
return maxPass_;
}
void Minimizer::setMaxPass(const unsigned int maxPass)
{
maxPass_ = maxPass;
}

View File

@ -40,8 +40,7 @@ public:
// destructor // destructor
virtual ~Minimizer(void) = default; virtual ~Minimizer(void) = default;
// access // access
virtual void resize(const Index dim); virtual void resize(const Index dim);
// limits
virtual double getHighLimit(const Index i) const ; virtual double getHighLimit(const Index i) const ;
virtual const DVec & getHighLimit(const PlaceHolder ph = _) const; virtual const DVec & getHighLimit(const PlaceHolder ph = _) const;
virtual double getLowLimit(const Index i) const; virtual double getLowLimit(const Index i) const;
@ -58,11 +57,14 @@ public:
virtual void useLowLimit(const Index i, const bool use = true); virtual void useLowLimit(const Index i, const bool use = true);
virtual void useLowLimit(const PlaceHolder ph = _, virtual void useLowLimit(const PlaceHolder ph = _,
const bool use = true); const bool use = true);
virtual unsigned int getMaxPass(void) const;
virtual void setMaxPass(const unsigned int maxPass);
// minimization // minimization
virtual const DVec & operator()(const DoubleFunction &f) = 0; virtual const DVec & operator()(const DoubleFunction &f) = 0;
private: private:
DVec highLimit_, lowLimit_; DVec highLimit_, lowLimit_;
Vec<bool> hasHighLimit_, hasLowLimit_; Vec<bool> hasHighLimit_, hasLowLimit_;
unsigned int maxPass_{5u};
}; };
END_LATAN_NAMESPACE END_LATAN_NAMESPACE

View File

@ -25,8 +25,7 @@
using namespace std; using namespace std;
using namespace Latan; using namespace Latan;
static constexpr double initErr = 0.1; static constexpr double initErr = 0.1;
static constexpr unsigned int maxTry = 10u;
/****************************************************************************** /******************************************************************************
* MinuitMinimizer implementation * * MinuitMinimizer implementation *
@ -137,28 +136,21 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
int status; int status;
unsigned int n = 0; unsigned int n = 0;
if (getVerbosity() >= Verbosity::Normal) min->SetStrategy(2);
{
cout << "========== Minuit minimization, pass #1";
cout << " ==========" << endl;
}
min->SetStrategy(0);
min->Minimize();
do do
{ {
n++;
if (getVerbosity() >= Verbosity::Normal) if (getVerbosity() >= Verbosity::Normal)
{ {
cout << "========== Minuit minimization, pass #" << n + 1; cout << "========== Minuit minimization, pass #" << n + 1;
cout << " ==========" << endl; cout << " =========" << endl;
} }
min->SetStrategy(2);
min->Minimize(); min->Minimize();
status = min->Status(); status = min->Status();
} while (status and (n < maxTry)); n++;
} while (status and (n < getMaxPass()));
if (getVerbosity() >= Verbosity::Normal) if (getVerbosity() >= Verbosity::Normal)
{ {
cout << "======================================" << endl; cout << "=================================================" << endl;
} }
switch (status) switch (status)
{ {

View File

@ -27,7 +27,8 @@
BEGIN_LATAN_NAMESPACE BEGIN_LATAN_NAMESPACE
/****************************************************************************** /******************************************************************************
* interface to CERN Minuit minimizer (http://www.cern.ch/minuit) * * interface to CERN Minuit minimizer *
* ( http://www.cern.ch/minuit ) *
******************************************************************************/ ******************************************************************************/
class MinuitMinimizer: public Minimizer class MinuitMinimizer: public Minimizer
{ {