1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-14 01:45:35 +00:00

DoubleModel: bind to a constant parameter set into a DoubleFunction

This commit is contained in:
Antonin Portelli 2014-03-03 17:01:07 +00:00
parent 15fa3f0354
commit 2b678ac72a
5 changed files with 37 additions and 17 deletions

View File

@ -45,15 +45,13 @@ public:
virtual Index getNArg(void) const; virtual Index getNArg(void) const;
void setFunction(const vecFunc &f, const Index nArg); void setFunction(const vecFunc &f, const Index nArg);
// function call // function call
virtual double operator()(const double *arg) const;
double operator()(const DVec &arg) const; double operator()(const DVec &arg) const;
double operator()(const std::vector<double> &arg) const; double operator()(const std::vector<double> &arg) const;
double operator()(std::stack<double> &arg) const; double operator()(std::stack<double> &arg) const;
double operator()(void) const; double operator()(void) const;
template <typename... Ts> template <typename... Ts>
double operator()(const double arg0, const Ts... args) const; double operator()(const double arg0, const Ts... args) const;
protected:
// function call
virtual double operator()(const double *arg) const;
private: private:
// error checking // error checking
void checkSize(const Index nPar) const; void checkSize(const Index nPar) const;

View File

@ -19,8 +19,10 @@
#include <latan/Model.hpp> #include <latan/Model.hpp>
#include <latan/includes.hpp> #include <latan/includes.hpp>
#include <functional>
using namespace std; using namespace std;
using namespace std::placeholders;
using namespace Latan; using namespace Latan;
/****************************************************************************** /******************************************************************************
@ -89,3 +91,13 @@ double DoubleModel::operator()(const double *data, const double *par) const
{ {
return f_(data, par); 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);
}

View File

@ -21,6 +21,7 @@
#define Latan_Model_hpp_ #define Latan_Model_hpp_
#include <latan/Global.hpp> #include <latan/Global.hpp>
#include <latan/Function.hpp>
#include <latan/Mat.hpp> #include <latan/Mat.hpp>
#include <vector> #include <vector>
@ -49,9 +50,9 @@ public:
double operator()(const DVec &data, const DVec &par) const; double operator()(const DVec &data, const DVec &par) const;
double operator()(const std::vector<double> &data, double operator()(const std::vector<double> &data,
const std::vector<double> &par) const; const std::vector<double> &par) const;
protected:
// function call
virtual double operator()(const double *data, const double *par) const; virtual double operator()(const double *data, const double *par) const;
// model bind
DoubleFunction getBind(const DVec &par) const;
private: private:
// error checking // error checking
void checkSize(const Index nArg, const Index nPar) const; void checkSize(const Index nArg, const Index nPar) const;

View File

@ -37,6 +37,11 @@ double FitResult::getChi2PerDof(void) const
return chi2_/static_cast<double>(nDof_); return chi2_/static_cast<double>(nDof_);
} }
const DoubleFunction & FitResult::getModel(const Index j) const
{
return model_[static_cast<unsigned int>(j)];
}
/****************************************************************************** /******************************************************************************
* XYStatData implementation * * XYStatData implementation *
******************************************************************************/ ******************************************************************************/
@ -257,6 +262,11 @@ FitResult XYStatData::fit(const vector<const DoubleModel *> &modelVector,
result = minimizer(chi2_); result = minimizer(chi2_);
result.chi2_ = chi2_(result); result.chi2_ = chi2_(result);
result.nDof_ = chi2_.getNDof(); 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; return result;
} }

View File

@ -26,6 +26,7 @@
#include <latan/Mat.hpp> #include <latan/Mat.hpp>
#include <latan/Minimizer.hpp> #include <latan/Minimizer.hpp>
#include <latan/Model.hpp> #include <latan/Model.hpp>
#include <vector>
BEGIN_NAMESPACE BEGIN_NAMESPACE
@ -44,9 +45,11 @@ public:
// access // access
double getChi2(void) const; double getChi2(void) const;
double getChi2PerDof(void) const; double getChi2PerDof(void) const;
const DoubleFunction & getModel(const Index j = 0) const;
private: private:
double chi2_{0.0}; double chi2_{0.0};
Index nDof_{0}; Index nDof_{0};
std::vector<DoubleFunction> model_;
}; };
/****************************************************************************** /******************************************************************************
@ -114,10 +117,6 @@ private:
Chi2Function chi2_; Chi2Function chi2_;
}; };
/******************************************************************************
* XYStatData template implementation *
******************************************************************************/
END_NAMESPACE END_NAMESPACE
#endif // Latan_XYData_hpp_ #endif // Latan_XYData_hpp_