diff options
| author | Bertrand <bertrand.horel@gmail.com> | 2016-03-01 14:32:31 +0000 |
|---|---|---|
| committer | Bertrand <bertrand.horel@gmail.com> | 2016-03-01 14:32:31 +0000 |
| commit | 69ef15f06495b92bd619963eb543cb098bab479c (patch) | |
| tree | 17043df5306d1ef334c2b44763cce1b003fbf5cd /src/projet.cpp | |
| parent | 96afa78f5fe1bafb95c96170932c7b4fc119ae7e (diff) | |
| download | projet_C++-69ef15f06495b92bd619963eb543cb098bab479c.tar.gz | |
on n'utilise plus rtnorm
Diffstat (limited to 'src/projet.cpp')
| -rw-r--r-- | src/projet.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/projet.cpp b/src/projet.cpp new file mode 100644 index 0000000..fb6df08 --- /dev/null +++ b/src/projet.cpp @@ -0,0 +1,87 @@ +#include <iostream> +#include <gsl/gsl_rng.h> +#include <vector> +#include <gsl/gsl_cdf.h> +#include <gsl/gsl_math.h> +#include "stratified_sampling.hpp" +#include <cmath> +#include <algorithm> +#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; + 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; + +}; + + + void exemple2 (){ + int d= 16; + std::vector<double> mu(d); + mu = argmax(0.05, 1.0, 50, 0.1, 45, d); + double norm_mu = 0; + std::vector<double> u(d); + for(int i=0; i<d; i++) { + norm_mu += mu[i]*mu[i]; + } + for(int i=0; i<d; i++) { + u[i] = mu[i]/sqrt(norm_mu); + } + vector<double> q = quantile_norm(100, 1); + vector<double> p(100, 0.01); + asian_option A(0.05, 1.0, 50, 0.1, d, 45); + f_mu G(mu,A); + std::vector<compose_t <f_mu, multi_gaussian_truncated> > X; + X.push_back(compose(G, multi_gaussian_truncated(GSL_NEGINF,q[0], u))); + for(int i=1; i<100; i++) { + X.push_back(compose(G, multi_gaussian_truncated(q[i-1],q[i], u))); + } + for(int i=0; i<100; i=i+10){ + std::cout<<X[i]()<<endl; + } + stratified_sampling<compose_t <f_mu, multi_gaussian_truncated> > S(p, X); + S.draw(1000); + cout<<"l'estimateur de la moyenne est :"<<S.estimator().first<<endl; + //~ compose_t <f_mu, multi_gaussian_truncated> X = compose(G,MG); + //~ for(int i=0; i<10; i++){ + //~ std::cout<<X()<<std::endl; + //~ } +} + + +int main() +{ + + exemple2(); + + return 0; +} |
