mirror of
				https://github.com/aportelli/LatAnalyze.git
				synced 2025-11-04 00:04:31 +00:00 
			
		
		
		
	XYStatData: simpler data access
This commit is contained in:
		@@ -22,9 +22,9 @@ int main(void)
 | 
			
		||||
    
 | 
			
		||||
    for (Index k = 0; k < nPoint; ++k)
 | 
			
		||||
    {
 | 
			
		||||
        x_k                = k*dx;
 | 
			
		||||
        data.x(0, k)(0, 0) = x_k;
 | 
			
		||||
        data.y(0, k)(0, 0) = f(&x_k, exactPar) + rg.gaussian(0.0, 0.1);
 | 
			
		||||
        x_k          = k*dx;
 | 
			
		||||
        data.x(0, k) = x_k;
 | 
			
		||||
        data.y(0, k) = f(&x_k, exactPar) + rg.gaussian(0.0, 0.1);
 | 
			
		||||
    }
 | 
			
		||||
    data.yyVar(0, 0).diagonal() = DMat::Constant(nPoint, 1, 0.1*0.1);
 | 
			
		||||
    data.assumeXExact(0);
 | 
			
		||||
 
 | 
			
		||||
@@ -243,7 +243,7 @@ double Chi2Function::operator()(const double *arg) const
 | 
			
		||||
    FOR_VEC(buffer_->dInd, k)
 | 
			
		||||
    {
 | 
			
		||||
        const DoubleModel *f = model_[static_cast<unsigned int>(j)];
 | 
			
		||||
        double            f_jk, y_jk = data_.y(j, buffer_->dInd(k))(0, 0);
 | 
			
		||||
        double            f_jk, y_jk = data_.y(j, buffer_->dInd(k));
 | 
			
		||||
        
 | 
			
		||||
        if (!f)
 | 
			
		||||
        {
 | 
			
		||||
@@ -253,7 +253,7 @@ double Chi2Function::operator()(const double *arg) const
 | 
			
		||||
        {
 | 
			
		||||
            if (data_.isXExact(i))
 | 
			
		||||
            {
 | 
			
		||||
                buffer_->x(i) = data_.x(i, buffer_->dInd(k))(0, 0);
 | 
			
		||||
                buffer_->x(i) = data_.x(i, buffer_->dInd(k));
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
@@ -269,7 +269,7 @@ double Chi2Function::operator()(const double *arg) const
 | 
			
		||||
    FOR_VEC(buffer_->xInd, i)
 | 
			
		||||
    FOR_VEC(buffer_->dInd, k)
 | 
			
		||||
    {
 | 
			
		||||
        double x_ik  = data_.x(buffer_->xInd(i), buffer_->dInd(k))(0, 0);
 | 
			
		||||
        double x_ik  = data_.x(buffer_->xInd(i), buffer_->dInd(k));
 | 
			
		||||
        double xi_ik = xi(i*nPoint + k);
 | 
			
		||||
        
 | 
			
		||||
        buffer_->v(i*nPoint + k) = xi_ik - x_ik;
 | 
			
		||||
 
 | 
			
		||||
@@ -143,44 +143,95 @@ void XYStatData::resize(const Index nData, const Index xDim, const Index yDim)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused,
 | 
			
		||||
                              const PlaceHolder ph2 __unused)
 | 
			
		||||
{
 | 
			
		||||
    return x_.block(0, 0, getNData(), getXDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused,
 | 
			
		||||
                                   const PlaceHolder ph2 __unused) const
 | 
			
		||||
{
 | 
			
		||||
    return x_.block(0, 0, getNData(), getXDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::x(const Index i, const PlaceHolder ph2 __unused)
 | 
			
		||||
{
 | 
			
		||||
    return x_.block(0, i, getNData(), 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::x(const Index i,
 | 
			
		||||
                                   const PlaceHolder ph2 __unused) const
 | 
			
		||||
{
 | 
			
		||||
    return x_.block(0, i, getNData(), 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused, const Index k)
 | 
			
		||||
{
 | 
			
		||||
    return x_.block(k, 0, 1, getXDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused,
 | 
			
		||||
                                   const Index k) const
 | 
			
		||||
{
 | 
			
		||||
    return x_.block(k, 0, 1, getXDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double & XYStatData::x(const Index i, const Index k)
 | 
			
		||||
{
 | 
			
		||||
    return x_(k, i);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const double & XYStatData::x(const Index i, const Index k) const
 | 
			
		||||
{
 | 
			
		||||
    return x_(k, i);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused,
 | 
			
		||||
                              const PlaceHolder ph2 __unused)
 | 
			
		||||
{
 | 
			
		||||
    return y_.block(0, 0, getNData(), getYDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused,
 | 
			
		||||
                                   const PlaceHolder ph2 __unused) const
 | 
			
		||||
{
 | 
			
		||||
    return y_.block(0, 0, getNData(), getYDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::y(const Index j, const PlaceHolder ph2 __unused)
 | 
			
		||||
{
 | 
			
		||||
    return y_.block(0, j, getNData(), 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::y(const Index j,
 | 
			
		||||
                                   const PlaceHolder ph2 __unused) const
 | 
			
		||||
{
 | 
			
		||||
    return y_.block(0, j, getNData(), 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused, const Index k)
 | 
			
		||||
{
 | 
			
		||||
    return y_.block(k, 0, 1, getYDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused,
 | 
			
		||||
                                   const Index k) const
 | 
			
		||||
{
 | 
			
		||||
    return y_.block(k, 0, 1, getYDim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double & XYStatData::y(const Index j, const Index k)
 | 
			
		||||
{
 | 
			
		||||
    return y_(k, j);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const double & XYStatData::y(const Index j, const Index k) const
 | 
			
		||||
{
 | 
			
		||||
    return y_(k, j);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define FULL_BLOCK(m) (m).block(0, 0, (m).rows(), (m).cols())
 | 
			
		||||
#define ACCESS_DATA(xy, ij, k) \
 | 
			
		||||
if ((ij >= 0)&&(k >= 0))\
 | 
			
		||||
{\
 | 
			
		||||
    return xy.block(k, ij, 1, 1);\
 | 
			
		||||
}\
 | 
			
		||||
else if ((ij < 0)&&(k >= 0))\
 | 
			
		||||
{\
 | 
			
		||||
    return xy.block(k, 0, 1, getXDim());\
 | 
			
		||||
}\
 | 
			
		||||
else if ((ij >= 0)&&(k < 0))\
 | 
			
		||||
{\
 | 
			
		||||
    return xy.block(0, ij, getNData(), 1);\
 | 
			
		||||
}\
 | 
			
		||||
else\
 | 
			
		||||
{\
 | 
			
		||||
    return xy.block(0, 0, getNData(), getXDim());\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::x(const Index i, const Index k)
 | 
			
		||||
{
 | 
			
		||||
    ACCESS_DATA(x_, i, k);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::x(const Index i, const Index k) const
 | 
			
		||||
{
 | 
			
		||||
    ACCESS_DATA(x_, i, k);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::y(const Index j, const Index k)
 | 
			
		||||
{
 | 
			
		||||
    ACCESS_DATA(y_, j, k);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConstBlock<DMatBase> XYStatData::y(const Index j, const Index k) const
 | 
			
		||||
{
 | 
			
		||||
    ACCESS_DATA(y_, j, k);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Block<DMatBase> XYStatData::xxVar(const Index i1, const Index i2)
 | 
			
		||||
{
 | 
			
		||||
@@ -249,7 +300,7 @@ FitResult XYStatData::fit(const vector<const DoubleModel *> &modelVector,
 | 
			
		||||
        for (Index k = 0; k < getNData(); ++k)
 | 
			
		||||
        if (isFitPoint(k))
 | 
			
		||||
        {
 | 
			
		||||
            fullInit(chi2_.getNPar() + nPoint*is + kf) = x(i, k)(0, 0);
 | 
			
		||||
            fullInit(chi2_.getNPar() + nPoint*is + kf) = x(i, k);
 | 
			
		||||
            kf++;
 | 
			
		||||
        }
 | 
			
		||||
        is++;
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,9 @@ private:
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                    object for X vs. Y statistical data                     *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
const Index _ = -1;
 | 
			
		||||
struct PlaceHolder {};
 | 
			
		||||
 | 
			
		||||
extern PlaceHolder _;
 | 
			
		||||
 | 
			
		||||
class XYStatData
 | 
			
		||||
{
 | 
			
		||||
@@ -89,10 +91,22 @@ public:
 | 
			
		||||
    void                 setYDim(const Index yDim);
 | 
			
		||||
    void                 resize(const Index nData, const Index xDim,
 | 
			
		||||
                                const Index yDim);
 | 
			
		||||
    Block<DMatBase>      x(const Index i = _, const Index k = _);
 | 
			
		||||
    ConstBlock<DMatBase> x(const Index i = _, const Index k = _) const;
 | 
			
		||||
    Block<DMatBase>      y(const Index j = _, const Index k = _);
 | 
			
		||||
    ConstBlock<DMatBase> y(const Index j = _, const Index k = _) const;
 | 
			
		||||
    Block<DMatBase>      x(const PlaceHolder ph1, const PlaceHolder ph2);
 | 
			
		||||
    ConstBlock<DMatBase> x(const PlaceHolder ph1, const PlaceHolder ph2) const;
 | 
			
		||||
    Block<DMatBase>      x(const Index i, const PlaceHolder ph2 = _);
 | 
			
		||||
    ConstBlock<DMatBase> x(const Index i, const PlaceHolder ph2 = _) const;
 | 
			
		||||
    Block<DMatBase>      x(const PlaceHolder ph1, const Index k);
 | 
			
		||||
    ConstBlock<DMatBase> 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<DMatBase>      y(const PlaceHolder ph1, const PlaceHolder ph2);
 | 
			
		||||
    ConstBlock<DMatBase> y(const PlaceHolder ph1, const PlaceHolder ph2) const;
 | 
			
		||||
    Block<DMatBase>      y(const Index i, const PlaceHolder ph2 = _);
 | 
			
		||||
    ConstBlock<DMatBase> y(const Index i, const PlaceHolder ph2 = _) const;
 | 
			
		||||
    Block<DMatBase>      y(const PlaceHolder ph1, const Index k);
 | 
			
		||||
    ConstBlock<DMatBase> 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<DMatBase>      xxVar(const Index i1, const Index i2);
 | 
			
		||||
    ConstBlock<DMatBase> xxVar(const Index i1, const Index i2) const;
 | 
			
		||||
    Block<DMatBase>      yyVar(const Index j1, const Index j2);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user