1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-09-20 05:25:37 +01:00
LatAnalyze/lib/Chi2Function.hpp

81 lines
2.7 KiB
C++
Raw Normal View History

2014-03-03 12:41:48 +00:00
/*
* Chi2Function.hpp, part of LatAnalyze 3
*
2015-06-11 14:04:54 +01:00
* Copyright (C) 2013 - 2015 Antonin Portelli
2014-03-03 12:41:48 +00:00
*
* LatAnalyze 3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze 3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Latan_Chi2Function_hpp_
#define Latan_Chi2Function_hpp_
2014-03-13 18:51:01 +00:00
#include <LatAnalyze/Global.hpp>
#include <LatAnalyze/Function.hpp>
#include <LatAnalyze/Model.hpp>
2014-03-03 12:41:48 +00:00
BEGIN_LATAN_NAMESPACE
2014-03-03 12:41:48 +00:00
/******************************************************************************
* <Class> *
******************************************************************************/
// forward declaration of XYStatData
class XYStatData;
2015-02-24 17:00:19 +00:00
class Chi2Function: public DoubleFunctionFactory
2014-03-03 12:41:48 +00:00
{
private:
struct Chi2FunctionBuffer
{
DVec v, x;
DMat invVar;
bool isInit{false};
Vec<Index> xInd, dInd;
};
public:
// constructor
2014-03-03 14:21:37 +00:00
explicit Chi2Function(const XYStatData &data);
2014-03-03 12:41:48 +00:00
Chi2Function(const XYStatData &data,
const std::vector<const DoubleModel *> &modelVector);
// destructor
virtual ~Chi2Function(void) = default;
// access
virtual Index getNArg(void) const;
Index getNDof(void) const;
Index getNPar(void) const;
void setModel(const DoubleModel &model, const Index j = 0);
void setModel(const std::vector<const DoubleModel *> &modelVector);
void requestInit(void) const;
// function call
2015-02-24 17:00:19 +00:00
double operator()(const double *arg) const;
// factory
virtual DoubleFunction makeFunction(const bool makeHardCopy = true) const;
2014-03-03 12:41:48 +00:00
private:
// access
void resizeBuffer(void) const;
// compute variance matrix inverse
void setVarianceBlock(const Index l1, const Index l2,
2015-02-23 18:11:37 +00:00
ConstBlock<MatBase<double>> m) const;
2014-03-03 12:41:48 +00:00
void initBuffer(void) const;
private:
const XYStatData &data_;
std::shared_ptr<Chi2FunctionBuffer> buffer_;
std::vector<const DoubleModel *> model_;
Index nPar_{-1};
};
END_LATAN_NAMESPACE
2014-03-03 12:41:48 +00:00
#endif // Latan_Chi2Function_hpp_