aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: f6e998a35ab664bff10fab5f0e2247b494ca3b9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#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>

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;
    
};



int main()
{   
    std::vector<double> u {sqrt(0.2), sqrt(0.2), sqrt(0.2), sqrt(0.2), sqrt(0.2)};
    multi_gaussian_truncated G(0, 2, u);
    std::vector<double> r(5);
    r = G();
    for (int i=0; i<5; i++){
        std::cout<<r[i]<<std::endl;
    }
        
    return 0; 
}