MTToolBox  0.2.10
AlgorithmReducibleRT.hpp
Go to the documentation of this file.
1 #ifndef MTTOOLBOX_ALGORITHM_REDUCIBLE_RT_HPP
2 #define MTTOOLBOX_ALGORITHM_REDUCIBLE_RT_HPP
3 
30 #include <iostream>
31 #include <ostream>
32 #include <iomanip>
33 #include <vector>
34 #include <cstdlib>
35 #include <cerrno>
36 #include <unistd.h>
37 #include <time.h>
43 #include <MTToolBox/util.hpp>
44 
45 namespace MTToolBox {
75  template<typename U, typename G>
77  public:
95  baseGenerator = &bg;
96  }
97 
126  bool search(G& rg,
129  bool verbose = false,
130  std::ostream& os = std::cout,
131  bool no_lsb = false) {
132  using namespace NTL;
133  using namespace std;
134 
135  out = &os;
136  int veq[bit_size<U>()];
137  AlgorithmReducibleRecursionSearch<U> search(rg, *baseGenerator);
139  int mexp = rg.bitSize();
140  bool found = false;
141  for (int i = 0;; i++) {
142  if (search.start(1000 * mexp)) {
143  found = true;
144  break;
145  }
146  if (verbose) {
147  *out << "not found in " << (i + 1) * 10000 << endl;
148  }
149  }
150  if (!found) {
151  return false;
152  }
153  if (verbose) {
154  time_t t = time(NULL);
155  *out << "irreducible parameter is found at " << ctime(&t);
156  }
157  if (verbose) {
158  *out << "count = " << search.getCount() << endl;
159  *out << rg.getParamString() << endl;
160  }
161  poly = search.getIrreducibleFactor();
162  parity = cp.searchParity(rg, poly);
163  weight = NTL::weight(poly);
164  GF2X lcm(0, 1);
166  NTL::GF2X quotient = lcm / poly;
167  annihilate(&rg, quotient);
168  if (verbose) {
169  AlgorithmEquidistribution<U> sb(rg, bit_size<U>());
170  int delta = sb.get_all_equidist(veq);
171  print_kv(veq, mexp, bit_size<U>());
172  *out << "delta = " << dec << delta << endl;
173  }
174  if (! no_lsb) {
175  st2(rg, verbose);
176  if (verbose) {
177  if (st2.isLSBTempering()) {
178  rg.setReverseOutput();
179  }
180  AlgorithmEquidistribution<U> sc(rg, bit_size<U>());
181  delta = sc.get_all_equidist(veq);
182  rg.resetReverseOutput();
183  time_t t = time(NULL);
184  *out << "lsb tempering parameters are found at "
185  << ctime(&t) << endl;
186  print_kv(veq, mexp, bit_size<U>());
187  *out << "lsb delta = " << dec << delta << endl;
188  }
189  }
190  st1(rg, verbose);
191  AlgorithmEquidistribution<U> sc(rg, bit_size<U>());
192  delta = sc.get_all_equidist(veq);
193  if (verbose) {
194  time_t t = time(NULL);
195  *out << "tempering parameters are found at " << ctime(&t)
196  << endl;
197  *out << rg.getParamString() << endl;
198  print_kv(veq, mexp, bit_size<U>());
199  *out << "delta = " << dec << delta << endl;
200  }
201  return true;
202  }
203 
235  bool verbose = false,
236  std::ostream& os = std::cout) {
237  return search(rg, st, st, verbose, os, true);
238  }
239 
252  int getDelta() {
253  return delta;
254  }
255 
269  const NTL::GF2X& getIrreducibleFactor() {
270  return poly;
271  }
272 
284  U getParity() const {
285  return parity;
286  }
287 
288  private:
289  int weight;
290  int delta;
291  U parity;
292  NTL::GF2X poly;
293  //NTL::GF2X characteristic;
294  std::ostream * out;
295  AbstractGenerator<U> * baseGenerator;
296 
297  void print_kv(int veq[], int mexp, int size) {
298  using namespace std;
299  for (int i = 0; i < size; i++) {
300  *out << dec << i + 1 << ":" << veq[i]
301  << "(" << mexp / (i + 1) - veq[i] << ")"
302  << endl;
303  }
304  }
305  };
306 
307 }
308 #endif //MTTOOLBOX_ALGORITHM_Reducible_RT_HPP
Calculate the dimension of equidistribution of reducible generators.
U getParity() const
Returns a period certification vector (parity check vector)
Definition: AlgorithmReducibleRT.hpp:284
pseudo random number generator.
Definition: AbstractGenerator.hpp:48
Calculate the parity check vector of reducible generator.
Definition: AlgorithmCalculateParity.hpp:91
const NTL::GF2X & getIrreducibleFactor()
Returns irreducible factor with mexp degree of characteristic polynomial of state transition function...
Definition: AlgorithmReducibleRT.hpp:269
Search parameters of state transition function.
void calcCharacteristicPolynomial(RecursionSearchable< U, V > *rand, NTL::GF2X &poly)
Calculate dimension of equi-distribution of output of pseudo random number generators.
Definition: AlgorithmEquidistribution.hpp:238
Utility functions.
bool search(TemperingCalculatable< U > &rg, AlgorithmTempering< U > &st, bool verbose=false, std::ostream &os=std::cout)
Simple wrapper for users who want to search tempering parameter only from MSB.
Definition: AlgorithmReducibleRT.hpp:233
Search parameters of state transition function of pseudo random number generator so that the characte...
Definition: AlgorithmReducibleRecursionSearch.hpp:84
int get_all_equidist(int veq[])
Calculate dimension of equi-distribution with v-bit accuracy.
Definition: AlgorithmEquidistribution.hpp:470
Definition: AlgorithmReducibleRT.hpp:76
Calculate the parity check vector of reducible generator.
Abstract class for searching tempering parameters.
void annihilate(EquidistributionCalculatable< U, V > *rg, const NTL::GF2X &poly)
Annihilate internal state of generator by given polynomial.
Definition: ReducibleGenerator.hpp:148
Abstruct class for searching tempering parameters.
bool search(G &rg, AlgorithmTempering< U > &st1, AlgorithmTempering< U > &st2, bool verbose=false, std::ostream &os=std::cout, bool no_lsb=false)
Search parameters for state transition function and parameters for tempering.
Definition: AlgorithmReducibleRT.hpp:126
U searchParity(G &g, const NTL::GF2X &f)
calculate the basis of subspace annihilated by q, and get the period certification vector (parity vec...
Definition: AlgorithmCalculateParity.hpp:110
AlgorithmReducibleRecursionAndTempering(AbstractGenerator< U > &bg)
Constructor.
Definition: AlgorithmReducibleRT.hpp:94
int getDelta()
returns sum of d(v)s, which are difference between k(v) and theoretical upper bound.
Definition: AlgorithmReducibleRT.hpp:252
Algorithm that search tempering parameters to improve dimension of equi-distribution of output of pse...
Definition: AlgorithmTempering.hpp:62
virtual bool isLSBTempering() const
Shows if searching tempering parameters is from LSBs.
Definition: AlgorithmTempering.hpp:107
name space for MTToolBox