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
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return highLimit_(i);
}
@ -62,6 +66,11 @@ const DVec & Minimizer::getHighLimit(const PlaceHolder ph __dumb) const
double Minimizer::getLowLimit(const Index i) const
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return lowLimit_(i);
}
@ -72,11 +81,21 @@ const DVec & Minimizer::getLowLimit(const PlaceHolder ph __dumb) const
bool Minimizer::hasHighLimit(const Index i) const
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return hasHighLimit_(i);
}
bool Minimizer::hasLowLimit(const Index i) const
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid variable index");
}
return hasLowLimit_(i);
}
@ -84,7 +103,7 @@ void Minimizer::setHighLimit(const Index i, const double l)
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid limit index");
resize(i + 1);
}
else
{
@ -97,7 +116,7 @@ void Minimizer::setHighLimit(const PlaceHolder ph __dumb, const DVec &l)
{
if (l.size() != getDim())
{
LATAN_ERROR(Size, "invalid limit vector size");
resize(l.size());
}
else
{
@ -110,7 +129,7 @@ void Minimizer::setLowLimit(const Index i, const double l)
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid limit index");
resize(i + 1);
}
else
{
@ -123,7 +142,7 @@ void Minimizer::setLowLimit(const PlaceHolder ph __dumb, const DVec &l)
{
if (l.size() != getDim())
{
LATAN_ERROR(Size, "invalid limit vector size");
resize(l.size());
}
else
{
@ -136,7 +155,7 @@ void Minimizer::useHighLimit(const Index i, const bool use)
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid limit index");
resize(i + 1);
}
else
{
@ -153,7 +172,7 @@ void Minimizer::useLowLimit(const Index i, const bool use)
{
if (i >= getDim())
{
LATAN_ERROR(Size, "invalid limit index");
resize(i + 1);
}
else
{
@ -165,3 +184,13 @@ void Minimizer::useLowLimit(const PlaceHolder ph __dumb, const bool 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
virtual ~Minimizer(void) = default;
// access
virtual void resize(const Index dim);
// limits
virtual void resize(const Index dim);
virtual double getHighLimit(const Index i) const ;
virtual const DVec & getHighLimit(const PlaceHolder ph = _) 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 PlaceHolder ph = _,
const bool use = true);
virtual unsigned int getMaxPass(void) const;
virtual void setMaxPass(const unsigned int maxPass);
// minimization
virtual const DVec & operator()(const DoubleFunction &f) = 0;
private:
DVec highLimit_, lowLimit_;
Vec<bool> hasHighLimit_, hasLowLimit_;
DVec highLimit_, lowLimit_;
Vec<bool> hasHighLimit_, hasLowLimit_;
unsigned int maxPass_{5u};
};
END_LATAN_NAMESPACE

View File

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

View File

@ -27,7 +27,8 @@
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
{