1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-21 08:32:01 +01:00

13 Commits

30 changed files with 539 additions and 319 deletions

View File

@ -1,6 +1,6 @@
name: Build macOS name: Build macOS
on: [push] on: [push, workflow_dispatch]
jobs: jobs:
build: build:

5
.gitignore vendored
View File

@ -25,9 +25,10 @@ lib/*Lexer.cpp
lib/*Parser.cpp lib/*Parser.cpp
lib/*Parser.hpp lib/*Parser.hpp
# Eigen headers # Eigen headers and archives
lib/Eigen/* lib/Eigen
lib/eigen_files.mk lib/eigen_files.mk
eigen-*.tar.bz2
# CI builds # CI builds
ci-scripts/local/* ci-scripts/local/*

View File

@ -2,5 +2,5 @@
rm -rf .buildutils rm -rf .buildutils
mkdir -p .buildutils/m4 mkdir -p .buildutils/m4
./update_eigen.sh eigen-3.3.8.tar.bz2 ./update_eigen.sh eigen-3.4.0.tar.bz2
autoreconf -fvi autoreconf -fvi

View File

@ -1,24 +0,0 @@
#!/bin/bash
set -e
PREFIX=`cat Makefile | grep '^prefix =' | awk '{print $3}'`
case $1 in
'')
echo '-- building...'
make -j8
echo '-- installing...'
make uninstall 1>/dev/null
make install 1>/dev/null;;
# if [[ `basename \`pwd\`` == "lib" ]]
# then
# echo '-- creating debug symbols...'
# dsymutil .libs/libLatAnalyze.0.dylib -o ${PREFIX}/lib/libLatAnalyze.0.dylib.dSYM
# fi;;
'clean')
echo '-- cleaning...'
make -j8 clean;;
*)
echo 'error: unknown action' 1>&2
exit 1;;
esac

Binary file not shown.

View File

@ -7,7 +7,7 @@
using namespace std; using namespace std;
using namespace Latan; using namespace Latan;
constexpr Index size = 8; constexpr Index n = 8;
constexpr Index nDraw = 20000; constexpr Index nDraw = 20000;
constexpr Index nSample = 2000; constexpr Index nSample = 2000;
const string stateFileName = "exRand.seed"; const string stateFileName = "exRand.seed";
@ -40,14 +40,14 @@ int main(void)
p << PlotFunction(compile("return exp(-x_0^2/2)/sqrt(2*pi);", 1), -5., 5.); p << PlotFunction(compile("return exp(-x_0^2/2)/sqrt(2*pi);", 1), -5., 5.);
p.display(); p.display();
DMat var(size, size); DMat var(n, n);
DVec mean(size); DVec mean(n);
DMatSample sample(nSample, size, 1); DMatSample sample(nSample, n, 1);
cout << "-- generating " << nSample << " Gaussian random vectors..." << endl; cout << "-- generating " << nSample << " Gaussian random vectors..." << endl;
var = DMat::Random(size, size); var = DMat::Random(n, n);
var *= var.adjoint(); var *= var.adjoint();
mean = DVec::Random(size); mean = DVec::Random(n);
RandomNormal mgauss(mean, var, rd()); RandomNormal mgauss(mean, var, rd());
sample[central] = mgauss(); sample[central] = mgauss();
FOR_STAT_ARRAY(sample, s) FOR_STAT_ARRAY(sample, s)

View File

@ -18,6 +18,7 @@
*/ */
#include <LatAnalyze/Core/Math.hpp> #include <LatAnalyze/Core/Math.hpp>
#include <LatAnalyze/Numerical/GslFFT.hpp>
#include <LatAnalyze/includes.hpp> #include <LatAnalyze/includes.hpp>
#include <gsl/gsl_cdf.h> #include <gsl/gsl_cdf.h>
@ -48,16 +49,42 @@ DMat MATH_NAMESPACE::corrToVar(const DMat &corr, const DVec &varDiag)
return res; return res;
} }
double MATH_NAMESPACE::svdDynamicRange(const DMat &mat) double MATH_NAMESPACE::conditionNumber(const DMat &mat)
{ {
DVec s = mat.singularValues(); DVec s = mat.singularValues();
return s.maxCoeff()/s.minCoeff(); return s.maxCoeff()/s.minCoeff();
} }
double MATH_NAMESPACE::svdDynamicRangeDb(const DMat &mat) double MATH_NAMESPACE::cdr(const DMat &mat)
{ {
return 10.*log10(svdDynamicRange(mat)); return 10.*log10(conditionNumber(mat));
}
template <typename FFT>
double nsdr(const DMat &m)
{
Index n = m.rows();
FFT fft(n);
CMat buf(n, 1);
FOR_VEC(buf, i)
{
buf(i) = 0.;
for (Index j = 0; j < n; ++j)
{
buf(i) += m(j, (i+j) % n);
}
buf(i) /= n;
}
fft(buf, FFT::Forward);
return 10.*log10(buf.real().maxCoeff()/buf.real().minCoeff());
}
double MATH_NAMESPACE::nsdr(const DMat &mat)
{
return ::nsdr<GslFFT>(mat);
} }
/****************************************************************************** /******************************************************************************

View File

@ -73,8 +73,9 @@ namespace MATH_NAMESPACE
DMat corrToVar(const DMat &corr, const DVec &varDiag); DMat corrToVar(const DMat &corr, const DVec &varDiag);
// matrix SVD dynamic range // matrix SVD dynamic range
double svdDynamicRange(const DMat &mat); double conditionNumber(const DMat &mat);
double svdDynamicRangeDb(const DMat &mat); double cdr(const DMat &mat);
double nsdr(const DMat &mat);
// Constants // Constants
constexpr double pi = 3.1415926535897932384626433832795028841970; constexpr double pi = 3.1415926535897932384626433832795028841970;

View File

@ -515,14 +515,16 @@ void Dash::operator()(PlotOptions &option) const
} }
// LogScale constructor //////////////////////////////////////////////////////// // LogScale constructor ////////////////////////////////////////////////////////
LogScale::LogScale(const Axis axis) LogScale::LogScale(const Axis axis, const double basis)
: axis_(axis) : axis_(axis)
, basis_(basis)
{} {}
// Logscale modifier /////////////////////////////////////////////////////////// // Logscale modifier ///////////////////////////////////////////////////////////
void LogScale::operator()(PlotOptions &option) const void LogScale::operator()(PlotOptions &option) const
{ {
option.scaleMode[static_cast<int>(axis_)] |= Plot::Scale::log; option.scaleMode[static_cast<int>(axis_)] |= Plot::Scale::log;
option.logScaleBasis[static_cast<int>(axis_)] = basis_;
} }
// PlotRange constructors ////////////////////////////////////////////////////// // PlotRange constructors //////////////////////////////////////////////////////
@ -915,11 +917,11 @@ ostream & Latan::operator<<(ostream &out, const Plot &plot)
out << "unset log" << endl; out << "unset log" << endl;
if (plot.options_.scaleMode[x] & Plot::Scale::log) if (plot.options_.scaleMode[x] & Plot::Scale::log)
{ {
out << "set log x" << endl; out << "set log x " << plot.options_.logScaleBasis[x] << endl;;
} }
if (plot.options_.scaleMode[y] & Plot::Scale::log) if (plot.options_.scaleMode[y] & Plot::Scale::log)
{ {
out << "set log y" << endl; out << "set log y " << plot.options_.logScaleBasis[y] << endl;
} }
if (!plot.options_.label[x].empty()) if (!plot.options_.label[x].empty())
{ {

View File

@ -227,6 +227,7 @@ struct PlotOptions
std::string caption; std::string caption;
std::string title; std::string title;
unsigned int scaleMode[2]; unsigned int scaleMode[2];
double logScaleBasis[2];
Range scale[2]; Range scale[2];
std::string label[2]; std::string label[2];
std::string lineColor; std::string lineColor;
@ -314,13 +315,14 @@ class LogScale: public PlotModifier
{ {
public: public:
// constructor // constructor
explicit LogScale(const Axis axis); explicit LogScale(const Axis axis, const double basis = 10);
// destructor // destructor
virtual ~LogScale(void) = default; virtual ~LogScale(void) = default;
// modifier // modifier
virtual void operator()(PlotOptions &option) const; virtual void operator()(PlotOptions &option) const;
private: private:
const Axis axis_; const Axis axis_;
const double basis_;
}; };
class PlotRange: public PlotModifier class PlotRange: public PlotModifier

View File

@ -108,23 +108,6 @@ inline std::string strFrom(const T x)
} }
// specialization for vectors // specialization for vectors
template<>
inline std::vector<Index> strTo<std::vector<Index>>(const std::string &str)
{
std::vector<Index> res;
std::vector<double> vbuf;
double buf;
std::istringstream stream(str);
while (!stream.eof())
{
stream >> buf;
res.push_back(buf);
}
return res;
}
template<> template<>
inline DVec strTo<DVec>(const std::string &str) inline DVec strTo<DVec>(const std::string &str)
{ {

View File

@ -58,6 +58,7 @@ libLatAnalyze_la_SOURCES = \
Numerical/RootFinder.cpp \ Numerical/RootFinder.cpp \
Numerical/Solver.cpp \ Numerical/Solver.cpp \
Physics/CorrelatorFitter.cpp \ Physics/CorrelatorFitter.cpp \
Physics/DataFilter.cpp \
Physics/EffectiveMass.cpp \ Physics/EffectiveMass.cpp \
Statistics/FitInterface.cpp \ Statistics/FitInterface.cpp \
Statistics/Histogram.cpp \ Statistics/Histogram.cpp \
@ -106,6 +107,7 @@ HPPFILES = \
Numerical/RootFinder.hpp \ Numerical/RootFinder.hpp \
Numerical/Solver.hpp \ Numerical/Solver.hpp \
Physics/CorrelatorFitter.hpp \ Physics/CorrelatorFitter.hpp \
Physics/DataFilter.hpp \
Physics/EffectiveMass.hpp \ Physics/EffectiveMass.hpp \
Statistics/Dataset.hpp \ Statistics/Dataset.hpp \
Statistics/FitInterface.hpp \ Statistics/FitInterface.hpp \

View File

@ -32,46 +32,91 @@ DWT::DWT(const DWTFilter &filter)
{} {}
// convolution primitive /////////////////////////////////////////////////////// // convolution primitive ///////////////////////////////////////////////////////
void DWT::filterConvolution(DVec &out, const DVec &data, template <typename MatType>
const std::vector<double> &filter, const Index offset) void filterConvolution(MatType &out, const MatType &data,
const std::vector<double> &filter, const Index offset)
{ {
Index n = data.size(), nf = n*filter.size(); Index n = data.rows(), nf = n*filter.size();
out.resize(n); out.resizeLike(data);
out.fill(0.); out.fill(0.);
for (unsigned int i = 0; i < filter.size(); ++i) for (unsigned int i = 0; i < filter.size(); ++i)
{ {
FOR_VEC(out, j) FOR_MAT(out, j, k)
{ {
out(j) += filter[i]*data((j + i + nf - offset) % n); out(j, k) += filter[i]*data((j + i + nf - offset) % n, k);
} }
} }
} }
void DWT::filterConvolution(DVec &out, const DVec &data,
const std::vector<double> &filter, const Index offset)
{
::filterConvolution(out, data, filter, offset);
}
void DWT::filterConvolution(DMat &out, const DMat &data,
const std::vector<double> &filter, const Index offset)
{
::filterConvolution(out, data, filter, offset);
}
// downsampling/upsampling primitives ////////////////////////////////////////// // downsampling/upsampling primitives //////////////////////////////////////////
template <typename MatType>
void downsample(MatType &out, const MatType &in)
{
if (out.rows() < in.rows()/2)
{
LATAN_ERROR(Size, "output rows smaller than half the input vector rows");
}
if (out.cols() != in.cols())
{
LATAN_ERROR(Size, "output and input number of columns mismatch");
}
for (Index j = 0; j < in.cols(); j++)
for (Index i = 0; i < in.rows(); i += 2)
{
out(i/2, j) = in(i, j);
}
}
void DWT::downsample(DVec &out, const DVec &in) void DWT::downsample(DVec &out, const DVec &in)
{ {
if (out.size() < in.size()/2) ::downsample(out, in);
}
void DWT::downsample(DMat &out, const DMat &in)
{
::downsample(out, in);
}
template <typename MatType>
void upsample(MatType &out, const MatType &in)
{
if (out.size() < 2*in.size())
{ {
LATAN_ERROR(Size, "output vector smaller than half the input vector size"); LATAN_ERROR(Size, "output rows smaller than twice the input rows");
} }
for (Index i = 0; i < in.size(); i += 2) if (out.cols() != in.cols())
{ {
out(i/2) = in(i); LATAN_ERROR(Size, "output and input number of columns mismatch");
}
out.block(0, 0, 2*in.size(), out.cols()).fill(0.);
for (Index j = 0; j < in.cols(); j++)
for (Index i = 0; i < in.size(); i ++)
{
out(2*i, j) = in(i, j);
} }
} }
void DWT::upsample(DVec &out, const DVec &in) void DWT::upsample(DVec &out, const DVec &in)
{ {
if (out.size() < 2*in.size()) ::upsample(out, in);
{ }
LATAN_ERROR(Size, "output vector smaller than twice the input vector size");
} void DWT::upsample(DMat &out, const DMat &in)
out.segment(0, 2*in.size()).fill(0.); {
for (Index i = 0; i < in.size(); i ++) ::upsample(out, in);
{
out(2*i) = in(i);
}
} }
// DWT ///////////////////////////////////////////////////////////////////////// // DWT /////////////////////////////////////////////////////////////////////////
@ -135,3 +180,26 @@ DVec DWT::backward(const std::vector<DWTLevel>& dwt) const
return res; return res;
} }
// concatenate levels //////////////////////////////////////////////////////////
DVec DWT::concat(const std::vector<DWTLevel> &dwt, const int maxLevel, const bool dropLow)
{
unsigned int level = ((maxLevel >= 0) ? (maxLevel + 1) : dwt.size());
Index nlast = dwt[level - 1].first.size();
Index n = 2*dwt.front().first.size() - ((dropLow) ? nlast : 0);
Index pt = n, nl;
DVec res(n);
for (unsigned int l = 0; l < level; ++l)
{
nl = dwt[l].second.size();
pt -= nl;
res.segment(pt, nl) = dwt[l].second;
}
if (!dropLow)
{
res.segment(0, nl) = dwt[level-1].first;
}
return res;
}

View File

@ -22,6 +22,7 @@
#include <LatAnalyze/Global.hpp> #include <LatAnalyze/Global.hpp>
#include <LatAnalyze/Numerical/DWTFilters.hpp> #include <LatAnalyze/Numerical/DWTFilters.hpp>
#include <LatAnalyze/Core/Mat.hpp>
BEGIN_LATAN_NAMESPACE BEGIN_LATAN_NAMESPACE
@ -40,12 +41,18 @@ public:
// convolution primitive // convolution primitive
static void filterConvolution(DVec &out, const DVec &data, static void filterConvolution(DVec &out, const DVec &data,
const std::vector<double> &filter, const Index offset); const std::vector<double> &filter, const Index offset);
static void filterConvolution(DMat &out, const DMat &data,
const std::vector<double> &filter, const Index offset);
// downsampling/upsampling primitives // downsampling/upsampling primitives
static void downsample(DVec &out, const DVec &in); static void downsample(DVec &out, const DVec &in);
static void downsample(DMat &out, const DMat &in);
static void upsample(DVec &out, const DVec &in); static void upsample(DVec &out, const DVec &in);
static void upsample(DMat &out, const DMat &in);
// DWT // DWT
std::vector<DWTLevel> forward(const DVec &data, const unsigned int level) const; std::vector<DWTLevel> forward(const DVec &data, const unsigned int level) const;
DVec backward(const std::vector<DWTLevel>& dwt) const; DVec backward(const std::vector<DWTLevel>& dwt) const;
// concatenate levels
static DVec concat(const std::vector<DWTLevel>& dwt, const int maxLevel = -1, const bool dropLow = false);
private: private:
DWTFilter filter_; DWTFilter filter_;
}; };

View File

@ -253,39 +253,16 @@ DMatSample CorrelatorUtils::shift(const DMatSample &c, const Index ts)
} }
} }
DMatSample CorrelatorUtils::fold(const DMatSample &c, const CorrelatorModels::ModelPar &par) DMatSample CorrelatorUtils::fold(const DMatSample &c)
{ {
const Index nt = c[central].rows(); const Index nt = c[central].rows();
DMatSample buf = c; DMatSample buf = c;
int sign;
bool fold = false;
switch (par.type) FOR_STAT_ARRAY(buf, s)
{ {
case CorrelatorType::cosh: for (Index t = 0; t < nt; ++t)
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)
{ {
for (Index t = 0; t < nt; ++t) buf[s](t) = 0.5*(c[s](t) + c[s]((nt - t) % nt));
{
buf[s](t) = 0.5*(c[s](t) + sign*c[s]((nt - t) % nt));
}
} }
} }

View File

@ -56,7 +56,7 @@ namespace CorrelatorModels
namespace CorrelatorUtils namespace CorrelatorUtils
{ {
DMatSample shift(const DMatSample &c, const Index ts); DMatSample shift(const DMatSample &c, const Index ts);
DMatSample fold(const DMatSample &c, const CorrelatorModels::ModelPar &par); DMatSample fold(const DMatSample &c);
DMatSample fourierTransform(const DMatSample &c, FFT &fft, DMatSample fourierTransform(const DMatSample &c, FFT &fft,
const unsigned int dir = FFT::Forward); const unsigned int dir = FFT::Forward);
}; };

View File

@ -0,0 +1,83 @@
/*
* DataFilter.cpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2020 Antonin Portelli
*
* 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/>.
*/
#include <LatAnalyze/Physics/DataFilter.hpp>
#include <LatAnalyze/includes.hpp>
#include <LatAnalyze/Numerical/DWT.hpp>
using namespace std;
using namespace Latan;
/******************************************************************************
* DataFilter implementation *
******************************************************************************/
// constructor ////////////////////////////////////////////////////////////////
DataFilter::DataFilter(const vector<double> &filter, const bool downsample)
: filter_(filter), downsample_(downsample)
{}
// filtering //////////////////////////////////////////////////////////////////
template <typename MatType>
void filter(MatType &out, const MatType &in, const vector<double> &filter,
const bool downsample, MatType &buf)
{
if (!downsample)
{
out.resizeLike(in);
DWT::filterConvolution(out, in, filter, filter.size()/2);
}
else
{
out.resize(in.rows()/2, in.cols());
buf.resizeLike(in);
DWT::filterConvolution(buf, in, filter, filter.size()/2);
DWT::downsample(out, buf);
}
}
void DataFilter::operator()(DVec &out, const DVec &in)
{
filter(out, in, filter_, downsample_, vBuf_);
}
void DataFilter::operator()(DMat &out, const DMat &in)
{
filter(out, in, filter_, downsample_, mBuf_);
}
/******************************************************************************
* LaplaceDataFilter implementation *
******************************************************************************/
// constructor ////////////////////////////////////////////////////////////////
LaplaceDataFilter::LaplaceDataFilter(const bool downsample)
: DataFilter({1., -2. , 1.}, downsample)
{}
// filtering //////////////////////////////////////////////////////////////////
void LaplaceDataFilter::operator()(DVec &out, const DVec &in, const double lambda)
{
filter_[1] = -2. - lambda;
DataFilter::operator()(out, in);
}
void LaplaceDataFilter::operator()(DMat &out, const DMat &in, const double lambda)
{
filter_[1] = -2. - lambda;
DataFilter::operator()(out, in);
}

139
lib/Physics/DataFilter.hpp Normal file
View File

@ -0,0 +1,139 @@
/*
* DataFilter.hpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2020 Antonin Portelli
*
* 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/>.
*/
#ifndef Latan_DataFilter_hpp_
#define Latan_DataFilter_hpp_
#include <LatAnalyze/Global.hpp>
#include <LatAnalyze/Core/Math.hpp>
#include <LatAnalyze/Statistics/StatArray.hpp>
#include <LatAnalyze/Statistics/MatSample.hpp>
#include <LatAnalyze/Numerical/Minimizer.hpp>
BEGIN_LATAN_NAMESPACE
/******************************************************************************
* Generic convolution filter class *
******************************************************************************/
class DataFilter
{
public:
// constructor
DataFilter(const std::vector<double> &filter, const bool downsample = false);
// filtering
void operator()(DVec &out, const DVec &in);
void operator()(DMat &out, const DMat &in);
template <typename MatType, Index o>
void operator()(StatArray<MatType, o> &out, const StatArray<MatType, o> &in);
protected:
std::vector<double> filter_;
private:
bool downsample_;
DVec vBuf_;
DMat mBuf_;
};
/******************************************************************************
* Laplacian filter class *
******************************************************************************/
class LaplaceDataFilter: public DataFilter
{
public:
// constructor
LaplaceDataFilter(const bool downsample = false);
// filtering
void operator()(DVec &out, const DVec &in, const double lambda = 0.);
void operator()(DMat &out, const DMat &in, const double lambda = 0.);
template <typename MatType, Index o>
void operator()(StatArray<MatType, o> &out, const StatArray<MatType, o> &in,
const double lambda = 0.);
// correlation optimisation
template <typename MatType, Index o>
double optimiseCdr(const StatArray<MatType, o> &data, Minimizer &min,
const unsigned int nPass = 3);
};
/******************************************************************************
* DataFilter class template implementation *
******************************************************************************/
// filtering //////////////////////////////////////////////////////////////////
template <typename MatType, Index o>
void DataFilter::operator()(StatArray<MatType, o> &out, const StatArray<MatType, o> &in)
{
FOR_STAT_ARRAY(in, s)
{
(*this)(out[s], in[s]);
}
}
/******************************************************************************
* LaplaceDataFilter class template implementation *
******************************************************************************/
// filtering //////////////////////////////////////////////////////////////////
template <typename MatType, Index o>
void LaplaceDataFilter::operator()(StatArray<MatType, o> &out,
const StatArray<MatType, o> &in, const double lambda)
{
FOR_STAT_ARRAY(in, s)
{
(*this)(out[s], in[s], lambda);
}
}
// correlation optimisation ///////////////////////////////////////////////////
template <typename MatType, Index o>
double LaplaceDataFilter::optimiseCdr(const StatArray<MatType, o> &data,
Minimizer &min, const unsigned int nPass)
{
StatArray<MatType, o> fdata(data.size());
DVec init(1);
double reg, prec;
DoubleFunction cdr([&data, &fdata, this](const double *x)
{
double res;
(*this)(fdata, data, x[0]);
res = Math::cdr(fdata.correlationMatrix());
return res;
}, 1);
min.setLowLimit(0., -0.1);
min.setHighLimit(0., 100000.);
init(0) = 0.1;
min.setInit(init);
prec = 0.1;
min.setPrecision(prec);
reg = min(cdr)(0);
for (unsigned int pass = 0; pass < nPass; pass++)
{
min.setLowLimit(0., (1.-10.*prec)*reg);
min.setHighLimit(0., (1.+10.*prec)*reg);
init(0) = reg;
min.setInit(init);
prec *= 0.1;
min.setPrecision(prec);
reg = min(cdr)(0);
}
return reg;
}
END_LATAN_NAMESPACE
#endif // Latan_DataFilter_hpp_

View File

@ -146,16 +146,6 @@ double Histogram::getX(const Index i) const
return x_(i); return x_(i);
} }
double Histogram::getXMin(void) const
{
return xMin_;
}
double Histogram::getXMax(void) const
{
return xMax_;
}
double Histogram::operator[](const Index i) const double Histogram::operator[](const Index i) const
{ {
return bin_(i)*(isNormalized() ? norm_ : 1.); return bin_(i)*(isNormalized() ? norm_ : 1.);

View File

@ -52,8 +52,6 @@ public:
const StatArray<double> & getData(void) const; const StatArray<double> & getData(void) const;
const StatArray<double> & getWeight(void) const; const StatArray<double> & getWeight(void) const;
double getX(const Index i) const; double getX(const Index i) const;
double getXMin(void) const;
double getXMax(void) const;
double operator[](const Index i) const; double operator[](const Index i) const;
double operator()(const double x) const; double operator()(const double x) const;
// percentiles & confidence interval // percentiles & confidence interval

View File

@ -103,10 +103,6 @@ public:
const Index nCol); const Index nCol);
// resize all matrices // resize all matrices
void resizeMat(const Index nRow, const Index nCol); void resizeMat(const Index nRow, const Index nCol);
// covariance matrix
Mat<T> covarianceMatrix(const MatSample<T> &sample) const;
Mat<T> varianceMatrix(void) const;
Mat<T> correlationMatrix(void) const;
}; };
// non-member operators // non-member operators
@ -383,79 +379,6 @@ void MatSample<T>::resizeMat(const Index nRow, const Index nCol)
} }
} }
// covariance matrix ///////////////////////////////////////////////////////////
template <typename T>
Mat<T> MatSample<T>::covarianceMatrix(const MatSample<T> &sample) const
{
if (((*this)[central].cols() != 1) or (sample[central].cols() != 1))
{
LATAN_ERROR(Size, "samples have more than one column");
}
Index n1 = (*this)[central].rows(), n2 = sample[central].rows();
Index nSample = this->size();
Mat<T> tmp1(n1, nSample), tmp2(n2, nSample), res(n1, n2);
Mat<T> s1(n1, 1), s2(n2, 1), one(nSample, 1);
one.fill(1.);
s1.fill(0.);
s2.fill(0.);
for (unsigned int s = 0; s < nSample; ++s)
{
s1 += (*this)[s];
tmp1.col(s) = (*this)[s];
}
tmp1 -= s1*one.transpose()/static_cast<double>(nSample);
for (unsigned int s = 0; s < nSample; ++s)
{
s2 += sample[s];
tmp2.col(s) = sample[s];
}
tmp2 -= s2*one.transpose()/static_cast<double>(nSample);
res = tmp1*tmp2.transpose()/static_cast<double>(nSample - 1);
return res;
}
template <typename T>
Mat<T> MatSample<T>::varianceMatrix(void) const
{
if ((*this)[central].cols() != 1)
{
LATAN_ERROR(Size, "samples have more than one column");
}
Index n1 = (*this)[central].rows();
Index nSample = this->size();
Mat<T> tmp1(n1, nSample), res(n1, n1);
Mat<T> s1(n1, 1), one(nSample, 1);
one.fill(1.);
s1.fill(0.);
for (unsigned int s = 0; s < nSample; ++s)
{
s1 += (*this)[s];
tmp1.col(s) = (*this)[s];
}
tmp1 -= s1*one.transpose()/static_cast<double>(nSample);
res = tmp1*tmp1.transpose()/static_cast<double>(nSample - 1);
return res;
}
template <typename T>
Mat<T> MatSample<T>::correlationMatrix(void) const
{
Mat<T> res = varianceMatrix();
Mat<T> invDiag(res.rows(), 1);
invDiag = res.diagonal();
invDiag = invDiag.cwiseInverse().cwiseSqrt();
res = (invDiag*invDiag.transpose()).cwiseProduct(res);
return res;
}
END_LATAN_NAMESPACE END_LATAN_NAMESPACE
#endif // Latan_MatSample_hpp_ #endif // Latan_MatSample_hpp_

View File

@ -52,10 +52,13 @@ public:
// statistics // statistics
void bin(Index binSize); void bin(Index binSize);
T sum(const Index pos = 0, const Index n = -1) const; T sum(const Index pos = 0, const Index n = -1) const;
T meanOld(const Index pos = 0, const Index n = -1) const;
T mean(const Index pos = 0, const Index n = -1) const; T mean(const Index pos = 0, const Index n = -1) const;
T covariance(const StatArray<T, os> &array) const; T covariance(const StatArray<T, os> &array) const;
T variance(void) const; T variance(void) const;
T covarianceMatrix(const StatArray<T, os> &data) const;
T varianceMatrix(void) const;
T correlationMatrix(void) const;
// IO type // IO type
virtual IoType getType(void) const; virtual IoType getType(void) const;
public: public:
@ -192,6 +195,79 @@ T StatArray<T, os>::variance(void) const
return covariance(*this); return covariance(*this);
} }
template <typename MatType, Index os>
MatType StatArray<MatType, os>::covarianceMatrix(
const StatArray<MatType, os> &data) const
{
if (((*this)[central].cols() != 1) or (data[central].cols() != 1))
{
LATAN_ERROR(Size, "samples have more than one column");
}
Index n1 = (*this)[central].rows(), n2 = data[central].rows();
Index nSample = this->size();
MatType tmp1(n1, nSample), tmp2(n2, nSample), res(n1, n2);
MatType s1(n1, 1), s2(n2, 1), one(nSample, 1);
one.fill(1.);
s1.fill(0.);
s2.fill(0.);
for (unsigned int s = 0; s < nSample; ++s)
{
s1 += (*this)[s];
tmp1.col(s) = (*this)[s];
}
tmp1 -= s1*one.transpose()/static_cast<double>(nSample);
for (unsigned int s = 0; s < nSample; ++s)
{
s2 += data[s];
tmp2.col(s) = data[s];
}
tmp2 -= s2*one.transpose()/static_cast<double>(nSample);
res = tmp1*tmp2.transpose()/static_cast<double>(nSample - 1);
return res;
}
template <typename MatType, Index os>
MatType StatArray<MatType, os>::varianceMatrix(void) const
{
if ((*this)[0].cols() != 1)
{
LATAN_ERROR(Size, "samples have more than one column");
}
Index n1 = (*this)[0].rows();
Index nSample = this->size();
MatType tmp1(n1, nSample), res(n1, n1);
MatType s1(n1, 1), one(nSample, 1);
one.fill(1.);
s1.fill(0.);
for (unsigned int s = 0; s < nSample; ++s)
{
s1 += (*this)[s];
tmp1.col(s) = (*this)[s];
}
tmp1 -= s1*one.transpose()/static_cast<double>(nSample);
res = tmp1*tmp1.transpose()/static_cast<double>(nSample - 1);
return res;
}
template <typename MatType, Index os>
MatType StatArray<MatType, os>::correlationMatrix(void) const
{
MatType res = varianceMatrix();
MatType invDiag(res.rows(), 1);
invDiag = res.diagonal();
invDiag = invDiag.cwiseInverse().cwiseSqrt();
res = (invDiag*invDiag.transpose()).cwiseProduct(res);
return res;
}
// reduction operations //////////////////////////////////////////////////////// // reduction operations ////////////////////////////////////////////////////////
namespace StatOp namespace StatOp
{ {

View File

@ -300,67 +300,6 @@ const XYStatData & XYSampleData::getData(void)
} }
// fit ///////////////////////////////////////////////////////////////////////// // fit /////////////////////////////////////////////////////////////////////////
void XYSampleData::fitSample(std::vector<Minimizer *> &minimizer,
const std::vector<const DoubleModel *> &v,
SampleFitResult &result,
DVec &init,
Index s)
{
result.resize(nSample_);
result.chi2_.resize(nSample_);
result.model_.resize(v.size());
FitResult sampleResult;
setDataToSample(s);
if (s == central)
{
sampleResult = data_.fit(minimizer, init, v);
init = sampleResult.segment(0, init.size());
result.nPar_ = sampleResult.getNPar();
result.nDof_ = sampleResult.nDof_;
result.parName_ = sampleResult.parName_;
result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat());
}
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);
}
}
SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
const DVec &init,
const std::vector<const DoubleModel *> &v,
Index s)
{
computeVarMat();
SampleFitResult result;
DVec initCopy = init;
fitSample(minimizer, v, result, initCopy, s);
return result;
}
SampleFitResult XYSampleData::fit(Minimizer &minimizer,
const DVec &init,
const std::vector<const DoubleModel *> &v,
Index s)
{
vector<Minimizer *> mv{&minimizer};
return fit(mv, init, v, s);
}
SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer, SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
const DVec &init, const DVec &init,
const std::vector<const DoubleModel *> &v) const std::vector<const DoubleModel *> &v)
@ -368,14 +307,43 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
computeVarMat(); computeVarMat();
SampleFitResult result; SampleFitResult result;
FitResult sampleResult;
DVec initCopy = init; DVec initCopy = init;
Minimizer::Verbosity verbCopy = minimizer.back()->getVerbosity(); Minimizer::Verbosity verbCopy = minimizer.back()->getVerbosity();
result.resize(nSample_);
result.chi2_.resize(nSample_);
result.model_.resize(v.size());
FOR_STAT_ARRAY(result, s) FOR_STAT_ARRAY(result, s)
{ {
fitSample(minimizer, v, result, initCopy, s); setDataToSample(s);
if (s == central)
{
sampleResult = data_.fit(minimizer, initCopy, v);
initCopy = sampleResult.segment(0, initCopy.size());
if (verbCopy != Minimizer::Verbosity::Debug)
{
minimizer.back()->setVerbosity(Minimizer::Verbosity::Silent);
}
}
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);
}
} }
minimizer.back()->setVerbosity(verbCopy); minimizer.back()->setVerbosity(verbCopy);
result.nPar_ = sampleResult.getNPar();
result.nDof_ = sampleResult.nDof_;
result.parName_ = sampleResult.parName_;
result.corrRangeDb_ = Math::cdr(getFitCorrMat());
return result; return result;
} }

View File

@ -103,13 +103,6 @@ public:
// get internal XYStatData // get internal XYStatData
const XYStatData & getData(void); const XYStatData & getData(void);
// fit // fit
void fitSample(std::vector<Minimizer *> &minimizer,
const std::vector<const DoubleModel *> &v,
SampleFitResult &sampleResult, DVec &init, Index s);
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,
const std::vector<const DoubleModel *> &v, Index s);
SampleFitResult fit(Minimizer &minimizer, const DVec &init,
const std::vector<const DoubleModel *> &v, Index s);
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init, SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,
const std::vector<const DoubleModel *> &v); const std::vector<const DoubleModel *> &v);
SampleFitResult fit(Minimizer &minimizer, const DVec &init, SampleFitResult fit(Minimizer &minimizer, const DVec &init,

View File

@ -358,7 +358,7 @@ FitResult XYStatData::fit(vector<Minimizer *> &minimizer, const DVec &init,
result = (*m)(chi2); result = (*m)(chi2);
totalInit = result; totalInit = result;
} }
result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat()); result.corrRangeDb_ = Math::cdr(getFitCorrMat());
result.chi2_ = chi2(result); result.chi2_ = chi2(result);
result.nPar_ = nPar; result.nPar_ = nPar;
result.nDof_ = layout.totalYSize - nPar; result.nDof_ = layout.totalYSize - nPar;

View File

@ -24,7 +24,7 @@ int main(int argc, char *argv[])
{ {
// parse arguments ///////////////////////////////////////////////////////// // parse arguments /////////////////////////////////////////////////////////
OptParser opt; OptParser opt;
bool parsed, doLaplace, doPlot, doHeatmap, doCorr, fold, doScan; bool parsed, doLaplace, doPlot, doHeatmap, doCorr, fold, doScan, noGuess;
string corrFileName, model, outFileName, outFmt, savePlot; string corrFileName, model, outFileName, outFmt, savePlot;
Index ti, tf, shift, nPar, thinning; Index ti, tf, shift, nPar, thinning;
double svdTol; double svdTol;
@ -59,6 +59,8 @@ int main(int argc, char *argv[])
"show the fit plot"); "show the fit plot");
opt.addOption("h", "heatmap" , OptParser::OptType::trigger, true, opt.addOption("h", "heatmap" , OptParser::OptType::trigger, true,
"show the fit correlation heatmap"); "show the fit correlation heatmap");
opt.addOption("", "no-guess" , OptParser::OptType::trigger, true,
"do not try to guess fit parameters");
opt.addOption("", "save-plot", OptParser::OptType::value, true, opt.addOption("", "save-plot", OptParser::OptType::value, true,
"saves the source and .pdf", ""); "saves the source and .pdf", "");
opt.addOption("", "scan", OptParser::OptType::trigger, true, opt.addOption("", "scan", OptParser::OptType::trigger, true,
@ -87,6 +89,7 @@ int main(int argc, char *argv[])
fold = opt.gotOption("fold"); fold = opt.gotOption("fold");
doPlot = opt.gotOption("p"); doPlot = opt.gotOption("p");
doHeatmap = opt.gotOption("h"); doHeatmap = opt.gotOption("h");
noGuess = opt.gotOption("no-guess");
savePlot = opt.optionValue("save-plot"); savePlot = opt.optionValue("save-plot");
doScan = opt.gotOption("scan"); doScan = opt.gotOption("scan");
switch (opt.optionValue<unsigned int>("v")) switch (opt.optionValue<unsigned int>("v"))
@ -114,7 +117,6 @@ int main(int argc, char *argv[])
nt = corr[central].rows(); nt = corr[central].rows();
corr = corr.block(0, 0, nt, 1); corr = corr.block(0, 0, nt, 1);
corr = CorrelatorUtils::shift(corr, shift); corr = CorrelatorUtils::shift(corr, shift);
if (doLaplace) if (doLaplace)
{ {
vector<double> filter = {1., -2., 1.}; vector<double> filter = {1., -2., 1.};
@ -156,11 +158,6 @@ int main(int argc, char *argv[])
} }
} }
if (fold)
{
corr = CorrelatorUtils::fold(corr,modelPar);
}
// fit ///////////////////////////////////////////////////////////////////// // fit /////////////////////////////////////////////////////////////////////
DVec init(nPar); DVec init(nPar);
NloptMinimizer globMin(NloptMinimizer::Algorithm::GN_CRS2_LM); NloptMinimizer globMin(NloptMinimizer::Algorithm::GN_CRS2_LM);
@ -173,13 +170,14 @@ int main(int argc, char *argv[])
fitter.setThinning(thinning); fitter.setThinning(thinning);
// set initial values ****************************************************** // set initial values ******************************************************
if (modelPar.type != CorrelatorType::undefined) if ((modelPar.type != CorrelatorType::undefined) and !noGuess)
{ {
init = CorrelatorModels::parameterGuess(corr, modelPar); init = CorrelatorModels::parameterGuess(corr, modelPar);
} }
else else
{ {
init.fill(0.1); init.fill(1.);
init(0) = 0.2;
} }
// set limits for minimisers *********************************************** // set limits for minimisers ***********************************************

View File

@ -17,6 +17,7 @@
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>. * along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <LatAnalyze/Core/Math.hpp>
#include <LatAnalyze/Core/OptParser.hpp> #include <LatAnalyze/Core/OptParser.hpp>
#include <LatAnalyze/Core/Plot.hpp> #include <LatAnalyze/Core/Plot.hpp>
#include <LatAnalyze/Io/Io.hpp> #include <LatAnalyze/Io/Io.hpp>
@ -53,6 +54,12 @@ int main(int argc, char *argv[])
cerr << "usage: " << argv[0]; cerr << "usage: " << argv[0];
cerr << " <options> <input file>" << endl; cerr << " <options> <input file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl; cerr << endl << "Possible options:" << endl << opt << endl;
cerr << "Available DWT filters:" << endl;
for (auto &fv: DWTFilters::fromName)
{
cerr << fv.first << " ";
}
cerr << endl << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -68,22 +75,45 @@ int main(int argc, char *argv[])
DMatSample in = Io::load<DMatSample>(inFilename), res; DMatSample in = Io::load<DMatSample>(inFilename), res;
Index nSample = in.size(), n = in[central].rows(); Index nSample = in.size(), n = in[central].rows();
vector<DMatSample> out(ss ? 1 : level, DMatSample(nSample)), vector<DMatSample> out(ss ? 1 : level, DMatSample(nSample)),
outh(ss ? 0 : level, DMatSample(nSample)); outh(ss ? 0 : level, DMatSample(nSample)),
concath(ss ? 0 : level, DMatSample(nSample));
DMatSample concat(nSample, n, 1);
DWT dwt(*DWTFilters::fromName.at(filterName)); DWT dwt(*DWTFilters::fromName.at(filterName));
vector<DWT::DWTLevel> dataDWT(level); vector<DWT::DWTLevel> dataDWT(level);
FOR_STAT_ARRAY(in, s)
{
in[s].conservativeResize(n, 1);
}
if (!ss) if (!ss)
{ {
DMatSample buf(nSample);
cout << "-- compute discrete wavelet transform" << endl; cout << "-- compute discrete wavelet transform" << endl;
cout << "filter '" << filterName << "' / " << level << " level(s)" << endl; cout << "filter '" << filterName << "' / " << level << " level(s)" << endl;
FOR_STAT_ARRAY(in, s) FOR_STAT_ARRAY(in, s)
{ {
dataDWT = dwt.forward(in[s].col(0), level); dataDWT = dwt.forward(in[s], level);
for (unsigned int l = 0; l < level; ++l) for (unsigned int l = 0; l < level; ++l)
{ {
out[l][s] = dataDWT[l].first; out[l][s] = dataDWT[l].first;
outh[l][s] = dataDWT[l].second; outh[l][s] = dataDWT[l].second;
concath[l][s] = DWT::concat(dataDWT, l, true);
} }
concat[s] = DWT::concat(dataDWT);
}
cout << "Data CDR " << Math::cdr(in.correlationMatrix()) << " dB" << endl;
cout << "DWT CDR " << Math::cdr(concat.correlationMatrix()) << " dB" << endl;
for (unsigned int l = 0; l < level; ++l)
{
cout << "DWT level " << l << " CDR: L= ";
cout << Math::cdr(out[l].correlationMatrix()) << " dB / H= ";
cout << Math::cdr(outh[l].correlationMatrix()) << " dB" << endl;
}
for (unsigned int l = 0; l < level; ++l)
{
cout << "DWT detail level " << l << " CDR: ";
cout << Math::cdr(concath[l].correlationMatrix()) << " dB" << endl;
} }
} }
else else
@ -102,7 +132,7 @@ int main(int argc, char *argv[])
} }
FOR_STAT_ARRAY(in, s) FOR_STAT_ARRAY(in, s)
{ {
dataDWT.back().first = in[s].col(0); dataDWT.back().first = in[s];
out[0][s] = dwt.backward(dataDWT); out[0][s] = dwt.backward(dataDWT);
} }
} }
@ -115,7 +145,9 @@ int main(int argc, char *argv[])
{ {
Io::save<DMatSample>(out[l], outFilename + "/L" + strFrom(l) + ".h5"); Io::save<DMatSample>(out[l], outFilename + "/L" + strFrom(l) + ".h5");
Io::save<DMatSample>(outh[l], outFilename + "/H" + strFrom(l) + ".h5"); Io::save<DMatSample>(outh[l], outFilename + "/H" + strFrom(l) + ".h5");
Io::save<DMatSample>(concath[l], outFilename + "/concatH" + strFrom(l) + ".h5");
} }
Io::save<DMatSample>(concat, outFilename + "/concat.h5");
} }
else else
{ {

View File

@ -18,42 +18,30 @@
*/ */
#include <LatAnalyze/Io/Io.hpp> #include <LatAnalyze/Io/Io.hpp>
#include <LatAnalyze/Core/OptParser.hpp>
using namespace std; using namespace std;
using namespace Latan; using namespace Latan;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
OptParser opt;
Index nSample; Index nSample;
double val, err; double val, err;
string outFileName; string outFileName;
opt.addOption("r", "seed" , OptParser::OptType::value, true, if (argc != 5)
"random generator seed (default: random)");
opt.addOption("", "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
bool parsed = opt.parse(argc, argv);
if (!parsed or (opt.getArgs().size() != 4) or opt.gotOption("help"))
{ {
cerr << "usage: " << argv[0]; cerr << "usage: " << argv[0];
cerr << " <central value> <error> <nSample> <output file>" << endl; cerr << " <central value> <error> <nSample> <output file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
val = strTo<double>(argv[1]); val = strTo<double>(argv[1]);
err = strTo<double>(argv[2]); err = strTo<double>(argv[2]);
nSample = strTo<Index>(argv[3]); nSample = strTo<Index>(argv[3]);
outFileName = argv[4]; outFileName = argv[4];
random_device rd; random_device rd;
SeedType seed = (opt.gotOption("r")) ? opt.optionValue<SeedType>("r") : rd(); mt19937 gen(rd());
mt19937 gen(seed);
normal_distribution<> dis(val, err); normal_distribution<> dis(val, err);
DSample res(nSample); DSample res(nSample);

View File

@ -68,7 +68,7 @@ int main(int argc, char *argv[])
var = sample.varianceMatrix(); var = sample.varianceMatrix();
corr = sample.correlationMatrix(); corr = sample.correlationMatrix();
cout << "dynamic range " << Math::svdDynamicRangeDb(corr) << " dB" << endl; cout << "dynamic range " << Math::cdr(corr) << " dB" << endl;
p << PlotCorrMatrix(corr); p << PlotCorrMatrix(corr);
p.display(); p.display();
if (!outVarName.empty()) if (!outVarName.empty())

View File

@ -38,23 +38,9 @@ int main(int argc, char *argv[])
{ {
DMatSample s = Io::load<DMatSample>(fileName); DMatSample s = Io::load<DMatSample>(fileName);
string name = Io::getFirstName(fileName); string name = Io::getFirstName(fileName);
Index nRows = s[central].rows();
Index nCols = s[central].cols();
cout << scientific; cout << scientific;
cout << "central value +/- standard deviation\n" << endl; cout << "central value:\n" << s[central] << endl;
cout << "Re:" << endl; cout << "standard deviation:\n" << s.variance().cwiseSqrt() << endl;
for(Index i = 0; i < nRows; i++)
{
cout << s[central](i,0) << " +/- " << s.variance().cwiseSqrt()(i,0) << endl;
}
if(nCols == 2)
{
cout << "\nIm:" << endl;
for(Index i = 0; i < nRows; i++)
{
cout << s[central](i,1) << " +/- " << s.variance().cwiseSqrt()(i,1) << endl;
}
}
if (!copy.empty()) if (!copy.empty())
{ {
Io::save(s, copy, File::Mode::write, name); Io::save(s, copy, File::Mode::write, name);
@ -65,8 +51,8 @@ int main(int argc, char *argv[])
DSample s = Io::load<DSample>(fileName); DSample s = Io::load<DSample>(fileName);
string name = Io::getFirstName(fileName); string name = Io::getFirstName(fileName);
cout << scientific; cout << scientific;
cout << "central value +/- standard deviation\n" << endl; cout << "central value:\n" << s[central] << endl;
cout << s[central] << " +/- " << sqrt(s.variance()) << endl; cout << "standard deviation:\n" << sqrt(s.variance()) << endl;
if (!copy.empty()) if (!copy.empty())
{ {
Io::save(s, copy, File::Mode::write, name); Io::save(s, copy, File::Mode::write, name);