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

various critical fixes and improvements to the new fit interface

This commit is contained in:
Antonin Portelli 2016-03-23 17:07:31 +00:00
parent 3793aca27c
commit ee8ed05b81
5 changed files with 31 additions and 7 deletions

View File

@ -407,7 +407,8 @@ void FitInterface::updateLayout(void)
{ {
if (initLayout_) if (initLayout_)
{ {
Index size, ifit; Index size, ifit;
vector<Index> v;
layout.nXFitDim = 0; layout.nXFitDim = 0;
layout.nYFitDim = 0; layout.nYFitDim = 0;
@ -416,6 +417,7 @@ void FitInterface::updateLayout(void)
layout.totalYSize = 0; layout.totalYSize = 0;
layout.xSize.clear(); layout.xSize.clear();
layout.ySize.clear(); layout.ySize.clear();
layout.dataIndexSet.clear();
layout.xDim.clear(); layout.xDim.clear();
layout.yDim.clear(); layout.yDim.clear();
layout.xFitDim.clear(); layout.xFitDim.clear();
@ -479,6 +481,7 @@ void FitInterface::updateLayout(void)
{ {
if (p.second) if (p.second)
{ {
layout.dataIndexSet.insert(p.first);
layout.y[j].push_back(s); layout.y[j].push_back(s);
layout.yFit[j].push_back(layout.y[j].size() - 1); layout.yFit[j].push_back(layout.y[j].size() - 1);
layout.data[j].push_back(p.first); layout.data[j].push_back(p.first);
@ -495,7 +498,15 @@ void FitInterface::updateLayout(void)
layout.totalSize = layout.totalXSize + layout.totalYSize; layout.totalSize = layout.totalXSize + layout.totalYSize;
layout.nXFitDim = static_cast<Index>(layout.xSize.size()); layout.nXFitDim = static_cast<Index>(layout.xSize.size());
layout.nYFitDim = static_cast<Index>(layout.ySize.size()); layout.nYFitDim = static_cast<Index>(layout.ySize.size());
initLayout_ = false; for (Index k: layout.dataIndexSet)
{
v = dataCoord(k);
for (Index i = 0; i < getNXDim(); ++i)
{
layout.xIndFromData[k].push_back(indX(v[i], i));
}
}
initLayout_ = false;
} }
} }

View File

@ -38,16 +38,20 @@ private:
Index totalSize, totalXSize, totalYSize; Index totalSize, totalXSize, totalYSize;
// size of each X/Y dimension // size of each X/Y dimension
std::vector<Index> xSize, ySize; std::vector<Index> xSize, ySize;
// set of active data indices
std::set<Index> dataIndexSet;
// lookup tables // lookup tables
// xDim : x fit dim ifit -> x dim i // xDim : x fit dim ifit -> x dim i
// x : x fit point ifit,rfit -> x point r // x : x fit point ifit,rfit -> x point r
// xFitDim : x dim i -> x fit dim ifit (-1 if empty) // xFitDim : x dim i -> x fit dim ifit (-1 if empty)
// xFit : x point i,r -> x fit point rfit (-1 if empty) // xFit : x point i,r -> x fit point rfit (-1 if empty)
// data : y fit point jfit,sfit -> y point index k // data : y fit point jfit,sfit -> y point index k
// yFitFromData: y point indec k,j -> y fit point sfit (-1 if empty) // yFitFromData: y point index k,j -> y fit point sfit (-1 if empty)
// xIndFromData: data index k -> index of coordinates of associated x
std::vector<Index> xDim, yDim, xFitDim, yFitDim; std::vector<Index> xDim, yDim, xFitDim, yFitDim;
std::vector<std::vector<Index>> x, y, data, xFit, yFit; std::vector<std::vector<Index>> x, y, data, xFit, yFit;
std::vector<std::map<Index, Index>> yFitFromData; std::vector<std::map<Index, Index>> yFitFromData;
std::map<Index, std::vector<Index>> xIndFromData;
} Layout; } Layout;
public: public:
// constructor // constructor

View File

@ -207,7 +207,7 @@ void XYSampleData::setDataToSample(const Index s)
{ {
data_.x(r, i) = xData_[i][r][s]; data_.x(r, i) = xData_[i][r][s];
} }
for (Index j = 0; j < getNXDim(); ++j) for (Index j = 0; j < getNYDim(); ++j)
for (auto &p: yData_[j]) for (auto &p: yData_[j])
{ {
data_.y(p.first, j) = p.second[s]; data_.y(p.first, j) = p.second[s];
@ -234,13 +234,15 @@ SampleFitResult XYSampleData::fit(Minimizer &minimizer, const DVec &init,
SampleFitResult result; SampleFitResult result;
FitResult sampleResult; FitResult sampleResult;
DVec initCopy = init;
result.resize(nSample_); result.resize(nSample_);
result.chi2_.resize(nSample_); result.chi2_.resize(nSample_);
FOR_STAT_ARRAY(result, s) FOR_STAT_ARRAY(result, s)
{ {
setDataToSample(s); setDataToSample(s);
sampleResult = data_.fit(minimizer, init, v); sampleResult = data_.fit(minimizer, initCopy, v);
initCopy = sampleResult.segment(0, initCopy.size());
result[s] = sampleResult; result[s] = sampleResult;
result.chi2_[s] = sampleResult.getChi2(); result.chi2_[s] = sampleResult.getChi2();
result.nDof_ = sampleResult.getNDof(); result.nDof_ = sampleResult.getNDof();

View File

@ -250,6 +250,7 @@ FitResult XYStatData::fit(Minimizer &minimizer, const DVec &init,
void XYStatData::createXData(const std::string name __dumb, const Index nData) void XYStatData::createXData(const std::string name __dumb, const Index nData)
{ {
xData_.push_back(DVec::Zero(nData)); xData_.push_back(DVec::Zero(nData));
xBuf_.resize(xData_.size());
resizeVarMat(); resizeVarMat();
} }
@ -444,7 +445,7 @@ void XYStatData::updateChi2ModVec(const DVec p,
{ {
updateLayout(); updateLayout();
Index nPar = v[0]->getNPar(), a = 0, j, k; Index nPar = v[0]->getNPar(), a = 0, j, k, ind;
auto &par = p.segment(0, nPar), &xsi = p.segment(nPar, layout.totalXSize); auto &par = p.segment(0, nPar), &xsi = p.segment(nPar, layout.totalXSize);
updateXMap(); updateXMap();
@ -453,7 +454,12 @@ void XYStatData::updateChi2ModVec(const DVec p,
{ {
j = layout.yDim[jfit]; j = layout.yDim[jfit];
k = layout.data[jfit][sfit]; k = layout.data[jfit][sfit];
chi2ModVec_(a) = (*v[j])(xMap_[k].data(), par.data()); for (Index i = 0; i < getNXDim(); ++i)
{
ind = layout.xIndFromData[k][i] - layout.totalYSize;
xBuf_(i) = (ind >= 0) ? xsi(ind) : xMap_[k](i);
}
chi2ModVec_(a) = (*v[j])(xBuf_.data(), par.data());
a++; a++;
} }
chi2ModVec_.segment(a, layout.totalXSize) = xsi; chi2ModVec_.segment(a, layout.totalXSize) = xsi;

View File

@ -110,6 +110,7 @@ private:
Mat<DMat> xxVar_, yyVar_, xyVar_; Mat<DMat> xxVar_, yyVar_, xyVar_;
DMat fitVar_, fitVarInv_; DMat fitVar_, fitVarInv_;
DVec chi2DataVec_, chi2ModVec_, chi2Vec_; DVec chi2DataVec_, chi2ModVec_, chi2Vec_;
DVec xBuf_;
bool initXMap_{true}; bool initXMap_{true};
bool initChi2DataVec_{true}; bool initChi2DataVec_{true};
}; };