mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
DoubleModel: bind to a constant parameter set into a DoubleFunction
This commit is contained in:
parent
15fa3f0354
commit
2b678ac72a
@ -45,15 +45,13 @@ public:
|
||||
virtual Index getNArg(void) const;
|
||||
void setFunction(const vecFunc &f, const Index nArg);
|
||||
// function call
|
||||
virtual double operator()(const double *arg) const;
|
||||
double operator()(const DVec &arg) const;
|
||||
double operator()(const std::vector<double> &arg) const;
|
||||
double operator()(std::stack<double> &arg) const;
|
||||
double operator()(void) const;
|
||||
template <typename... Ts>
|
||||
double operator()(const double arg0, const Ts... args) const;
|
||||
protected:
|
||||
// function call
|
||||
virtual double operator()(const double *arg) const;
|
||||
private:
|
||||
// error checking
|
||||
void checkSize(const Index nPar) const;
|
||||
|
@ -19,8 +19,10 @@
|
||||
|
||||
#include <latan/Model.hpp>
|
||||
#include <latan/includes.hpp>
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
using namespace Latan;
|
||||
|
||||
/******************************************************************************
|
||||
@ -89,3 +91,13 @@ double DoubleModel::operator()(const double *data, const double *par) const
|
||||
{
|
||||
return f_(data, par);
|
||||
}
|
||||
|
||||
// model bind //////////////////////////////////////////////////////////////////
|
||||
DoubleFunction DoubleModel::getBind(const DVec &par) const
|
||||
{
|
||||
auto modelWithVec = [this](const double *_arg, const DVec &_par)
|
||||
{return (*this)(_arg, _par.data());};
|
||||
auto modelBind = bind(modelWithVec, _1, par);
|
||||
|
||||
return DoubleFunction(getNArg(), modelBind);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define Latan_Model_hpp_
|
||||
|
||||
#include <latan/Global.hpp>
|
||||
#include <latan/Function.hpp>
|
||||
#include <latan/Mat.hpp>
|
||||
#include <vector>
|
||||
|
||||
@ -33,7 +34,7 @@ class DoubleModel
|
||||
{
|
||||
private:
|
||||
typedef std::function<double(const double *, const double *)> vecFunc;
|
||||
struct ModelSize {Index nArg, nPar;};
|
||||
struct ModelSize{Index nArg, nPar;};
|
||||
public:
|
||||
// constructor
|
||||
DoubleModel(const Index nArg = 0, const Index nPar = 0,
|
||||
@ -49,9 +50,9 @@ public:
|
||||
double operator()(const DVec &data, const DVec &par) const;
|
||||
double operator()(const std::vector<double> &data,
|
||||
const std::vector<double> &par) const;
|
||||
protected:
|
||||
// function call
|
||||
virtual double operator()(const double *data, const double *par) const;
|
||||
// model bind
|
||||
DoubleFunction getBind(const DVec &par) const;
|
||||
private:
|
||||
// error checking
|
||||
void checkSize(const Index nArg, const Index nPar) const;
|
||||
|
@ -37,6 +37,11 @@ double FitResult::getChi2PerDof(void) const
|
||||
return chi2_/static_cast<double>(nDof_);
|
||||
}
|
||||
|
||||
const DoubleFunction & FitResult::getModel(const Index j) const
|
||||
{
|
||||
return model_[static_cast<unsigned int>(j)];
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* XYStatData implementation *
|
||||
******************************************************************************/
|
||||
@ -254,9 +259,14 @@ FitResult XYStatData::fit(const vector<const DoubleModel *> &modelVector,
|
||||
// fit
|
||||
FitResult result;
|
||||
|
||||
result = minimizer(chi2_);
|
||||
result.chi2_ = chi2_(result);
|
||||
result.nDof_ = chi2_.getNDof();
|
||||
result = minimizer(chi2_);
|
||||
result.chi2_ = chi2_(result);
|
||||
result.nDof_ = chi2_.getNDof();
|
||||
result.model_.resize(modelVector.size());
|
||||
for (unsigned int j = 0; j < modelVector.size(); ++j)
|
||||
{
|
||||
result.model_[j] = modelVector[j]->getBind(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <latan/Mat.hpp>
|
||||
#include <latan/Minimizer.hpp>
|
||||
#include <latan/Model.hpp>
|
||||
#include <vector>
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
@ -42,11 +43,13 @@ public:
|
||||
// destructor
|
||||
virtual ~FitResult(void) = default;
|
||||
// access
|
||||
double getChi2(void) const;
|
||||
double getChi2PerDof(void) const;
|
||||
double getChi2(void) const;
|
||||
double getChi2PerDof(void) const;
|
||||
const DoubleFunction & getModel(const Index j = 0) const;
|
||||
private:
|
||||
double chi2_{0.0};
|
||||
Index nDof_{0};
|
||||
double chi2_{0.0};
|
||||
Index nDof_{0};
|
||||
std::vector<DoubleFunction> model_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
@ -114,10 +117,6 @@ private:
|
||||
Chi2Function chi2_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* XYStatData template implementation *
|
||||
******************************************************************************/
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
#endif // Latan_XYData_hpp_
|
||||
|
Loading…
Reference in New Issue
Block a user