File indexing completed on 2026-08-06 09:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EXSAMPLE_exponential_generator_h_included
0012 #define EXSAMPLE_exponential_generator_h_included
0013
0014 #include "cell.h"
0015 #include "selectors.h"
0016 #include "statistics.h"
0017 #include "linear_interpolator.h"
0018 #include "binary_tree.h"
0019
0020 namespace exsample {
0021
0022
0023
0024 struct exponential_regenerate{};
0025
0026
0027 template<class Function, class Random>
0028 class exponential_generator {
0029
0030 public:
0031
0032
0033 exponential_generator()
0034 : function_(0), check_events_(0), adaption_info_(), root_cell_(),
0035 rnd_gen_(), did_split_(false), initialized_(false),
0036 evolution_variable_(0), evolution_cutoff_(0.),
0037 sample_variables_(), sample_other_variables_(),
0038 parameter_splits_(),
0039 last_cell_(), last_point_(), last_value_(0.),
0040 last_parameter_bin_(), exponents_(),
0041 last_exponent_integrand_(),
0042 last_exponent_(), compensating_(false),
0043 integral_accessor_(), missing_accessor_(),
0044 parametric_selector_(), exponent_selector_(),
0045 parametric_sampler_(), attempts_(0), accepts_(0),
0046 splits_(0), docompensate_(false), detuning_(1.0) {}
0047
0048 public:
0049
0050
0051 void initialize();
0052
0053
0054 void finalize() {}
0055
0056
0057
0058
0059 double generate(double enhance = 1.);
0060
0061
0062
0063
0064 double generate(double cutoff,
0065 double enhance) {
0066 double oldcut = evolution_cutoff_;
0067 evolution_cutoff_ = cutoff;
0068 double w = 0.0;
0069 try {
0070 w = generate(enhance);
0071 } catch(...) {
0072 evolution_cutoff_ = oldcut;
0073 throw;
0074 }
0075 evolution_cutoff_ = oldcut;
0076 return w;
0077 }
0078
0079
0080 const std::vector<double>& last_point() const { return last_point_; }
0081
0082
0083 double last_value() const { return last_value_; }
0084
0085
0086 void reject() {
0087 last_cell_->info().reject();
0088 }
0089
0090 public:
0091
0092
0093 bool initialized() const { return initialized_; }
0094
0095
0096 bool did_split() const { return did_split_; }
0097
0098
0099 Function& function() { return *function_; }
0100
0101
0102 void function(Function * f) { function_ = f; }
0103
0104
0105 adaption_info& sampling_parameters() { return adaption_info_; }
0106
0107
0108 void docompensate(bool yes = true) { docompensate_ = yes; }
0109
0110
0111 void detuning(double val) { detuning_ = val; }
0112
0113 public:
0114
0115
0116 template<class OStream>
0117 void put(OStream& os) const;
0118
0119
0120 template<class IStream>
0121 void get(IStream& is);
0122
0123 private:
0124
0125
0126
0127 bool split();
0128
0129
0130
0131
0132
0133
0134
0135 void get_exponent();
0136
0137
0138 void compensate();
0139
0140
0141
0142 std::set<std::vector<double> > parameter_points();
0143
0144
0145
0146 void recursive_parameter_points(std::set<std::vector<double> >&,
0147 std::vector<double>&,
0148 size_t);
0149
0150
0151 Function * function_;
0152
0153
0154
0155 unsigned long check_events_;
0156
0157
0158 adaption_info adaption_info_;
0159
0160
0161 binary_tree<cell> root_cell_;
0162
0163
0164 rnd_generator<Random> rnd_gen_;
0165
0166
0167 bool did_split_;
0168
0169
0170 bool initialized_;
0171
0172
0173 std::size_t evolution_variable_;
0174
0175
0176 double evolution_cutoff_;
0177
0178
0179
0180 std::vector<bool> sample_variables_;
0181
0182
0183
0184 std::vector<bool> sample_other_variables_;
0185
0186
0187
0188 std::map<std::size_t,std::vector<double> > parameter_splits_;
0189
0190
0191 binary_tree<cell>::iterator last_cell_;
0192
0193
0194 std::vector<double> last_point_;
0195
0196
0197 double last_value_;
0198
0199
0200 bit_container<parameter_hash_bits> last_parameter_bin_;
0201
0202
0203 std::map<bit_container<parameter_hash_bits>,linear_interpolator > exponents_;
0204
0205
0206 std::vector<double> last_exponent_integrand_;
0207
0208
0209 std::map<bit_container<parameter_hash_bits>,linear_interpolator >::iterator last_exponent_;
0210
0211
0212 bool compensating_;
0213
0214
0215 integral_accessor integral_accessor_;
0216
0217
0218 parametric_missing_accessor missing_accessor_;
0219
0220
0221 parametric_selector parametric_selector_;
0222
0223
0224 parametric_selector exponent_selector_;
0225
0226
0227 parametric_sampling_selector<rnd_generator<Random> > parametric_sampler_;
0228
0229
0230 unsigned long attempts_;
0231
0232
0233 unsigned long accepts_;
0234
0235
0236 unsigned long splits_;
0237
0238
0239 bool docompensate_;
0240
0241
0242 double detuning_;
0243
0244 };
0245
0246 }
0247
0248 #include "exponential_generator.icc"
0249
0250 #endif