From: Alex Schmidt Date: Fri, 25 May 2012 09:14:44 +0000 (+0200) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/f88ac5417385884367cf8cd5fc105ec4ffda8904?ds=inline;hp=d7a3df98c51fc1660f664835131a6ad349d1f270 ... --- diff --git a/obs.hpp b/obs.hpp index bba6687..2501f14 100644 --- a/obs.hpp +++ b/obs.hpp @@ -1,7 +1,7 @@ #ifndef OBS_HPP #define OBS_HPP -#include +#include #include #include #include @@ -17,24 +17,34 @@ public: void computeEasy(const string& compid="one", const int& ival=0) { mean(compid, &measurements, ival); } - void computeJack(const string& compid, double (*func)(list< vector > *vals, void *para)=NULL, void *para=NULL); - void computeJack(double (*func)(list< vector > *vals, void *para)=NULL, void *para=NULL) { computeJack("one",func,para); } + void computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para)=NULL, void *para=NULL); + void computeJack(double (*func)(vector< vector > *vals, void *para)=NULL, void *para=NULL) { computeJack("one",func,para); } double getMean(const string& compid="one") { return computations[compid].val; } double getErr(const string& compid="one") { return computations[compid].err; } + void reset(); + private: struct result{ double val; double err; }; - list< vector > measurements; + vector< vector > measurements; map computations; - void mean(const string& compid, list< vector > *meas, const int& ival); + void mean(const string& compid, vector< vector > *meas, const int& ival); }; + +template +void obs::reset() +{ + computations.clear(); + measurements.clear(); +} + template void obs::addMeas(const obstype& val) { @@ -50,25 +60,25 @@ void obs::addMeas(obstype val[], int valsize) } template -void obs::mean(const string& compid, list< vector > *meas, const int& ival) +void obs::mean(const string& compid, vector< vector > *meas, const int& ival) { computations[compid].val = 0; computations[compid].err = 0; int nmeas = meas->size(); - for(list< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) + for(vector< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) computations[compid].val += (*measIt)[ival]; computations[compid].val /= nmeas; - for(list< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) + for(vector< vector >::iterator measIt = meas->begin(); measIt != meas->end(); ++measIt) computations[compid].err += pow( (*measIt)[ival] - computations[compid].val, 2 ); computations[compid].err /= nmeas*(nmeas-1); computations[compid].err = sqrt( computations[compid].err ); } template -void obs::computeJack(const string& compid, double (*func)(list< vector > *vals, void *para), void *para) +void obs::computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para), void *para) { int nmeas=measurements.size(); double manymeans[nmeas]; @@ -77,26 +87,23 @@ void obs::computeJack(const string& compid, double (*func)(list< vector computations[compid].err = 0; int imeas=0; - for(typename list< vector >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++) + for(typename vector< vector >::iterator removedIt = measurements.begin(); removedIt != measurements.end(); ++removedIt, imeas++) { vector removed = *removedIt; - typename list< vector >::iterator nextAfterIt = removedIt; - ++nextAfterIt; + *removedIt = measurements.back(); + measurements.pop_back(); - measurements.erase(removedIt); - manymeans[imeas] = func(&measurements, para); computations[compid].val += manymeans[imeas]; - - measurements.insert(nextAfterIt, removed); - - removedIt = nextAfterIt; + + measurements.push_back( *removedIt ); + *removedIt = removed; } computations[compid].val /= nmeas; for(int imean=0; imean