diff options
| author | Guillaume Horel <guillame.horel@gmail.com> | 2016-02-09 13:05:58 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillame.horel@gmail.com> | 2016-02-09 13:05:58 -0500 |
| commit | a41bb158fba7d631e477cbac424274c9dafd59be (patch) | |
| tree | 581cb6a173166df7fbefa805364ecdcca80666ed /stratified_sampling.hpp | |
| parent | 5036aaeed5a197bdda996cedf0b49d2faa2fc29b (diff) | |
| download | projet_C++-a41bb158fba7d631e477cbac424274c9dafd59be.tar.gz | |
Add const where it makes sense
C'est bien de marquer les methods qui ne modifient pas l'objet comme const
De même que les variables qui ne sont jamais modifiées (comme I).
Diffstat (limited to 'stratified_sampling.hpp')
| -rw-r--r-- | stratified_sampling.hpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/stratified_sampling.hpp b/stratified_sampling.hpp index cf857ec..76fafbf 100644 --- a/stratified_sampling.hpp +++ b/stratified_sampling.hpp @@ -51,11 +51,11 @@ struct stratified_sampling { :p(p), X(X), mean(p.size(), 0), sigma2(p.size(), 0), I(p.size()){}; void update(int N); void draw(); - vector<double> get_mean(); - vector<double> get_var(); - void print_mean(); - void print_sigma(); - pair<double,double> estimator(); + vector<double> get_mean() const; + vector<double> get_var() const; + void print_mean() const; + void print_sigma() const; + pair<double,double> estimator() const; private: vector<double> p; vector<int> M; @@ -63,7 +63,7 @@ private: vector<double> mean; vector<double> sigma2; vector<L> X; - int I; + const int I; }; //actualisation du nombre de tirages à faire par strates @@ -127,17 +127,17 @@ void stratified_sampling<L>::draw() { }; template <typename L> -vector<double> stratified_sampling<L>::get_mean() { +vector<double> stratified_sampling<L>::get_mean() const { return mean; }; template <typename L> -vector<double> stratified_sampling<L>::get_var() { +vector<double> stratified_sampling<L>::get_var() const { return sigma2; }; template <typename L> -void stratified_sampling<L>::print_mean() { +void stratified_sampling<L>::print_mean() const { cout<<"les espérances :"<<endl; for(int i=0;i<I;i++){ cout<<mean[i]<<"\t"; @@ -146,7 +146,7 @@ void stratified_sampling<L>::print_mean() { }; template <typename L> -void stratified_sampling<L>::print_sigma() { +void stratified_sampling<L>::print_sigma() const { cout<<"les écarts types :"<<endl; for(int i=0;i<I;i++){ cout<<sqrt(sigma2[i])<<"\t"; @@ -155,7 +155,7 @@ void stratified_sampling<L>::print_sigma() { }; template <typename L> -pair<double,double> stratified_sampling<L>::estimator() { +pair<double,double> stratified_sampling<L>::estimator() const { double est_mean = 0; double est_std = 0; for (int i=0; i<I; i++) { |
