1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-04-10 19:20:44 +01:00

latan-sample-fake now takes option -r/--seed where seed can be specified if fake bootstrap samples with 100% correlation are needed.

This commit is contained in:
Andrew Zhen Ning Yong 2020-11-13 07:56:58 +00:00
parent ddee922e72
commit 1b12f2ca2d

View File

@ -18,30 +18,42 @@
*/ */
#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;
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 << "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;
mt19937 gen(rd()); SeedType seed = (opt.gotOption("r")) ? opt.optionValue<SeedType>("r") : rd();
mt19937 gen(seed);
normal_distribution<> dis(val, err); normal_distribution<> dis(val, err);
DSample res(nSample); DSample res(nSample);
@ -59,4 +71,4 @@ int main(int argc, char *argv[])
Io::save<DSample>(res, outFileName); Io::save<DSample>(res, outFileName);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }