aboutsummaryrefslogtreecommitdiffstats
path: root/src/projet.cpp
diff options
context:
space:
mode:
authorBertrand <bertrand.horel@gmail.com>2016-04-20 20:10:51 +0200
committerBertrand <bertrand.horel@gmail.com>2016-04-20 20:10:51 +0200
commitd3d2034b35a5fe76f533a4d5ffc9db7ea0f778d9 (patch)
tree6fbf0ef9fbdeef9049ab03459792143cf8b5dbc1 /src/projet.cpp
parentba441e85f15d911d87b0d5363414138a50c65aa8 (diff)
downloadprojet_C++-d3d2034b35a5fe76f533a4d5ffc9db7ea0f778d9.tar.gz
ajout fction normalize ds projet
Diffstat (limited to 'src/projet.cpp')
-rw-r--r--src/projet.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/projet.cpp b/src/projet.cpp
index 6bcd90a..af322ed 100644
--- a/src/projet.cpp
+++ b/src/projet.cpp
@@ -60,18 +60,26 @@ vector< vector<double> > exemple1_rqmc(){
return data;
};
- void exemple2_stratified (){
- int d= 16;
+
+std::vector<double> normalize (std::vector<double> mu) {
+ int d = mu.size();
+ 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);
+ }
+ return u;
+}
+
+
+ void exemple2_stratified (int d){
std::vector<double> mu(d);
- mu = argmax(0.05, 1.0, 50, 0.1, 45, d);
- double norm_mu = 0;
+ mu = argmax(0.05, 1.0, 50, 0.1, 45, d);
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);
- }
+ u = normalize(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);
@@ -90,11 +98,9 @@ vector< vector<double> > exemple1_rqmc(){
cout<<"l'estimateur de la moyenne est :"<<S.estimator().first<<endl;
}
-void exemple2_rqmc() {
+void exemple2_rqmc(int d) {
asian_option A(0.05, 1.0, 50.0, 0.1, 16, 45);
int N= 10000;
-
- int d =16;
std::vector<double> result(3);
@@ -112,7 +118,7 @@ void exemple2_rqmc() {
int make_table(vector< vector<double> > data1, vector< vector<double> > data2) {
std::fstream fs("doc/table.tex", std::fstream::out);;
- fs<<R"(\begin{tabular}{|r|rr|rr|r|})"<<std::endl;
+ fs<<R"(\begin{tabular}{|r|rr|rr|c|})"<<std::endl;
fs<<R"(\hline)"<<endl;
fs<<"N"<<" & "<<R"($\mu_{strat}$)"<<" & "<<R"($\mu_{rqmc}$)"<<" & "<<R"($\textrm{IC}_{strat}$)"<<" & "<<R"($\textrm{IC}_{rqmc}$)"<<" & "<< R"($\textrm{IC}_{strat}/\textrm{IC}_{rqmc}$)"<<R"(\\ \hline)"<<std::endl;
fs.precision(2);
@@ -134,6 +140,8 @@ int main()
cout<<"Randomised quasi Monte-Carlo sur l'exemple 1 de la normale"<<endl;
vector< vector<double> > data2 = exemple1_rqmc();
make_table(data1, data2);
+
+ exemple2_stratified(16);
return 0;
}