File indexing completed on 2026-08-06 09:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EXSAMPLE_generator_h_included
0012 #define EXSAMPLE_generator_h_included
0013
0014 #include "cell.h"
0015 #include "selectors.h"
0016 #include "statistics.h"
0017 #include "binary_tree.h"
0018
0019 namespace exsample {
0020
0021
0022
0023 struct generator_update{};
0024
0025
0026 template<class Function, class Random>
0027 class generator {
0028
0029 public:
0030
0031
0032 generator()
0033 : function_(0), statistics_(), check_events_(0),
0034 adaption_info_(), root_cell_(),
0035 rnd_gen_(), did_split_(false), initialized_(false),
0036 last_cell_(), last_point_(), last_value_(0.),
0037 compensating_(false) {}
0038
0039 public:
0040
0041
0042 template<class SlaveStatistics>
0043 void initialize(SlaveStatistics&);
0044
0045
0046
0047 template<class SlaveStatistics>
0048 double generate(SlaveStatistics&);
0049
0050
0051 const std::vector<double>& last_point() const { return last_point_; }
0052
0053
0054 void reject() {
0055 statistics_.reject(last_value_);
0056 last_cell_->info().reject();
0057 }
0058
0059
0060 void finalize() {
0061 statistics_.reset();
0062 }
0063
0064 public:
0065
0066
0067 bool initialized() const { return initialized_; }
0068
0069
0070 bool did_split() const { return did_split_; }
0071
0072
0073 Function& function() { return *function_; }
0074
0075
0076 void function(Function * f) { function_ = f; }
0077
0078
0079 const statistics& stats() const { return statistics_; }
0080
0081
0082 double volume() const {
0083 return exsample::volume(adaption_info_.lower_left, adaption_info_.upper_right);
0084 }
0085
0086
0087 double integral() const {
0088 return volume() * statistics_.average_weight();
0089 }
0090
0091
0092 double integral_uncertainty() const {
0093 return volume() * std::sqrt(statistics_.average_weight_variance());
0094 }
0095
0096
0097 double current_integral() const {
0098 return volume() * statistics_.current().first;
0099 }
0100
0101
0102 double current_integral_uncertainty() const {
0103 return volume() * std::sqrt(statistics_.current().second);
0104 }
0105
0106
0107 double integral_variance() const {
0108 return sqr(volume()) * statistics_.average_weight_variance();
0109 }
0110
0111
0112 adaption_info& sampling_parameters() { return adaption_info_; }
0113
0114
0115 bool compensating() const { return compensating_; }
0116
0117 public:
0118
0119
0120 template<class OStream>
0121 void put(OStream& os) const;
0122
0123
0124 template<class IStream>
0125 void get(IStream& is);
0126
0127 private:
0128
0129
0130
0131 bool split();
0132
0133
0134
0135 void compensate();
0136
0137
0138 Function * function_;
0139
0140
0141 statistics statistics_;
0142
0143
0144
0145 unsigned long check_events_;
0146
0147
0148 adaption_info adaption_info_;
0149
0150
0151 binary_tree<cell> root_cell_;
0152
0153
0154 rnd_generator<Random> rnd_gen_;
0155
0156
0157 bool did_split_;
0158
0159
0160 bool initialized_;
0161
0162
0163 binary_tree<cell>::iterator last_cell_;
0164
0165
0166 std::vector<double> last_point_;
0167
0168
0169 double last_value_;
0170
0171
0172 bool compensating_;
0173
0174 };
0175
0176 }
0177
0178 #include "generator.icc"
0179
0180 #endif
0181