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

210 lines
5.4 KiB
C++
Raw Normal View History

2014-03-12 19:17:15 +00:00
/*
* FitInterface.cpp, part of LatAnalyze 3
*
2015-06-11 14:04:54 +01:00
* Copyright (C) 2013 - 2015 Antonin Portelli
2014-03-12 19:17:15 +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/>.
*/
2014-03-13 18:51:01 +00:00
#include <LatAnalyze/FitInterface.hpp>
#include <LatAnalyze/includes.hpp>
2014-03-12 19:17:15 +00:00
using namespace std;
using namespace Latan;
/******************************************************************************
* FitInterface implementation *
******************************************************************************/
// constructors ////////////////////////////////////////////////////////////////
FitInterface::FitInterface(const Index nData, const Index xDim,
const Index yDim)
{
resize(nData, xDim, yDim);
}
// access //////////////////////////////////////////////////////////////////////
void FitInterface::assumeXExact(const Index i, const bool isExact)
{
isXExact_(i) = (isExact) ? 1 : 0;
}
void FitInterface::assumeXXCorrelated(const Index i1, const Index i2,
const bool isCorrelated)
{
2014-03-17 14:58:18 +00:00
int val = (isCorrelated) ? 1 : 0;
isXXCorr_(i1, i2) = val;
isXXCorr_(i2, i1) = val;
2014-03-12 19:17:15 +00:00
}
void FitInterface::assumeYYCorrelated(const Index j1, const Index j2,
const bool isCorrelated)
{
2014-03-17 14:58:18 +00:00
int val = (isCorrelated) ? 1 : 0;
isYYCorr_(j1, j2) = val;
isYYCorr_(j2, j1) = val;
2014-03-12 19:17:15 +00:00
}
void FitInterface::assumeYXCorrelated(const Index j, const Index i,
const bool isCorrelated)
{
2014-03-17 14:58:18 +00:00
int val = (isCorrelated) ? 1 : 0;
isYXCorr_(j, i) = val;
2014-03-12 19:17:15 +00:00
}
void FitInterface::assumeDataCorrelated(const Index k1, const Index k2,
const bool isCorrelated)
{
2014-03-17 14:58:18 +00:00
int val = (isCorrelated) ? 1 : 0;
isDataCorr_(k1, k2) = val;
isDataCorr_(k2, k1) = val;
2014-03-12 19:17:15 +00:00
}
void FitInterface::assumeDataCorrelated(const bool isCorrelated)
{
FOR_MAT(isDataCorr_, k1, k2)
{
if (k1 != k2)
{
assumeDataCorrelated(k1, k2, isCorrelated);
}
}
}
2014-03-12 19:17:15 +00:00
void FitInterface::fitPoint(const Index i, const bool isFitPoint)
{
isFitPoint_(i) = (isFitPoint) ? 1 : 0;
}
void FitInterface::fitPointRange(const Index k1, const Index k2,
const bool isFitPoint)
{
int size = static_cast<int>(k2-k1+1);
isFitPoint_.segment(k1, size) = IVec::Constant(size, (isFitPoint) ? 1 : 0);
}
void FitInterface::fitAllPoints(const bool isFitPoint)
{
fitPointRange(0, getNData()-1, isFitPoint);
}
Index FitInterface::getNData(void) const
{
return isFitPoint_.size();
}
Index FitInterface::getNFitPoint(void) const
{
return isFitPoint_.sum();
}
Index FitInterface::getXDim(void) const
{
return isXXCorr_.rows();
}
Index FitInterface::getYDim(void) const
{
return isYYCorr_.rows();
}
Index FitInterface::getStatXDim(void) const
{
return isXExact_.size() - isXExact_.sum();
}
double FitInterface::getSvdTolerance(void) const
{
return svdTolerance_;
}
2014-03-12 19:17:15 +00:00
void FitInterface::setFitInterface(const FitInterface &fitInterface)
{
if (&fitInterface != this)
{
isXExact_ = fitInterface.isXExact_;
isFitPoint_ = fitInterface.isFitPoint_;
isXXCorr_ = fitInterface.isXXCorr_;
isYYCorr_ = fitInterface.isYYCorr_;
isYXCorr_ = fitInterface.isYXCorr_;
isDataCorr_ = fitInterface.isDataCorr_;
svdTolerance_ = fitInterface.svdTolerance_;
2014-03-12 19:17:15 +00:00
}
}
void FitInterface::setNData(const Index nData)
{
resize(nData, getXDim(), getYDim());
}
void FitInterface::setXDim(const Index xDim)
{
resize(getNData(), xDim, getYDim());
}
void FitInterface::setYDim(const Index yDim)
{
resize(getNData(), getXDim(), yDim);
}
void FitInterface::setSvdTolerance(const double tolerance)
{
svdTolerance_ = tolerance;
}
2014-03-12 19:17:15 +00:00
void FitInterface::resize(const Index nData, const Index xDim, const Index yDim)
{
isXExact_.setConstant(xDim, 0);
isFitPoint_.setConstant(nData, 0);
isXXCorr_.setIdentity(xDim, xDim);
2014-03-17 14:58:18 +00:00
isYYCorr_.setIdentity(yDim, yDim);
2014-03-12 19:17:15 +00:00
isYXCorr_.setConstant(yDim, xDim, 0);
isDataCorr_.setIdentity(nData, nData);
}
// test ////////////////////////////////////////////////////////////////////////
bool FitInterface::isFitPoint(const Index k) const
{
return (isFitPoint_[k] == 1);
}
bool FitInterface::isXExact(const Index i) const
{
return (isXExact_[i] == 1);
}
bool FitInterface::isXXCorrelated(const Index i1, const Index i2) const
{
return (isXXCorr_(i1, i2) == 1);
}
bool FitInterface::isYYCorrelated(const Index j1, const Index j2) const
{
return (isYYCorr_(j1, j2) == 1);
}
bool FitInterface::isYXCorrelated(const Index j, const Index i) const
{
return (isYXCorr_(j, i) == 1);
}
bool FitInterface::isDataCorrelated(const Index k1, const Index k2) const
{
return (isDataCorr_(k1, k2) == 1);
}