mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
Merge branch 'master' of github.com:aportelli/LatAnalyze3
This commit is contained in:
commit
aa1ae67b60
@ -34,7 +34,7 @@ int main(void)
|
||||
// fit
|
||||
DVec init = DVec::Constant(2, 0.5);
|
||||
FitResult p;
|
||||
MinuitMinimizer minimizer(2);
|
||||
MinuitMinimizer minimizer;
|
||||
|
||||
data.fitAllPoints();
|
||||
p = data.fit(minimizer, init, f);
|
||||
|
@ -18,7 +18,7 @@ int main(int argc, char* argv[])
|
||||
source = argv[1];
|
||||
|
||||
DoubleFunction f = compile(source, 1);
|
||||
MinuitMinimizer minimize(1);
|
||||
MinuitMinimizer minimize;
|
||||
DVec init(1);
|
||||
double min;
|
||||
|
||||
|
@ -11,7 +11,7 @@ int main(void)
|
||||
DoubleFunction f1([a](const double *x){return a*(1.-x[0]);}, 2);
|
||||
DoubleFunction f2([b](const double *x){return b*(x[1]-x[0]*x[0]);}, 2);
|
||||
vector<DoubleFunction *> system = {&f1, &f2};
|
||||
GslHybridRootFinder solve(2);
|
||||
GslHybridRootFinder solve;
|
||||
DVec init(2), x;
|
||||
|
||||
solve.setVerbosity(Solver::Verbosity::Debug);
|
||||
|
@ -95,7 +95,7 @@ GslHybridRootFinder::operator()(const vector<DoubleFunction *> &func)
|
||||
}
|
||||
if (res.size() != nArg)
|
||||
{
|
||||
res.conservativeResize(nArg);
|
||||
resize(nArg);
|
||||
}
|
||||
solver_ = gsl_multiroot_fsolver_alloc(gsl_multiroot_fsolver_hybrids, nFunc);
|
||||
x = gsl_vector_alloc(nFunc);
|
||||
|
@ -33,7 +33,8 @@ BEGIN_LATAN_NAMESPACE
|
||||
class GslHybridRootFinder: public RootFinder
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
// constructors
|
||||
GslHybridRootFinder(void) = default;
|
||||
explicit GslHybridRootFinder(const Index dim);
|
||||
// destructor
|
||||
virtual ~GslHybridRootFinder(void) = default;
|
||||
|
@ -26,15 +26,18 @@ using namespace Latan;
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Minimizer::Minimizer(const Index dim)
|
||||
: Solver(dim)
|
||||
, highLimit_(dim)
|
||||
, lowLimit_(dim)
|
||||
, hasHighLimit_(dim)
|
||||
, hasLowLimit_(dim)
|
||||
{
|
||||
highLimit_.fill(0.);
|
||||
lowLimit_.fill(0.);
|
||||
hasHighLimit_.fill(false);
|
||||
hasLowLimit_.fill(false);
|
||||
resize(dim);
|
||||
}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
void Minimizer::resize(const Index dim)
|
||||
{
|
||||
Solver::resize(dim);
|
||||
highLimit_.conservativeResize(dim);
|
||||
lowLimit_.conservativeResize(dim);
|
||||
hasHighLimit_.conservativeResize(dim);
|
||||
hasLowLimit_.conservativeResize(dim);
|
||||
}
|
||||
|
||||
// limits //////////////////////////////////////////////////////////////////////
|
||||
|
@ -35,9 +35,12 @@ class Minimizer: public Solver
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Minimizer(void) = default;
|
||||
explicit Minimizer(const Index dim);
|
||||
// destructor
|
||||
virtual ~Minimizer(void) = default;
|
||||
// access
|
||||
virtual void resize(const Index dim);
|
||||
// limits
|
||||
virtual double getHighLimit(const Index i) const ;
|
||||
virtual const DVec & getHighLimit(const PlaceHolder ph = _) const;
|
||||
|
@ -61,11 +61,17 @@ double MinuitMinimizer::MinuitFunction::Up(void) const
|
||||
return 1.;
|
||||
}
|
||||
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
// constructors ////////////////////////////////////////////////////////////////
|
||||
MinuitMinimizer::MinuitMinimizer(const Algorithm algorithm)
|
||||
{
|
||||
setAlgorithm(algorithm);
|
||||
}
|
||||
|
||||
MinuitMinimizer::MinuitMinimizer(const Index dim, const Algorithm algorithm)
|
||||
: Minimizer(dim)
|
||||
, algorithm_(algorithm)
|
||||
{}
|
||||
{
|
||||
setAlgorithm(algorithm);
|
||||
}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
MinuitMinimizer::Algorithm MinuitMinimizer::getAlgorithm(void) const
|
||||
@ -100,7 +106,7 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
|
||||
|
||||
if (f.getNArg() != x.size())
|
||||
{
|
||||
LATAN_ERROR(Size, "function to minimize number of arguments mismatch");
|
||||
resize(f.getNArg());
|
||||
}
|
||||
|
||||
// set parameters
|
||||
|
@ -54,7 +54,8 @@ private:
|
||||
const DoubleFunction *f_;
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
// constructors
|
||||
MinuitMinimizer(const Algorithm algorithm = Algorithm::Migrad);
|
||||
explicit MinuitMinimizer(const Index dim,
|
||||
const Algorithm algorithm = Algorithm::Migrad);
|
||||
// destructor
|
||||
|
@ -33,7 +33,8 @@ BEGIN_LATAN_NAMESPACE
|
||||
class RootFinder: public Solver
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
// constructors
|
||||
RootFinder(void) = default;
|
||||
explicit RootFinder(const Index dim);
|
||||
// destructor
|
||||
virtual ~RootFinder(void) = default;
|
||||
|
@ -26,15 +26,20 @@ using namespace Latan;
|
||||
/******************************************************************************
|
||||
* Solver implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Solver::Solver(const Index dim, const double precision,
|
||||
const unsigned int maxIteration)
|
||||
: x_(dim)
|
||||
// constructors ////////////////////////////////////////////////////////////////
|
||||
Solver::Solver(const double precision, const unsigned int maxIteration)
|
||||
{
|
||||
setMaxIteration(maxIteration);
|
||||
setPrecision(precision);
|
||||
}
|
||||
|
||||
Solver::Solver(const Index dim, const double precision,
|
||||
const unsigned int maxIteration)
|
||||
: Solver(precision, maxIteration)
|
||||
{
|
||||
resize(dim);
|
||||
}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
Index Solver::getDim(void) const
|
||||
{
|
||||
@ -65,12 +70,9 @@ void Solver::setInit(const DVec &x0)
|
||||
{
|
||||
if (x0.size() != x_.size())
|
||||
{
|
||||
LATAN_ERROR(Size, "initial vector state with invalid size");
|
||||
}
|
||||
else
|
||||
{
|
||||
x_ = x0;
|
||||
resize(x0.size());
|
||||
}
|
||||
x_ = x0;
|
||||
}
|
||||
|
||||
void Solver::setMaxIteration(const unsigned int maxIteration)
|
||||
@ -87,3 +89,8 @@ void Solver::setVerbosity(const Verbosity verbosity)
|
||||
{
|
||||
verbosity_ = verbosity;
|
||||
}
|
||||
|
||||
void Solver::resize(const Index dim)
|
||||
{
|
||||
x_.resize(dim);
|
||||
}
|
||||
|
@ -41,7 +41,9 @@ public:
|
||||
Debug = 2
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
// constructors
|
||||
Solver(const double precision = defaultPrec,
|
||||
const unsigned int maxIteration = defaultMaxIteration);
|
||||
explicit Solver(const Index dim, const double precision = defaultPrec,
|
||||
const unsigned int maxIteration = defaultMaxIteration);
|
||||
// destructor
|
||||
@ -55,6 +57,7 @@ public:
|
||||
virtual void setPrecision(const double precision);
|
||||
virtual void setMaxIteration(const unsigned int maxIteration);
|
||||
void setVerbosity(const Verbosity verbosity);
|
||||
virtual void resize(const Index dim);
|
||||
protected:
|
||||
// access
|
||||
DVec & getState(void);
|
||||
|
Loading…
Reference in New Issue
Block a user