1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-13 03:17:06 +01:00

38 Commits

Author SHA1 Message Date
cd4d739f46 Merge pull request #19 from AndrewYongZhenNing/develop
Corrected Sinh model's definition, init fit parameter & fold definition.
2022-10-12 19:07:24 +01:00
a20dff68d1 Merge branch 'andrew-pr' into develop 2022-10-12 19:07:06 +01:00
cb5a28dfa6 Merge branch 'develop' of https://github.com/AndrewYongZhenNing/LatAnalyze into develop 2022-05-03 10:06:21 +01:00
be72d31364 Added histogram feature to return xMax and xMin. 2022-05-03 10:04:50 +01:00
db08559632 Update Readme.md 2022-05-03 10:04:50 +01:00
8b259879ff utility to compute sample DWT 2022-05-03 10:04:50 +01:00
500210a2eb DWT working and tested 2022-05-03 10:04:50 +01:00
b9f61d8c17 first skeleton for DWT 2022-05-03 10:04:50 +01:00
51a46edb27 tool to merge samples 2022-05-03 10:04:50 +01:00
4436c575e6 correlation matrix plot compute dynamic range 2022-05-03 10:04:50 +01:00
e02a4bf30d data plots compatible with multi-column arrays 2022-05-03 10:04:50 +01:00
feb6f96589 Merge branch 'develop' of https://github.com/aportelli/LatAnalyze into develop 2022-04-15 11:25:46 +01:00
c442a437e5 Restructured sample-read to print stat err next to central value. 2022-03-25 09:38:32 +00:00
493d641e2f Modified fitSample routines to use SampleFitResult objects. 2022-03-04 10:36:30 +00:00
cd1aeac669 Merge from AP's develop. 2022-02-23 13:52:27 +00:00
db99951dd4 removed redundant pValue private member 2022-01-14 16:58:44 +00:00
a389e01aa0 corrected own bug in strTo<T> 2022-01-14 16:58:24 +00:00
d11c6f725c Merge branch 'alt-fit-scan' into Tesseract 2022-01-14 16:10:14 +00:00
15a5471bef strTo<> now converts string of numbers to vector<Index> 2022-01-14 16:03:52 +00:00
6eca1e6fc6 i) removed pvalue fit criteria
ii) overloaded fit() to output FitResult object of a particular sample
2021-10-07 17:44:10 +01:00
28aff209c4 New function fitSample to make XYSampleData::fit more modular:
Eg application: In fit scans, one may only want central fit for the uncorr fit to speed up process.
2021-09-22 15:53:26 +01:00
9c5ade4989 Changed fit criteria from chi2PerDof to pValue. 2021-09-22 12:35:41 +01:00
f0739047c3 XYSampleData throws Runtime exception error if central fit's chi2PerDof exceeds user-set/default bounds for chi2PerDof. This can be used to skip fits with bad fitranges. 2021-08-25 15:59:00 +01:00
6990d16ca0 Merge remote-tracking branch 'fork/develop' into develop 2021-08-25 14:55:52 +01:00
80e3c27d8e Added private variables to set bound on chi2perDof. This is used tas criteria for fit scans.
TODO: modify to exception handling.
2021-08-25 14:53:52 +01:00
2b52ee4512 Merge remote-tracking branch 'fork/develop' into develop 2021-05-21 15:33:52 +01:00
af31d1564d Previous commit failed to compile: needed to remove leftover lines. 2021-05-21 15:33:34 +01:00
938b96bf95 Merge remote-tracking branch 'fork/develop' into develop 2021-05-21 15:30:02 +01:00
375b8fd038 Removed criteria of rejecting fits if sample fit chi2PerDof is bad. 2021-05-21 15:29:24 +01:00
a7d020e0f9 Merge remote-tracking branch 'fork/develop' into develop 2021-05-20 11:51:53 +01:00
c48e2be20b Added feature to reject fit if 25% of sample fits are bad (with chi2perdof > 2 or is a NaN) 2021-05-20 11:51:29 +01:00
113b433b5e Merge remote-tracking branch 'fork/develop' into develop 2021-05-20 11:14:53 +01:00
9e8d534635 New methods in XYSampleData class to skip fits that are non-converging/large chi2PerDof.
This is tracked by boolean goodFit_.
2021-05-20 11:05:25 +01:00
1b12f2ca2d latan-sample-fake now takes option -r/--seed where seed can be specified if fake bootstrap samples with 100% correlation are needed. 2020-11-13 07:56:58 +00:00
ddee922e72 1) restored original definition of sinh in makeSinhModel() and its init in parameterGuess(). 2) fold definition includes sign factor due to cosh/sinh model. 2020-07-10 08:33:28 +01:00
7b3b203ca9 Merge remote-tracking branch 'upstream/develop' into develop 2020-07-07 10:09:01 +01:00
3e3cdf2d69 2pt-fit.cpp now has correct number of arguments for fold function if --fold is called. 2020-07-07 10:07:48 +01:00
b6c2efa666 1) fold now requires second argument: modelPar to properly fold correlators with cosh/sinh form. 2) makeSinhModel has the appropriate alternate sign s.t the prefactor remains positive. 3) parameterGuess uses correct analytic form for sinh-type correlator's init(1), corresponding to the prefactor. 2020-07-07 10:07:05 +01:00
10 changed files with 168 additions and 45 deletions

View File

@ -108,6 +108,23 @@ inline std::string strFrom(const T x)
}
// 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<>
inline DVec strTo<DVec>(const std::string &str)
{

View File

@ -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));
}
}
}

View File

@ -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);
};

View File

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

View File

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

View File

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

View File

@ -103,9 +103,16 @@ public:
// get internal XYStatData
const XYStatData & getData(void);
// fit
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,
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,
const std::vector<const DoubleModel *> &v);
SampleFitResult fit(Minimizer &minimizer, const DVec &init,
SampleFitResult fit(Minimizer &minimizer, const DVec &init,
const std::vector<const DoubleModel *> &v);
template <typename... Ts>
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,

View File

@ -114,6 +114,7 @@ int main(int argc, char *argv[])
nt = corr[central].rows();
corr = corr.block(0, 0, nt, 1);
corr = CorrelatorUtils::shift(corr, shift);
if (doLaplace)
{
vector<double> filter = {1., -2., 1.};
@ -155,6 +156,11 @@ int main(int argc, char *argv[])
}
}
if (fold)
{
corr = CorrelatorUtils::fold(corr,modelPar);
}
// fit /////////////////////////////////////////////////////////////////////
DVec init(nPar);
NloptMinimizer globMin(NloptMinimizer::Algorithm::GN_CRS2_LM);

View File

@ -18,30 +18,42 @@
*/
#include <LatAnalyze/Io/Io.hpp>
#include <LatAnalyze/Core/OptParser.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char *argv[])
{
OptParser opt;
Index nSample;
double val, err;
string outFileName;
if (argc != 5)
opt.addOption("r", "seed" , OptParser::OptType::value, true,
"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 << " <central value> <error> <nSample> <output file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
val = strTo<double>(argv[1]);
err = strTo<double>(argv[2]);
nSample = strTo<Index>(argv[3]);
outFileName = argv[4];
random_device rd;
mt19937 gen(rd());
SeedType seed = (opt.gotOption("r")) ? opt.optionValue<SeedType>("r") : rd();
mt19937 gen(seed);
normal_distribution<> dis(val, err);
DSample res(nSample);
@ -59,4 +71,4 @@ int main(int argc, char *argv[])
Io::save<DSample>(res, outFileName);
return EXIT_SUCCESS;
}
}

View File

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