diff options
| -rw-r--r-- | src/projet.cpp | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/src/projet.cpp b/src/projet.cpp index fb6df08..980ef98 100644 --- a/src/projet.cpp +++ b/src/projet.cpp @@ -1,5 +1,4 @@ #include <iostream> -#include <gsl/gsl_rng.h> #include <vector> #include <gsl/gsl_cdf.h> #include <gsl/gsl_math.h> @@ -9,37 +8,29 @@ #include "opti.hpp" using namespace std; -//--génération quantiles-- -vector<double> quantile_norm(int n, double sigma){ - vector<double> q(n); - for (int i=0; i<n; i++) { - q[i] = gsl_cdf_gaussian_Pinv ((double)(i+1)/n, sigma); - } - return q; -} + void exemple1() { -gsl_rng_env_setup(); -vector<double> q = quantile_norm(10, 1); -vector<double> p(10, 0.1); -vector<gaussian_truncated> rvar; -rvar.push_back(gaussian_truncated(GSL_NEGINF, q[0],0,1,0)); -for (int i=1; i<10; i++){ - rvar.push_back(gaussian_truncated(q[i-1], q[i],0,1,i)); -}; -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; + vector<double> q = quantile_norm(10, 1); + vector<double> p(10, 0.1); + vector<gaussian_truncated> rvar; + rvar.push_back(gaussian_truncated(GSL_NEGINF, q[0])); + for (int i=1; i<10; i++){ + rvar.push_back(gaussian_truncated(q[i-1], q[i])); + }; + 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<<"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; }; @@ -80,8 +71,9 @@ x = 1.64*S.estimator().second; int main() { - - exemple2(); + init_alea(1); + exemple1(); + //exemple2(); return 0; } |
