1 #ifndef MTTOOLBOX_ALGORITHM_PARTIAL_BITPATTERN_HPP
2 #define MTTOOLBOX_ALGORITHM_PARTIAL_BITPATTERN_HPP
109 template<
typename U,
typename V,
110 int bit_len,
int param_num,
int try_bit_len,
int step = 5,
134 bool verbose =
false) {
137 cout <<
"searching..." << endl;
142 cout <<
"searching from LSB" << endl;
147 cout <<
"searching from MSB" << endl;
151 for (
int p = 0; p < try_bit_len; p += step) {
152 int max_depth = p + step;
153 if (max_depth > try_bit_len) {
154 max_depth = try_bit_len;
156 for (
int i = 0; i < param_num; i++) {
157 delta = search_best_temper(rand, p, i, max_depth, verbose);
161 cout <<
"delta = " << dec << delta << endl;
239 int search_best_temper(TemperingCalculatable<U, V>& rand,
int v_bit,
240 int param_pos,
int max_v_bit,
bool verbose) {
242 int bitSize = rand.bitSize();
244 int min_delta = bitSize * bit_len;
246 int size = max_v_bit - v_bit;
248 U mask = make_mask(v_bit, size);
249 int length = bit_size<U>() / 4;
250 for (
int i = (1 << size) -1; i >= 0; i--) {
252 pattern =
static_cast<U
>(i) << v_bit;
254 pattern =
static_cast<U
>(i) << (bit_len - v_bit - size);
256 make_temper_bit(rand, mask, param_pos, pattern);
257 delta = get_equidist(rand, bit_len);
258 if (delta < min_delta) {
260 cout <<
"pattern change " << hex << min_pattern
261 <<
":" << pattern << endl;
264 min_pattern = pattern;
265 }
else if (delta == min_delta) {
268 cout <<
"pattern change " << hex << min_pattern
269 <<
":" << pattern << endl;
271 min_pattern = pattern;
275 make_temper_bit(rand, mask, param_pos, min_pattern);
277 cout << dec << min_delta <<
":"
278 << hex << setw(length) << min_pattern <<
":"
279 << hex << setw(length) << mask << endl;
302 int get_equidist(TemperingCalculatable<U, V>& rand,
304 AlgorithmEquidistribution<U, V> sb(rand, bit_length);
306 int sum = sb.get_all_equidist(veq);
334 U make_mask(
int start,
int size) {
337 if (start + size > bit_len) {
338 size = bit_len - start;
342 mask <<= bit_len - size;
343 mask >>= bit_len - start - size;
346 mask >>= bit_len - size;
347 mask <<= bit_len - start - size;
354 #endif // MTTOOLBOX_ALGORITHM_PARTIAL_BITPATTERN_HPP
Abstruct class for searching tempering parameters.
Calculate dimension of equi-distribution of output of pseudo random number generators.
Abstract class for searching tempering parameters.