From: Alex Schmidt Date: Thu, 24 May 2012 11:23:46 +0000 (+0200) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/d4e3cb0ebd372ab5e931490599fa0c72831bc23f ... --- diff --git a/obs.cpp b/obs.cpp index f9a7dbf..75c1d93 100644 --- a/obs.cpp +++ b/obs.cpp @@ -4,162 +4,63 @@ using namespace std; -namespace obs +template +void obs::addMeas(obstype val[], int valsize) { - vector mymeas; - - double addMeas(int id, double val) - { - meas tmpmeas; - tmpmeas.id = id; - tmpmeas.val.push_back(val); - mymeas.push_back(tmpmeas); - return val; - } - - double* addMeas(int id, double *val, int valsize) - { - meas tmpmeas; - tmpmeas.id = id; - for( int ival=0; ival vals)) - { - int nmeas = 0; - vector mymeans; - int vecsize = mymeas.size(); - obsa jackobs; - - jackobs.mean = 0; - - for (int ijack=0; ijack < nmeas || nmeas == 0; ijack++) - { - - nmeas = 0; - vector myvals; - - for (int i=0; i > vals)) - { - int nmeas = 0; - vector mymeans; - int vecsize = mymeas.size(); - obsa jackobs; - - jackobs.mean = 0; - - for (int ijack=0; ijack < nmeas || nmeas == 0; ijack++) - { - - nmeas = 0; - vector< vector > myvals; - - for (int i=0; i +void obs::addMeas(const obstype& val) +{ + measurements.push_back(val); +} - jackobs.mean /= nmeas; +template +void obs::mean(const string& compid, const list& meas) +{ + computations[compid][0] = 0; + computations[compid][1] = 0; + int nmeas = meas.size(); + + for(list::iterator measIt = meas.begin(); measIt != meas.end(); ++measIt) + computations[compid][0] += *measIt; + computations[compid][0] /= nmeas; + + for(list::iterator measIt = meas.begin(); measIt != meas.end(); ++measIt) + computations[compid][1] += pow( *measIt - computations[compid][0], 2 ); + computations[compid][1] /= nmeas*(nmeas-1); + computations[compid][1] = sqrt(computations[compid][1]); +} - /* compute jack error */ - vecsize = mymeans.size(); - jackobs.err = 0; - for (int i=0; i +void obs::computeJack(const string& compid, double (*func)(const list& vals, void *para), void *para) +{ + int nmeas=measurements.size(); + double manymeans[nmeas]; + + computations[compid][0] = 0; + computations[compid][1] = 0; + + int imeas=0; + for(typename list::iterator removedIt = measurements.begin(); removedIt != measurements.end(); imeas++) + { + obstype removed = *removedIt; + + typename list::iterator nextAfterIt = removedIt; + ++nextAfterIt; + + measurements.erase(removedIt); + + manymeans[imeas] = func(measurements, para); + computations[compid][0] += manymeans[imeas]; + + measurements.insert(nextAfterIt, removed); + } + computations[compid][0] /= nmeas; + + for(int imean=0; imean +#include +#include +#include using namespace std; -namespace obs +template +class obs { - struct obsa - { - double mean; - double err; - }; + public: + void addMeas(obstype val[], int valsize); + void addMeas(const obstype& val); - struct meas - { - int id; - vector val; - }; + void computeMean(const string& compid) { mean(compid, measurements); } + void computeJack(const string& compid, double (*func)(const list& vals, void *para), void *para=NULL); - double addMeas(int id, double val); - double* addMeas(int id, double *val, int valsize); + private: + list measurements; + map computations; - obsa jackObs(int id, double (*func)(vector< vector > vals)); - obsa normObs(int id); - - void reset(); -} + void mean(const string& compid, const list& meas); +}; #endif