aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/projet.cpp71
1 files changed, 41 insertions, 30 deletions
diff --git a/src/projet.cpp b/src/projet.cpp
index 007dd6c..4a5889e 100644
--- a/src/projet.cpp
+++ b/src/projet.cpp
@@ -11,7 +11,14 @@
using namespace std;
-void exemple1_stratified() {
+struct first:public std::unary_function<std::vector<double>, double>
+{
+ double operator()(std::vector<double> X){
+ return X[0];
+ }
+};
+
+vector< vector<double> > exemple1_stratified() {
vector<double> q = quantile_norm(10, 1);
vector<double> p(10, 0.1);
vector<gaussian_truncated> rvar;
@@ -19,22 +26,38 @@ void exemple1_stratified() {
for (int i=1; i<10; i++){
rvar.push_back(gaussian_truncated(q[i-1], q[i]));
};
+ vector<int> N = {300, 1000, 10000, 20000}; //notre tableau du nombre successif de tirages, qui correspondent aux 300, 1300, 11300 et 31300
+ //de l'article de Etoré et Jourdain
+ vector< vector<double> > data (4);
stratified_sampling<gaussian_truncated> S(p,rvar);
- S.draw(100);
- double x = 1.64*S.estimator().second;
- cout<<"l'estimateur de la moyenne est :"<<S.estimator().first<<endl;
- cout<<"Son intervalle de confiance à 95% est :"<<"["<<S.estimator().first-(x/10)<<" ,"<<S.estimator().first+(x/10)<<"]"<<endl;
- S.draw(1000);
- x = 1.64*S.estimator().second;
- cout<<"l'estimateur de la moyenne est :"<<S.estimator().first<<endl;
- cout<<"Son intervalle de confiance à 95% est :"<<"["<<S.estimator().first-(x/sqrt(1100))<<" ,"<<S.estimator().first+(x/sqrt(1100))<<"]"<<endl;
- S.draw(10000);
- x = 1.64*S.estimator().second;
- cout<<"l'estimateur de la moyenne est :"<<S.estimator().first<<endl;
- cout<<"Son intervalle de confiance à 95% est :"<<"["<<S.estimator().first-(x/sqrt(11100))<<" ,"<<S.estimator().first+(x/sqrt(11100))<<"]"<<endl;
-
+ cout<<"N"<<"\t"<<"moyenne"<<"\t\t"<<"sigma"<<"\t"<<"théorique"<<endl;
+ vector<double> r(4,0);
+ for (int i=0; i<4; i++){
+ S.draw(N[i]);
+ r[0]= r[0] + N[i];
+ r[1] = S.estimator().first;
+ r[2] = S.estimator().second;
+ r[3] = 0.1559335;
+ cout<<r[0]<<"\t"<<r[1]<<"\t"<<r[2]<<"\t"<<r[3]<<endl;
+ data[i] = r;
+ };
+ return data;
};
+vector< vector<double> > exemple1_rqmc(){
+ int I = 100;
+ vector<int> N = {3, 13, 113, 313}; //les N choisis pour que les NI soient égaux aux N de l'exemple 1 stratified_sampling
+ first f; //comme quasi_gaussian retourne un vecteur, on doit composer avec f pour avoir le double QG()[0]
+ vector< vector<double> > data (4);
+ for(int i =0; i<4; i++){
+ data[i] = monte_carlo (I,quasi_mean<struct first, sobol> (N[i], 1, f));
+ }
+ cout<<"moyenne"<<"\t\t"<<"sigma"<<"\t\t"<<"taille IC"<<endl;
+ for(int i =0; i<3; i++){
+ cout<<data[i][0]<<"\t"<<data[i][1]<<"\t"<<data[i][2]<<endl;
+ }
+ return data;
+};
void exemple2_stratified (){
int d= 16;
@@ -86,26 +109,14 @@ void exemple2_rqmc() {
}
};
-struct first:public std::unary_function<std::vector<double>, double>
-{ double operator()(std::vector<double> X){return X[0];}
-};
-
-void exemple1_rqmc(){
- int N = 100;
- first f; //comme quasi_gaussian retourne un vecteur, on doit composer avec f pour avoir le double QG()[0]
- std::vector<double> result(3);
- result = monte_carlo (100,quasi_mean<struct first, sobol> (N, 1, f));
- for(int i =0; i<3; i++){
- std::cout<<result[i]<<std::endl;
- }
-};
int main()
{
init_alea(1);
- //exemple2_rqmc();
- //exemple1_stratified();
- exemple1_rqmc();
+ cout<<"Stratified_sampling sur l'exemple 1 de la normale"<<endl;
+ exemple1_stratified();
+ cout<<"Randomised quasi Monte-Carlo sur l'exemple 1 de la normale"<<endl;
+ exemple1_rqmc();
return 0;
}