mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-06-20 08:16:55 +01:00
Merge remote-tracking branch 'fork/develop' into develop
This commit is contained in:
@ -253,16 +253,39 @@ DMatSample CorrelatorUtils::shift(const DMatSample &c, const Index ts)
|
||||
}
|
||||
}
|
||||
|
||||
DMatSample CorrelatorUtils::fold(const DMatSample &c)
|
||||
DMatSample CorrelatorUtils::fold(const DMatSample &c, const CorrelatorModels::ModelPar &par)
|
||||
{
|
||||
const Index nt = c[central].rows();
|
||||
DMatSample buf = c;
|
||||
|
||||
FOR_STAT_ARRAY(buf, s)
|
||||
int sign;
|
||||
bool fold = false;
|
||||
|
||||
switch (par.type)
|
||||
{
|
||||
for (Index t = 0; t < nt; ++t)
|
||||
case CorrelatorType::cosh:
|
||||
case CorrelatorType::cst:
|
||||
sign = 1;
|
||||
fold = true;
|
||||
break;
|
||||
case CorrelatorType::sinh:
|
||||
sign = -1;
|
||||
fold = true;
|
||||
break;
|
||||
case CorrelatorType::linear:
|
||||
cout << "Linear model is asymmetric: will not fold." << endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (fold)
|
||||
{
|
||||
FOR_STAT_ARRAY(buf, s)
|
||||
{
|
||||
buf[s](t) = 0.5*(c[s](t) + c[s]((nt - t) % nt));
|
||||
for (Index t = 0; t < nt; ++t)
|
||||
{
|
||||
buf[s](t) = 0.5*(c[s](t) + sign*c[s]((nt - t) % nt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace CorrelatorModels
|
||||
namespace CorrelatorUtils
|
||||
{
|
||||
DMatSample shift(const DMatSample &c, const Index ts);
|
||||
DMatSample fold(const DMatSample &c);
|
||||
DMatSample fold(const DMatSample &c, const CorrelatorModels::ModelPar &par);
|
||||
DMatSample fourierTransform(const DMatSample &c, FFT &fft,
|
||||
const unsigned int dir = FFT::Forward);
|
||||
};
|
||||
|
@ -234,6 +234,21 @@ DVec XYSampleData::getYError(const Index j)
|
||||
return data_.getYError(j);
|
||||
}
|
||||
|
||||
bool XYSampleData::checkFit()
|
||||
{
|
||||
return goodFit_;
|
||||
}
|
||||
|
||||
void XYSampleData::checkChi2PerDof(double Chi2PerDof)
|
||||
{
|
||||
if(Chi2PerDof >= 2 or Chi2PerDof < 0 or isnan(Chi2PerDof))
|
||||
{
|
||||
goodFit_ = false;
|
||||
cerr << "chi2PerDof = " << Chi2PerDof << ". Aborting fit now." << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// get total fit variance matrix and its pseudo-inverse ////////////////////////
|
||||
const DMat & XYSampleData::getFitVarMat(void)
|
||||
{
|
||||
@ -292,24 +307,34 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
|
||||
result.resize(nSample_);
|
||||
result.chi2_.resize(nSample_);
|
||||
result.model_.resize(v.size());
|
||||
double chi2PerDof;
|
||||
goodFit_ = true;
|
||||
FOR_STAT_ARRAY(result, s)
|
||||
{
|
||||
setDataToSample(s);
|
||||
if (s == central)
|
||||
if(goodFit_)
|
||||
{
|
||||
sampleResult = data_.fit(minimizer, initCopy, v);
|
||||
initCopy = sampleResult.segment(0, initCopy.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
sampleResult = data_.fit(*(minimizer.back()), initCopy, 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);
|
||||
setDataToSample(s);
|
||||
if (s == central)
|
||||
{
|
||||
sampleResult = data_.fit(minimizer, initCopy, v);
|
||||
initCopy = sampleResult.segment(0, initCopy.size());
|
||||
chi2PerDof = sampleResult.getChi2PerDof();
|
||||
checkChi2PerDof(chi2PerDof);
|
||||
}
|
||||
else
|
||||
{
|
||||
sampleResult = data_.fit(*(minimizer.back()), initCopy, v);
|
||||
chi2PerDof = sampleResult.getChi2PerDof();
|
||||
checkChi2PerDof(chi2PerDof);
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
result.nPar_ = sampleResult.getNPar();
|
||||
|
@ -91,6 +91,8 @@ public:
|
||||
const DMat & getXYVar(const Index i, const Index j);
|
||||
DVec getXError(const Index i);
|
||||
DVec getYError(const Index j);
|
||||
bool checkFit(); // check fit candidate based on chi2PerDof
|
||||
void checkChi2PerDof(double Chi2PerDof);
|
||||
// get total fit variance matrix and its pseudo-inverse
|
||||
const DMat & getFitVarMat(void);
|
||||
const DMat & getFitVarMatPInv(void);
|
||||
@ -133,6 +135,7 @@ private:
|
||||
Index nSample_, dataSample_{central};
|
||||
bool initData_{true}, computeVarMat_{true};
|
||||
bool initXMap_{true};
|
||||
bool goodFit_{true}; // used to break minimisation if central sample chi2PerDof is bad
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
|
Reference in New Issue
Block a user