aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand <bertrand.horel@gmail.com>2016-02-13 22:35:00 +0000
committerBertrand <bertrand.horel@gmail.com>2016-02-13 22:35:00 +0000
commit833fe23df203623c0cf9c540cd9a085792c04869 (patch)
tree88b00d20c49f734e8a264292a4c8654d6548e672
parent34f073125f5c458c5c76128344f1745779f631a0 (diff)
downloadprojet_C++-833fe23df203623c0cf9c540cd9a085792c04869.tar.gz
maj Makefile et calcul de moyenne de normales avec méthode qmc
-rw-r--r--Makefile2
-rw-r--r--rqmc.cpp40
2 files changed, 34 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 6b87c38..bb7cdc6 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ main.o: stratified_sampling.o
test: test.o mt19937.o
$(CXX) $^ -o $@
-rqmc: rqmc.o
+rqmc: rqmc.o mt19937.o
$(CXX) $^ -o $@ $(GSL_FLAGS)
clean:
diff --git a/rqmc.cpp b/rqmc.cpp
index 40fd8ad..e8b98fc 100644
--- a/rqmc.cpp
+++ b/rqmc.cpp
@@ -1,14 +1,40 @@
#include "low_discrepancy.hpp"
#include <vector>
+#include <gsl/gsl_cdf.h>
+#include "var_alea.hpp"
+
+
+double frac_part(double x){
+ return x - floor(x);
+}
+
+double mean_rqmc(int N, double X) {
+ sobol s(1);
+ double sum = 0;
+ for(int i=0; i<N; i++){
+ sum +=gsl_cdf_gaussian_Pinv (frac_part(X+s()[0]), 1);
+ }
+ return sum/N;
+}
int main() {
- sobol s(3);
- std::vector<double> q;
- std::vector<double> a;
- q = s();
- a = s();
- for(int i=0; i<3; i++){
- std::cout<<a[i]<<std::endl;
+ init_alea(0);
+ int I=100;
+ int N= 10000;
+ uniform U;
+ double m = 0;
+ double s = 0;
+ double temp;
+
+ for(int i=0;i<I;i++){
+ temp = mean_rqmc(N,U());
+ m+=temp;
+ s+=temp*temp;
}
+ m = m/N;
+ s = s/N - m*m;
+
+ std::cout<<"espérance "<<m<<" taille de l'IC "<<sqrt(s)*1.64/10<<std::endl;
+
return 0;
}