From 6eca1e6fc6d01cf5d8689788523ab8f190feceaa Mon Sep 17 00:00:00 2001 From: AndrewYongZhenNing Date: Thu, 7 Oct 2021 17:41:36 +0100 Subject: [PATCH] i) removed pvalue fit criteria ii) overloaded fit() to output FitResult object of a particular sample --- lib/Statistics/XYSampleData.cpp | 74 ++++++++++++++++----------------- lib/Statistics/XYSampleData.hpp | 20 +++++---- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/Statistics/XYSampleData.cpp b/lib/Statistics/XYSampleData.cpp index 0bad9ce..48f6d4d 100644 --- a/lib/Statistics/XYSampleData.cpp +++ b/lib/Statistics/XYSampleData.cpp @@ -234,21 +234,6 @@ DVec XYSampleData::getYError(const Index j) return data_.getYError(j); } -void XYSampleData::setPValueBound(double uLim, double lLim) -{ - pValMax = uLim; - pValMin = lLim; -} - -void XYSampleData::checkPValue(double pValue) -{ - if(pValue >= pValMax or pValue <= pValMin or isnan(pValue)) - { - string msg = "central pValue = " + to_string(pValue) + " not within user-set bound of " + to_string(pValMin) + " < pValue < " + to_string(pValMax) ; - LATAN_ERROR(Runtime, msg); - } -} - // get total fit variance matrix and its pseudo-inverse //////////////////////// const DMat & XYSampleData::getFitVarMat(void) { @@ -297,37 +282,51 @@ const XYStatData & XYSampleData::getData(void) void XYSampleData::fitSample(std::vector &minimizer, const std::vector &v, - SampleFitResult &result, FitResult &sampleResult, DVec &init, Index s) { - double pValue = 0; setDataToSample(s); if (s == central) { sampleResult = data_.fit(minimizer, init, v); init = sampleResult.segment(0, init.size()); - pValue = sampleResult.getPValue(); - checkPValue(pValue); } else { sampleResult = data_.fit(*(minimizer.back()), init, v); } - result[s] = sampleResult; - result.chi2_[s] = sampleResult.getChi2(); - for (unsigned int j = 0; j < v.size(); ++j) - { - result.model_[j].resize(nSample_); - result.model_[j][s] = sampleResult.getModel(j); - } + +} + +FitResult XYSampleData::fit(std::vector &minimizer, + const DVec &init, + const std::vector &v, + Index s) +{ + computeVarMat(); + + FitResult sampleResult; + DVec initCopy = init; + + fitSample(minimizer, v, sampleResult, initCopy, s); + + return sampleResult; +} + +FitResult XYSampleData::fit(Minimizer &minimizer, + const DVec &init, + const std::vector &v, + Index s) +{ + vector mv{&minimizer}; + + return fit(mv, init, v, s); } SampleFitResult XYSampleData::fit(std::vector &minimizer, const DVec &init, - const std::vector &v, - bool centralSample) + const std::vector &v) { computeVarMat(); @@ -338,15 +337,15 @@ SampleFitResult XYSampleData::fit(std::vector &minimizer, result.resize(nSample_); result.chi2_.resize(nSample_); result.model_.resize(v.size()); - if(centralSample) + FOR_STAT_ARRAY(result, s) { - fitSample(minimizer, v, result, sampleResult, initCopy, central); - } - else - { - FOR_STAT_ARRAY(result, s) + fitSample(minimizer, v, sampleResult, initCopy, s); + result[s] = sampleResult; + result.chi2_[s] = sampleResult.getChi2(); + for (unsigned int j = 0; j < v.size(); ++j) { - fitSample(minimizer, v, result, sampleResult, initCopy, s); + result.model_[j].resize(nSample_); + result.model_[j][s] = sampleResult.getModel(j); } } result.nPar_ = sampleResult.getNPar(); @@ -358,12 +357,11 @@ SampleFitResult XYSampleData::fit(std::vector &minimizer, SampleFitResult XYSampleData::fit(Minimizer &minimizer, const DVec &init, - const std::vector &v, - bool centralSample) + const std::vector &v) { vector mv{&minimizer}; - return fit(mv, init, v, centralSample); + return fit(mv, init, v); } // residuals /////////////////////////////////////////////////////////////////// diff --git a/lib/Statistics/XYSampleData.hpp b/lib/Statistics/XYSampleData.hpp index ac3a464..8e9def6 100644 --- a/lib/Statistics/XYSampleData.hpp +++ b/lib/Statistics/XYSampleData.hpp @@ -91,9 +91,6 @@ public: const DMat & getXYVar(const Index i, const Index j); DVec getXError(const Index i); DVec getYError(const Index j); - // fit criteria - void setPValueBound(double uLim, double lLim); - void checkPValue(double Chi2PerDof); // get total fit variance matrix and its pseudo-inverse const DMat & getFitVarMat(void); const DMat & getFitVarMatPInv(void); @@ -102,12 +99,17 @@ public: // get internal XYStatData const XYStatData & getData(void); // fit - void fitSample(std::vector &minimizer, const std::vector &v, - SampleFitResult &result, FitResult &sampleResult, DVec &init, Index s); - SampleFitResult fit(std::vector &minimizer, const DVec &init, - const std::vector &v, bool centralSample = false); - SampleFitResult fit(Minimizer &minimizer, const DVec &init, - const std::vector &v, bool centralSample = false); + void fitSample(std::vector &minimizer, + const std::vector &v, + FitResult &sampleResult, DVec &init, Index s); + FitResult fit(std::vector &minimizer, const DVec &init, + const std::vector &v, Index s); + FitResult fit(Minimizer &minimizer, const DVec &init, + const std::vector &v, Index s); + SampleFitResult fit(std::vector &minimizer, const DVec &init, + const std::vector &v); + SampleFitResult fit(Minimizer &minimizer, const DVec &init, + const std::vector &v); template SampleFitResult fit(std::vector &minimizer, const DVec &init, const DoubleModel &model, const Ts... models);