Commit b0f023cb authored by Florian Goth's avatar Florian Goth
Browse files

Add some old tests that were flying around and update them. They need C++11 for the RNG.

parent 0ae5c909
#include <iostream>
#include <fstream>
#include <random>
#include <functional>
#include <chrono>
# include "rebin_containers.h"
# include "scalar_observable.h"
int main()
{
// std::mt19937 gen;
auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
auto real_rand = std::bind(std::uniform_real_distribution<double>(0,1), std::mt19937(seed));
// rng rand;
mc_analysis::Scalar_Observable<double> obs1;
mc_analysis::Scalar_Observable<double, mc_analysis::ScalarRebinContainer<double, std::vector<double> > > obs2;
double a;
for(unsigned int i=0; i<1000000; i++)
{
a=real_rand();
obs1.push_back(a);
obs2.push_back(a);
}
obs1.rebin_data(1);
obs2.rebin_data(1);
std::cout.precision(10);
std::cout<< "Data rebinned"<< std::endl;
std::cout << "Size obs1: " << obs1.size()<< std::endl;
std::cout << "Size obs2: " << obs2.size() << std::endl;
std::cout<< obs1.mean() << "\t"<< obs1.sd() << "\t" << obs1.standard_error() << std::endl;
std::cout<< obs2.mean() << "\t"<< obs2.sd() << "\t" << obs2.standard_error() << std::endl;
/* mc_analysis::errordata<double> erd;
mc_analysis::ExampleFunctor f;
std::cout<< f(0.) << "\t" << f(1.) << std::endl;
mc_analysis::errordata<double> ferd;
ferd = obs1.jack_eval(f);
std::cout<< ferd.get_mean() << "\t" << ferd.get_error() << "\n";
for(unsigned int i=1; i<100; i+=10)
{
obs1.rebin_data(i);
// obs.fractional_rebinning( obs.get_num_data_points()/i );
erd=obs1.jackknife();
std::cout<<i <<"\t"<<"\t" << erd.get_mean() << "\t" << erd.get_error() << "\n";
}
*/
}
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <random>
#include <functional>
#include <chrono>
#include <valarray>
#include "scalar_observable.h"
#include "analysis_functions.h"
#include "rebin_containers.h"
#include "array_observable.h"
class fun
{
public:
typedef std::valarray<double> res_t;
res_t operator()(std::valarray<double> input){ return 2.*input; };
};
int main()
{
auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
auto real_rand = std::bind(std::uniform_real_distribution<double>(0,1), std::mt19937(seed));
unsigned int length=5;
std::valarray<double> a(length);
std::vector<std::valarray<double> > data;
// for(unsigned int i=0; i< 200000; i++)
// {
// for(unsigned int v=0; v<a.size(); v++) a[v]=r.rnd();
// data.push_back(a);
// }
// Test of array_observable:
mc_analysis::array_observable<double> a_obs;
mc_analysis::array_observable<double, mc_analysis::ArrayRebinContainer<double, std::vector<std::valarray<double> > > > auto_obs;
for(unsigned int i=0; i< 1000000; i++)
{
for(unsigned int v=0; v<a.size(); v++) a[v]=real_rand();
a_obs.push_back(a);
auto_obs.push_back(a);
data.push_back(a);
}
// Testing the rebin container
//
mc_analysis::ArrayRebinContainer<double, std::vector<std::valarray<double> > > testcont;
testcont.push_back(a);
//
// End test
auto_obs.rebin_data(1);
std::valarray<double> resauto(a);
resauto = auto_obs.mean();
std::cout << "autorebinned: " << std::endl;
for(unsigned int i=0; i< resauto.size(); i++)
{
std::cout << resauto[i] << "\t" ;
}
std::cout << std::endl;
std::valarray<double> res(a);
res= mc_analysis::mean( data );
std::cout << "result" << std::endl;
for(unsigned int i=0; i< res.size(); i++)
{
std::cout << res[i] << "\t" ;
}
std::cout << std::endl;
std::cout << "=================\n\n";
a_obs.rebin_data(100);
// a_obs.print_data();
std::cout << "=================\n\n";
fun f;
mc_analysis::errordata<std::valarray<double> > result;
result=a_obs.jack_eval(f);
std::cout << "Result" << std::endl;
std::valarray<double> x=result.get_mean();
std::valarray<double> dx=result.get_error();
for(unsigned int i=0; i< length ; i++)
{
std::cout << x[i] << "\t" ;
}
std::cout << std::endl;
for(unsigned int i=0; i< length ; i++)
{
std::cout << dx[i] << "\t" ;
}
std::cout << std::endl;
std::cout << "errordata test\n";
mc_analysis::errordata<std::valarray<double> > t;
std::valarray<double> val(3);
val[0]=15.;
val[1]=2.;
val[2]=17.;
t.set_mean(val);
std::valarray<double> val2(3);
val2=t.get_mean();
for(unsigned int u=0;u<3;u++)
std::cout << val2[u] << "\t";
std::cout << "\n";
std::cout << "Control\n\n";
mc_analysis::Scalar_Observable<double> testing;
for(unsigned int i=0;i<1000000; i++) testing.push_back(2*real_rand());
testing.rebin_data(100);
mc_analysis::errordata<double> e;
e= testing.jackknife();
std::cout << e.get_mean() << "\t" << e.get_error() << std::endl;
// Test 2
std::cout << "Test2\n \n" << std::endl;
mc_analysis::Scalar_Observable<double> testing2;
for(unsigned int i=0;i<1000000; i++) testing2.push_back(real_rand());
testing2.rebin_data(100);
mc_analysis::errordata<double> e2;
e2= testing2.jackknife();
std::cout << e2.get_mean() << "\t" << e2.get_error() << std::endl;
a_obs.rebin_data(100);
mc_analysis::errordata<std::valarray<double> > result2;
result2=a_obs.jackknife();
std::cout << "Result" << std::endl;
std::valarray<double> x2=result2.get_mean();
std::valarray<double> dx2=result2.get_error();
for(unsigned int i=0; i< length ; i++)
{
std::cout << x2[i] << "\t" ;
}
std::cout << std::endl;
for(unsigned int i=0; i< length ; i++)
{
std::cout << dx2[i] << "\t" ;
}
std::cout << std::endl;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment