1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-14 01:45:35 +00:00

sample_read util update and resampling util

This commit is contained in:
Antonin Portelli 2014-02-17 18:50:26 +00:00
parent b53b47fcda
commit 7699dad913
3 changed files with 103 additions and 10 deletions

View File

@ -15,10 +15,15 @@ endif
endif endif
noinst_PROGRAMS = \ noinst_PROGRAMS = \
latan_sample_read latan_sample_read\
latan_resample
latan_sample_read_SOURCES = sample_read.cpp latan_sample_read_SOURCES = sample_read.cpp
latan_sample_read_CFLAGS = -g -O2 latan_sample_read_CFLAGS = -g -O2
latan_sample_read_LDFLAGS = -L../latan/.libs -llatan latan_sample_read_LDFLAGS = -L../latan/.libs -llatan
latan_resample_SOURCES = resample.cpp
latan_resample_CFLAGS = -g -O2
latan_resample_LDFLAGS = -L../latan/.libs -llatan
ACLOCAL_AMFLAGS = -I .buildutils/m4 ACLOCAL_AMFLAGS = -I .buildutils/m4

85
utils/resample.cpp Normal file
View File

@ -0,0 +1,85 @@
#include <iostream>
#include <libgen.h>
#include <unistd.h>
#include <latan/Dataset.hpp>
#include <latan/Io.hpp>
#ifndef DEF_NSAMPLE
#define DEF_NSAMPLE 100u
#endif
using namespace std;
using namespace Latan;
static void usage(const string &cmdName)
{
cerr << "usage: " << cmdName
<< " [-n <nsample> -r <state> -o <output>] <manifest> <name> "
<< endl;
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
int c;
unsigned int nSample = DEF_NSAMPLE;
string manFileName, name, outFileName, stateFileName;
char *cmdName;
opterr = 0;
cmdName = basename(argv[0]);
while ((c = getopt(argc, argv, "n:r:o:")) != -1)
{
switch (c)
{
case 'n':
nSample = strTo<unsigned int>(optarg);
break;
case 'r':
stateFileName = optarg;
break;
case 'o':
outFileName = optarg;
break;
case '?':
cerr << "error parsing option -" << char(optopt) << endl;
usage(cmdName);
break;
default:
usage(cmdName);
break;
}
}
if (argc - optind == 2)
{
manFileName = argv[optind];
name = argv[optind+1];
}
else
{
usage(cmdName);
}
Dataset<DMat, AsciiFile> dataset;
DMatSample s;
RandGen g;
if (!stateFileName.empty())
{
AsciiFile f(stateFileName, File::Mode::read);
g.setState(f.read<RandGen::State>());
}
cout << "-- loading data from manifest '" << manFileName << "'..." << endl;
dataset.load(manFileName, name);
s = dataset.bootstrapMean(nSample, g);
cout << scientific;
cout << "central value:\n" << s[central] << endl;
cout << "standard deviation:\n" << s.variance().cwiseSqrt() << endl;
if (!outFileName.empty())
{
AsciiFile f(outFileName, File::Mode::write);
f.save(s, manFileName + "_" + name);
}
return EXIT_SUCCESS;
}

View File

@ -1,20 +1,23 @@
#include <iostream> #include <iostream>
#include <latan/Dataset.hpp>
#include <latan/Io.hpp> #include <latan/Io.hpp>
#include <latan/Sample.hpp>
using namespace std; using namespace std;
using namespace Latan; using namespace Latan;
int main(void) int main(int argc, char *argv[])
{ {
Dataset<DMat, AsciiFile> dataset; if (argc != 2)
DMatSample s, r; {
RandGen g; cerr << "usage: " << argv[0] << " <file>" << endl;
return EXIT_FAILURE;
}
dataset.load("man", "HVP_2_2_000_00_0_0"); string fileName = argv[1];
s = dataset.bootstrapMean(100, g); AsciiFile f(fileName, File::Mode::read);
cout << "-- loading sample from '" << fileName << "'..." << endl;
const DMatSample &s = f.read<DMatSample>();
cout << scientific;
cout << "central value:\n" << s[central] << endl; cout << "central value:\n" << s[central] << endl;
cout << "standard deviation:\n" << s.variance().cwiseSqrt() << endl; cout << "standard deviation:\n" << s.variance().cwiseSqrt() << endl;