/* * XYData.hpp, part of LatAnalyze 3 * * Copyright (C) 2013 - 2015 Antonin Portelli * * 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 . */ #ifndef Latan_XYData_hpp_ #define Latan_XYData_hpp_ #include #include #include #include #include #include #include #include BEGIN_LATAN_NAMESPACE /****************************************************************************** * object for fit result * ******************************************************************************/ class FitResult: public DVec { friend class XYStatData; friend class SampleFitResult; public: // constructors FitResult(void) = default; EIGEN_EXPR_CTOR(FitResult, FitResult, Base, MatExpr) // destructor virtual ~FitResult(void) = default; // access double getChi2(void) const; double getChi2PerDof(void) const; double getNDof(void) const; const DoubleFunction & getModel(const Index j = 0) const; private: double chi2_{0.0}; Index nDof_{0}; std::vector model_; }; /****************************************************************************** * object for X vs. Y statistical data * ****************************************************************************** * index convention: i: X, j: Y, k: data */ class XYStatData: public FitInterface { public: enum { xx = 0, yy = 1, yx = 2 }; public: // constructors XYStatData(void); XYStatData(const Index nData, const Index nXDim, const Index nYDim); // destructor virtual ~XYStatData(void) = default; // access void resize(const Index nData, const Index xDim, const Index yDim); void reinitChi2(const bool doReinit = true); Block> x(const PlaceHolder ph1 = _, const PlaceHolder ph2 = _); ConstBlock> x(const PlaceHolder ph1 = _, const PlaceHolder ph2 = _) const; Block> x(const Index i, const PlaceHolder ph2 = _); ConstBlock> x(const Index i, const PlaceHolder ph2 = _) const; Block> x(const PlaceHolder ph1, const Index k); ConstBlock> x(const PlaceHolder ph1, const Index k) const; double & x(const Index i, const Index k); const double & x(const Index i, const Index k) const; Block> y(const PlaceHolder ph1 = _, const PlaceHolder ph2 = _); ConstBlock> y(const PlaceHolder ph1 = _, const PlaceHolder ph2 = _) const; Block> y(const Index i, const PlaceHolder ph2 = _); ConstBlock> y(const Index i, const PlaceHolder ph2 = _) const; Block> y(const PlaceHolder ph1, const Index k); ConstBlock> y(const PlaceHolder ph1, const Index k) const; double & y(const Index i, const Index k); const double & y(const Index i, const Index k) const; Block> xxVar(const Index i1, const Index i2); ConstBlock> xxVar(const Index i1, const Index i2) const; Block> yyVar(const Index j1, const Index j2); ConstBlock> yyVar(const Index j1, const Index j2) const; Block> yxVar(const Index j, const Index i); ConstBlock> yxVar(const Index j, const Index i) const; // fit FitResult fit(Minimizer &minimizer, const DVec &init, const std::vector &modelVector); template FitResult fit(Minimizer &minimizer, const DVec &init, const DoubleModel &model, const Ts... models); // residuals XYStatData getResiduals(const FitResult &fit) const; XYStatData getPartialResiduals(const FitResult &fit, const DVec &x, const Index j) const; private: DMat x_, y_; Mat var_[3]; IVec isXExact_, isFitPoint_; Chi2Function chi2_; bool reinitChi2_{true}; }; /****************************************************************************** * XYStatData template implementation * ******************************************************************************/ template FitResult XYStatData::fit(Minimizer &minimizer, const DVec &init, const DoubleModel &model, const Ts... models) { static_assert(static_or::value...>::value, "model arguments are not compatible with DoubleModel &"); std::vector modelVector{&model, &models...}; return fit(minimizer, init, modelVector); } END_LATAN_NAMESPACE #endif // Latan_XYData_hpp_