mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-06-16 06:27:05 +01:00
Merge branch 'master' into new_fit
This commit is contained in:
@ -42,21 +42,21 @@ int main(int argc, char *argv[])
|
||||
nSample = strTo<Index>(argv[3]);
|
||||
outFileName = argv[4];
|
||||
|
||||
RandGen gen;
|
||||
DMatSample res(nSample, 1, 1);
|
||||
RandGen gen;
|
||||
DSample res(nSample);
|
||||
|
||||
FOR_STAT_ARRAY(res, s)
|
||||
{
|
||||
if (s == central)
|
||||
{
|
||||
res[s](0, 0) = val;
|
||||
res[s] = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
res[s](0, 0) = gen.gaussian(val, err);
|
||||
res[s] = gen.gaussian(val, err);
|
||||
}
|
||||
}
|
||||
Io::save<DMatSample>(res, outFileName);
|
||||
Io::save<DSample>(res, outFileName);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -35,6 +35,108 @@ static void usage(const string &cmdName)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void loadAndCheck(vector<T> &sample, const vector<string> &fileName)
|
||||
{
|
||||
const unsigned int n = sample.size();
|
||||
Index nSample = 0;
|
||||
|
||||
cout << "-- loading data..." << endl;
|
||||
for (unsigned int i = 0; i < n; ++i)
|
||||
{
|
||||
sample[i] = Io::load<T>(fileName[i]);
|
||||
if (i == 0)
|
||||
{
|
||||
nSample = sample[i].size();
|
||||
}
|
||||
else if (sample[i].size() != nSample)
|
||||
{
|
||||
cerr << "error: number of sample mismatch (between '";
|
||||
cerr << fileName[0] << "' and '" << fileName[i] << "')" << endl;
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void combine(const string &outFileName __dumb,
|
||||
const vector<T> &sample __dumb, const string &code __dumb)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
template <>
|
||||
void combine(const string &outFileName, const vector<DSample> &sample,
|
||||
const string &code)
|
||||
{
|
||||
const unsigned int n = sample.size();
|
||||
DoubleFunction f = compile(code, n);
|
||||
DSample result(sample[0]);
|
||||
DVec buf(n);
|
||||
|
||||
cout << "-- combining data..." << endl;
|
||||
result = sample[0];
|
||||
FOR_STAT_ARRAY(result, s)
|
||||
{
|
||||
for (unsigned int k = 0; k < n; ++k)
|
||||
{
|
||||
buf[k] = sample[k][s];
|
||||
}
|
||||
result[s] = f(buf);
|
||||
}
|
||||
cout << scientific;
|
||||
cout << "central value:\n" << result[central];
|
||||
cout << endl;
|
||||
cout << "standard deviation:\n" << sqrt(result.variance());
|
||||
cout << endl;
|
||||
if (!outFileName.empty())
|
||||
{
|
||||
Io::save<DSample>(result, outFileName);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void combine(const string &outFileName, const vector<DMatSample> &sample,
|
||||
const string &code)
|
||||
{
|
||||
const unsigned int n = sample.size();
|
||||
DoubleFunction f = compile(code, n);
|
||||
DVec buf(n);
|
||||
DMatSample result(sample[0]);
|
||||
|
||||
cout << "-- combining data..." << endl;
|
||||
FOR_STAT_ARRAY(result, s)
|
||||
{
|
||||
FOR_MAT(result[s], i, j)
|
||||
{
|
||||
for (unsigned int k = 0; k < n; ++k)
|
||||
{
|
||||
buf[k] = sample[k][s](i,j);
|
||||
}
|
||||
result[s](i, j) = f(buf);
|
||||
}
|
||||
}
|
||||
cout << scientific;
|
||||
cout << "central value:\n" << result[central];
|
||||
cout << endl;
|
||||
cout << "standard deviation:\n" << result.variance().cwiseSqrt();
|
||||
cout << endl;
|
||||
if (!outFileName.empty())
|
||||
{
|
||||
Io::save<DMatSample>(result, outFileName);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void process(const string &outFileName, const vector<string> &fileName,
|
||||
const string &code)
|
||||
{
|
||||
vector<T> sample(fileName.size());
|
||||
|
||||
loadAndCheck(sample, fileName);
|
||||
combine(outFileName, sample, code);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// argument parsing ////////////////////////////////////////////////////////
|
||||
@ -82,54 +184,16 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
usage(cmdName);
|
||||
}
|
||||
|
||||
// data loading ////////////////////////////////////////////////////////////
|
||||
vector<DMatSample> sample(n);
|
||||
Index nSample = 0;
|
||||
|
||||
cout << "-- loading data..." << endl;
|
||||
for (unsigned int i = 0; i < n; ++i)
|
||||
|
||||
// process data ////////////////////////////////////////////////////////////
|
||||
try
|
||||
{
|
||||
sample[i] = Io::load<DMatSample>(fileName[i]);
|
||||
if (i == 0)
|
||||
{
|
||||
nSample = sample[i].size();
|
||||
}
|
||||
else if (sample[i].size() != nSample)
|
||||
{
|
||||
cerr << "error: number of sample mismatch (between '";
|
||||
cerr << fileName[0] << "' and '" << fileName[i] << "')" << endl;
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
process<DSample>(outFileName, fileName, code);
|
||||
}
|
||||
|
||||
// combine data ////////////////////////////////////////////////////////////
|
||||
DoubleFunction f = compile(code, n);
|
||||
DVec buf(n);
|
||||
DMatSample result(sample[0]);
|
||||
|
||||
cout << "-- combining data..." << endl;
|
||||
FOR_STAT_ARRAY(result, s)
|
||||
catch (bad_cast &e)
|
||||
{
|
||||
FOR_MAT(result[s], i, j)
|
||||
{
|
||||
for (unsigned int k = 0; k < n; ++k)
|
||||
{
|
||||
buf[k] = sample[k][s](i,j);
|
||||
}
|
||||
result[s](i, j) = f(buf);
|
||||
}
|
||||
process<DMatSample>(outFileName, fileName, code);
|
||||
}
|
||||
|
||||
// output //////////////////////////////////////////////////////////////////
|
||||
cout << scientific;
|
||||
cout << "central value:\n" << result[central] << endl;
|
||||
cout << "standard deviation:\n" << result.variance().cwiseSqrt() << endl;
|
||||
if (!outFileName.empty())
|
||||
{
|
||||
Io::save<DMatSample>(result, outFileName);
|
||||
}
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -35,14 +35,29 @@ int main(int argc, char *argv[])
|
||||
string fileName = argv[1], copy = (argc >= 3) ? argv[2] : "";
|
||||
|
||||
cout << "-- loading sample from '" << fileName << "'..." << endl;
|
||||
DMatSample s = Io::load<DMatSample>(fileName);
|
||||
string name = Io::getFirstName(fileName);
|
||||
cout << scientific;
|
||||
cout << "central value:\n" << s[central] << endl;
|
||||
cout << "standard deviation:\n" << s.variance().cwiseSqrt() << endl;
|
||||
if (!copy.empty())
|
||||
try
|
||||
{
|
||||
Io::save(s, copy, File::Mode::write, name);
|
||||
DMatSample s = Io::load<DMatSample>(fileName);
|
||||
string name = Io::getFirstName(fileName);
|
||||
cout << scientific;
|
||||
cout << "central value:\n" << s[central] << endl;
|
||||
cout << "standard deviation:\n" << s.variance().cwiseSqrt() << endl;
|
||||
if (!copy.empty())
|
||||
{
|
||||
Io::save(s, copy, File::Mode::write, name);
|
||||
}
|
||||
}
|
||||
catch (bad_cast &e)
|
||||
{
|
||||
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;
|
||||
if (!copy.empty())
|
||||
{
|
||||
Io::save(s, copy, File::Mode::write, name);
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
Reference in New Issue
Block a user