aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand <bertrand.horel@gmail.com>2016-02-09 14:48:21 +0000
committerBertrand <bertrand.horel@gmail.com>2016-02-09 14:48:21 +0000
commit861100a098452ddd02a9df1cf58ec8ea8fadf07f (patch)
treecf665c94dc745ee97dde1da64c12bfe4b70a0f1c
parent486c1e061bfe039b0d8baa7cb59cab8f3b8e07ba (diff)
downloadprojet_C++-861100a098452ddd02a9df1cf58ec8ea8fadf07f.tar.gz
estimateur, intervalles de confiances ...
-rw-r--r--main.cpp24
m---------qmc0
-rw-r--r--rtnormbin0 -> 9538576 bytes
-rw-r--r--stratified_sampling.hpp29
4 files changed, 34 insertions, 19 deletions
diff --git a/main.cpp b/main.cpp
index 8692967..0728976 100644
--- a/main.cpp
+++ b/main.cpp
@@ -31,13 +31,23 @@ int main()
stratified_sampling<gaussian_truncated> S(p,rvar);
S.update(100);
S.draw();
- for(int i=0;i<10;i++){
- cout<<S.get_mean()[i]<<endl;
- }
- S.update(500);
+ 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.update(1000);
S.draw();
- for(int i=0;i<10;i++){
- cout<<S.get_mean()[i]<<endl;
- }
+ 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.update(10000);
+ S.draw();
+ 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;
+
+ //~ S.draw();
+ //~ for(int i=0;i<10;i++){
+ //~ cout<<S.get_mean()[i]<<endl;
+ //~ }
return 0;
}
diff --git a/qmc b/qmc
new file mode 160000
+Subproject 3723be5c65f44ae0d9ea25a9e563163e3e1b044
diff --git a/rtnorm b/rtnorm
new file mode 100644
index 0000000..1e39751
--- /dev/null
+++ b/rtnorm
Binary files differ
diff --git a/stratified_sampling.hpp b/stratified_sampling.hpp
index e9e1823..cf857ec 100644
--- a/stratified_sampling.hpp
+++ b/stratified_sampling.hpp
@@ -54,6 +54,7 @@ struct stratified_sampling {
vector<double> get_mean();
vector<double> get_var();
void print_mean();
+ void print_sigma();
pair<double,double> estimator();
private:
vector<double> p;
@@ -97,22 +98,16 @@ void stratified_sampling<L>::update(int Nk) {
double scal = std::inner_product(p.begin(), p.end(), sigma.begin(), (double) 0);
for (int i=0; i < I; i++) {
m[i] = (Nk-I)*p[i]*sigma[i]/scal;
- std::cout<<m[i]<<std::endl;
+ //std::cout<<m[i]<<std::endl;
}
}
- std::cout<<"M[O] avant mis à jour"<<M[0]<<endl;
M[0]+=floor(m[0]);
- std::cout<<"M[0] après"<<M[0]<<endl;
double current = m[0];
- int compteur = M[0];
- for (int i=1; i<I; i++){
+ for (int i=1; i<I-1; i++){
M[i] += floor(current+m[i]) - floor(current);
current += m[i];
- compteur += M[i];
- cout<<M[i]<<"\t";
}
- cout<<endl;
- cout<<compteur<<endl;
+ M[I-1]+=Nk-I-floor(current);
}
template <typename L>
@@ -143,16 +138,26 @@ vector<double> stratified_sampling<L>::get_var() {
template <typename L>
void stratified_sampling<L>::print_mean() {
- for(int i=0;i<10;i++){
+ cout<<"les espérances :"<<endl;
+ for(int i=0;i<I;i++){
cout<<mean[i]<<"\t";
}
cout<<endl;
};
template <typename L>
+void stratified_sampling<L>::print_sigma() {
+ cout<<"les écarts types :"<<endl;
+ for(int i=0;i<I;i++){
+ cout<<sqrt(sigma2[i])<<"\t";
+ }
+ cout<<endl;
+};
+
+template <typename L>
pair<double,double> stratified_sampling<L>::estimator() {
- double est_mean;
- double est_std;
+ double est_mean = 0;
+ double est_std = 0;
for (int i=0; i<I; i++) {
est_mean += mean[i]*p[i];
est_std += sqrt(sigma2[i])*p[i];