aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stratified_sampling.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/stratified_sampling.cpp b/stratified_sampling.cpp
index 98e5442..4d3de48 100644
--- a/stratified_sampling.cpp
+++ b/stratified_sampling.cpp
@@ -8,12 +8,24 @@
//--génération quantiles--
std::vector<double> quantile_norm(int n, double sigma){
std::vector<double> q(n);
- for (int i=1; i<n; i++) {
- q[i] = gsl_cdf_gaussian_Pinv ((double)i/n, sigma);
+ for (int i=0; i<n; i++) {
+ q[i] = gsl_cdf_gaussian_Pinv ((double)(i+1)/n, sigma);
}
return q;
}
+//--tirage de normale tronquée entre les quantile de taille 1/n i et i+1--
+double quantile_truncate_normal (int i, int n, double mu,
+ double sigma, gsl_rng *gen) {
+ std::vector<double> q;
+ q = quantile_norm(n, sigma);
+ std::pair<double, double> p;
+ p = rtnorm (gen, q[i], q[i+1], mu, sigma);
+ return p.first;
+ }
+
+
+
int main()
{
//--- GSL random init ---
@@ -22,7 +34,12 @@ int main()
gsl_rng *gen = gsl_rng_alloc (type); // Rand generator allocation
std::vector<double> q;
q = quantile_norm(10, 1);
- std::cout<<q[1]<<std::endl;
+ std::cout<<q[5]<<std::endl;
+ double a;
+ int i;
+ for (i=0; i<20; i++){
+ a= quantile_truncate_normal(4, 10, 0, 1, gen);
+ std::cout<<a<<std::endl;}
return 0;
}