aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillame.horel@gmail.com>2016-02-07 15:04:55 -0500
committerGuillaume Horel <guillame.horel@gmail.com>2016-02-07 15:07:26 -0500
commit67a28837c6bbb05d2636a70955a665a88696b96f (patch)
tree53c547147f0d98a0c96e074974eb3a082b231587
parentf9a7dc81072724a863be5d956f09de53f9b022d6 (diff)
downloadprojet_C++-67a28837c6bbb05d2636a70955a665a88696b96f.tar.gz
passe à quatre espaces pour les tabs
-rw-r--r--main.cpp36
-rw-r--r--stratified_sampling.cpp58
2 files changed, 46 insertions, 48 deletions
diff --git a/main.cpp b/main.cpp
index c1eb3ec..88617c4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -10,26 +10,26 @@
//--génération quantiles--
std::vector<double> quantile_norm(int n, double sigma){
- std::vector<double> q(n);
- for (int i=0; i<n; i++) {
- q[i] = gsl_cdf_gaussian_Pinv ((double)(i+1)/n, sigma);
- }
- return q;
+ std::vector<double> q(n);
+ for (int i=0; i<n; i++) {
+ q[i] = gsl_cdf_gaussian_Pinv ((double)(i+1)/n, sigma);
+ }
+ return q;
}
int main()
{
- //--- GSL random init ---
- gsl_rng_env_setup();
- std::vector<double> q;
- q = quantile_norm(10, 1);
- vector<double> p(10, 0.1);
- vector<gaussian_truncated> gen;
- gen.push_back(gaussian_truncated(GSL_NEGINF,q[0]));
- for (int i=1; i<10; i++){
- gen.push_back(gaussian_truncated(q[i-1],q[i]));
- }
- stratified_sampling<gaussian_truncated> S(p, gen);
- //S.update(1000);
- return 0;
+ //--- GSL random init ---
+ gsl_rng_env_setup();
+ std::vector<double> q;
+ q = quantile_norm(10, 1);
+ vector<double> p(10, 0.1);
+ vector<gaussian_truncated> gen;
+ gen.push_back(gaussian_truncated(GSL_NEGINF,q[0]));
+ for (int i=1; i<10; i++){
+ gen.push_back(gaussian_truncated(q[i-1],q[i]));
+ }
+ stratified_sampling<gaussian_truncated> S(p, gen);
+ //S.update(1000);
+ return 0;
}
diff --git a/stratified_sampling.cpp b/stratified_sampling.cpp
index c03d447..b959776 100644
--- a/stratified_sampling.cpp
+++ b/stratified_sampling.cpp
@@ -13,41 +13,39 @@ std::pair<double, double> mean_var( std::vector<double> r){
p.second -= p.first * p.first;
return p;
}
+
//actualisation du nombre de tirages à faire par strates
template <typename Gen>
void stratified_sampling<Gen>::update(int Nk) {
- int I = p.size();
- //reinitialistation du vecteur M du nombre de tirages par strates
- if (M.empty()) {
- M.resize(I,1);
- }
- else {
- for(int i=0; i<I; i++){
- M[i]=1;
+ int I = p.size();
+ //reinitialistation du vecteur M du nombre de tirages par strates
+ if (M.empty()) {
+ M.resize(I,1);
+ }
+ else {
+ for(int i=0; i<I; i++){
+ M[i]=1;
+ }
}
- }
-
- std::vector<double> m(I, 0); //le vecteur des m_i idéals
- if (sigma.empty()) {
- for (int i=0; i<I; i++) {
- m[i] = (Nk-I)*p[i];
+ std::vector<double> m(I, 0); //le vecteur des m_i idéals
+
+ if (sigma.empty()) {
+ for (int i=0; i<I; i++) {
+ m[i] = (Nk-I)*p[i];
+ }
}
- }
- else {
- 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;
+ else {
+ 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;
+ }
+ }
+ M[0]+=floor(m[0]);
+ double current = m[0];
+ for (int i=1; i<I; i++){
+ M[i] += floor(current+m[i]) - floor(current);
+ current += m[i];
}
- }
- M[0]+=floor(m[0]);
- double current = m[0];
- for (int i=1; i<I; i++){
- M[i] += floor(current+m[i]) - floor(current);
- current += m[i];
- }
-
}
-
-