diff options
Diffstat (limited to 'stratified_sampling.hpp')
| -rw-r--r-- | stratified_sampling.hpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/stratified_sampling.hpp b/stratified_sampling.hpp index ca96a3c..e9e1823 100644 --- a/stratified_sampling.hpp +++ b/stratified_sampling.hpp @@ -54,7 +54,7 @@ struct stratified_sampling { vector<double> get_mean(); vector<double> get_var(); void print_mean(); - //double estimator(); + pair<double,double> estimator(); private: vector<double> p; vector<int> M; @@ -147,6 +147,19 @@ void stratified_sampling<L>::print_mean() { cout<<mean[i]<<"\t"; } cout<<endl; - } +}; + +template <typename L> +pair<double,double> stratified_sampling<L>::estimator() { + double est_mean; + double est_std; + for (int i=0; i<I; i++) { + est_mean += mean[i]*p[i]; + est_std += sqrt(sigma2[i])*p[i]; + } + return {est_mean, est_std}; +} + + |
