File indexing completed on 2026-08-06 09:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EXSAMPLE_cell_h_included
0012 #define EXSAMPLE_cell_h_included
0013
0014 #include "utility.h"
0015 #include "adaption_info.h"
0016 #include "statistics.h"
0017
0018 namespace exsample {
0019
0020
0021 class cell_info {
0022
0023 public:
0024
0025
0026 cell_info();
0027
0028
0029 cell_info(const std::vector<double>& ll,
0030 const std::vector<double>& ur,
0031 const adaption_info& ainfo);
0032
0033
0034
0035 cell_info(const std::vector<double>& ll,
0036 const std::vector<double>& ur,
0037 const std::vector<bool>& sampled_variables,
0038 const adaption_info& ainfo);
0039
0040 public:
0041
0042
0043 template<class Random>
0044 void select(Random&,
0045 std::vector<double>&);
0046
0047
0048
0049 template<class Random>
0050 void select(Random&,
0051 std::vector<double>&,
0052 const std::vector<bool>&);
0053
0054
0055 void selected(const std::vector<double>&,
0056 double,
0057 const adaption_info&);
0058
0059
0060
0061 void accept() { ++accepted_; }
0062
0063
0064 void reject() { --accepted_; }
0065
0066 public:
0067
0068
0069 bool bad(const adaption_info& ainfo) const {
0070 return ((static_cast<double>(accepted_)/static_cast<double>(attempted_)) <
0071 ainfo.efficiency_threshold);
0072 }
0073
0074
0075
0076 std::pair<std::size_t,double> get_split(const adaption_info&,
0077 bool&) const;
0078
0079
0080
0081
0082 template<class Random, class Function, class SlaveStatistics>
0083 void explore(Random&, const adaption_info&, Function*, statistics*,
0084 SlaveStatistics& opt);
0085
0086
0087
0088
0089 template<class Random, class Function>
0090 void explore(Random&, const adaption_info&, Function*);
0091
0092 public:
0093
0094
0095 double overestimate() const { return overestimate_; }
0096
0097
0098 const std::vector<double>& last_max_position() const { return last_max_position_; }
0099
0100
0101 void overestimate(double v, const std::vector<double>& pos) {
0102 overestimate_ = v;
0103 last_max_position_ = pos;
0104 }
0105
0106
0107 double volume() const { return volume_; }
0108
0109
0110 const std::vector<double>& lower_left() const { return lower_left_; }
0111
0112
0113 const std::vector<double>& upper_right() const { return upper_right_; }
0114
0115
0116 unsigned long attempted() const { return attempted_; }
0117
0118
0119 unsigned long accepted() const { return accepted_; }
0120
0121 public:
0122
0123
0124
0125 int parametric_missing(const bit_container<parameter_hash_bits>& id) const;
0126
0127
0128
0129 void parametric_missing(const bit_container<parameter_hash_bits>& id, int n);
0130
0131
0132
0133 void increase_parametric_missing(const bit_container<parameter_hash_bits>& id);
0134
0135
0136
0137 void decrease_parametric_missing(const bit_container<parameter_hash_bits>& id);
0138
0139
0140
0141 bool parametric_compensating() const {
0142 return !parametric_missing_map_.empty();
0143 }
0144
0145
0146
0147 bool contains_parameter(const std::vector<double>& point,
0148 const std::vector<bool>& sampled) const;
0149
0150 public:
0151
0152
0153 template<class OStream>
0154 void put(OStream& os) const;
0155
0156
0157 template<class IStream>
0158 void get(IStream& is);
0159
0160 private:
0161
0162
0163 double overestimate_;
0164
0165
0166 double volume_;
0167
0168
0169 std::vector<double> lower_left_;
0170
0171
0172 std::vector<double> upper_right_;
0173
0174
0175 std::vector<double> mid_point_;
0176
0177
0178
0179 std::vector<double> last_max_position_;
0180
0181
0182 std::vector<std::pair<double,double> > avg_weight_;
0183
0184
0185 unsigned long attempted_;
0186
0187
0188 unsigned long accepted_;
0189
0190
0191
0192 std::map<bit_container<parameter_hash_bits>,int> parametric_missing_map_;
0193
0194 };
0195
0196
0197 class cell {
0198
0199 public:
0200
0201
0202 cell();
0203
0204
0205 cell(const std::vector<double>& ll,
0206 const std::vector<double>& ur,
0207 const adaption_info& ainfo);
0208
0209
0210
0211 cell(const std::vector<double>& ll,
0212 const std::vector<double>& ur,
0213 const std::vector<bool>& sampled_variables,
0214 const adaption_info& ainfo);
0215
0216
0217 cell(const cell& x);
0218
0219
0220 cell& operator=(const cell& x);
0221
0222 public:
0223
0224
0225
0226 template<class Random, class Function>
0227 std::pair<cell,cell> split(std::pair<std::size_t,double> split_d,
0228 Random& rnd_gen,
0229 Function* f,
0230 const adaption_info& ainfo,
0231 const std::vector<bool>& sampled =
0232 std::vector<bool>());
0233
0234 public:
0235
0236
0237 std::size_t split_dimension() const { return split_dimension_; }
0238
0239
0240 double split_point() const { return split_point_; }
0241
0242
0243 double integral() const { return integral_; }
0244
0245
0246 double& integral() { return integral_; }
0247
0248
0249 void integral(double v) { integral_ = v; }
0250
0251
0252 int& missing_events() { return missing_events_; }
0253
0254
0255 int missing_events() const { return missing_events_; }
0256
0257
0258 void missing_events(int n) { missing_events_ = n; }
0259
0260
0261 cell_info& info() { assert(cell_info_); return *cell_info_; }
0262
0263
0264 const cell_info& info() const { assert(cell_info_); return *cell_info_; }
0265
0266 public:
0267
0268
0269 template<class OStream>
0270 void put(OStream& os) const;
0271
0272
0273 template<class IStream>
0274 void get(IStream& is);
0275
0276 private:
0277
0278
0279
0280 std::size_t split_dimension_;
0281
0282
0283 double split_point_;
0284
0285
0286
0287
0288 double integral_;
0289
0290
0291 int missing_events_;
0292
0293
0294
0295 std::unique_ptr<cell_info> cell_info_;
0296
0297
0298 };
0299
0300 }
0301
0302 #include "cell.icc"
0303
0304 #endif