File indexing completed on 2026-08-06 09:24:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EXSAMPLE_statistics_h_included
0012 #define EXSAMPLE_statistics_h_included
0013
0014 #include "utility.h"
0015
0016 namespace exsample {
0017
0018
0019
0020 class statistics {
0021
0022 public:
0023
0024
0025 statistics();
0026
0027
0028
0029 void presampled(double weight);
0030
0031
0032
0033 void select(double weight,
0034 bool calculate_integral = true);
0035
0036
0037 void accept(double weight) {
0038 ++accepted_;
0039 if (weight < 0) ++accepted_negative_;
0040 }
0041
0042
0043 void reject(double weight) {
0044 --accepted_;
0045 if (weight < 0) --accepted_negative_;
0046 }
0047
0048
0049 void reset();
0050
0051
0052
0053 std::pair<double,double> current() const;
0054
0055
0056 double average_weight() const {
0057 return (n_iterations_ == 0 ? 0. : average_weight_/n_iterations_);
0058 }
0059
0060
0061 double average_abs_weight() const {
0062 return (n_iterations_ == 0 ? 0. : average_abs_weight_/n_iterations_);
0063 }
0064
0065
0066 double average_weight_variance() const {
0067 return (n_iterations_ == 0 ? 0. : average_weight_variance_/n_iterations_);
0068 }
0069
0070
0071 unsigned long iteration_points() const { return iteration_points_; }
0072
0073
0074 unsigned long n_iterations() const { return n_iterations_; }
0075
0076
0077 unsigned long attempted() const { return attempted_; }
0078
0079
0080 unsigned long accepted() const { return accepted_; }
0081
0082
0083 unsigned long accepted_negative() const { return accepted_negative_; }
0084
0085
0086 double sum_weights() const { return sum_weights_; }
0087
0088
0089 double sum_abs_weights() const { return sum_abs_weights_; }
0090
0091
0092 double sum_weights_squared() const { return sum_weights_squared_; }
0093
0094
0095 double max_weight() const { return max_weight_; }
0096
0097 public:
0098
0099
0100 template<class OStream>
0101 void put(OStream& os) const;
0102
0103
0104 template<class IStream>
0105 void get(IStream& is);
0106
0107 private:
0108
0109
0110 double average_weight_;
0111
0112
0113 double average_abs_weight_;
0114
0115
0116 double average_weight_variance_;
0117
0118
0119 unsigned long iteration_points_;
0120
0121
0122 unsigned long attempted_;
0123
0124
0125 unsigned long accepted_;
0126
0127
0128 unsigned long accepted_negative_;
0129
0130
0131 double sum_weights_;
0132
0133
0134 double sum_abs_weights_;
0135
0136
0137 double sum_weights_squared_;
0138
0139
0140 double max_weight_;
0141
0142
0143 unsigned long n_iterations_;
0144
0145 };
0146
0147 }
0148
0149 #include "statistics.icc"
0150
0151 #endif