本文整理汇总了C++中boost::random::mt19937::seed方法的典型用法代码示例。如果您正苦于以下问题:C++ mt19937::seed方法的具体用法?C++ mt19937::seed怎么用?C++ mt19937::seed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::random::mt19937
的用法示例。
在下文中一共展示了mt19937::seed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_rand_gen
static void init_rand_gen()
{
int fd = open("/dev/urandom", O_RDONLY);
if (fd != -1) {
uint32_t seed;
read(fd, &seed, sizeof(uint32_t));
g_mt_rand.seed(seed);
close(fd);
}
else {
g_mt_rand.seed(time(NULL));
}
}
示例2: main
int main() {
gen.seed(static_cast<unsigned int>(std::time(0)));
const int beam_size = 3;
const int vocab_size = 10;
const int start_symbol = 0;
const int end_symbol = 1;
const int max_decoding_length = 30;
const int min_decoding_length = 10;
const int source_length = 10;
const precision penalty = 3;
decoder<precision> d(beam_size,vocab_size,start_symbol,end_symbol,
max_decoding_length,min_decoding_length,penalty,"");
Eigen::Matrix<precision,Eigen::Dynamic, Eigen::Dynamic> outputDist;
Eigen::Matrix<precision, 1, Eigen::Dynamic> normalization;
outputDist.resize(vocab_size,beam_size);
normalization.resize(1,beam_size);
init_output_dist(outputDist,normalization);
d.init_decoder();
for(int i=0; i<20; i++) {
init_output_dist(outputDist,normalization);
d.expand_hypothesis(outputDist);
d.print_current_hypotheses();
}
d.finish_current_hypotheses(outputDist);
d.print_current_hypotheses();
}
示例3: Seed
void UnsyncedRNG::Seed(unsigned seed)
{
#ifdef USE_BOOST_RNG
rng.seed(seed);
#else
randSeed = seed;
#endif
}
示例4: seedrand
void seedrand()
{
randfast.seed(time(0));
randfast64.seed(time(0));
}
示例5: main
int main(int argc, char** argv) {
build_odes();
return 0;
// build_odes();
// return 0;
ptime begin = microsec_clock::local_time();
random::mt19937 rng;
random::uniform_real_distribution<> uni(-1, 1);
int seed = lexical_cast<int>(argv[1]);
if (seed != -1) {
double Wi = lexical_cast<double>(argv[2]);
double Wf = lexical_cast<double>(argv[3]);
double mu = lexical_cast<double>(argv[4]);
double Ui = UWi(Wi);
double D = lexical_cast<double>(argv[5]);
double taui = lexical_cast<double>(argv[6]);
double tauf = lexical_cast<double>(argv[7]);
int ntaus = lexical_cast<int>(argv[8]);
int numthreads = lexical_cast<int>(argv[9]);
int resi = lexical_cast<int>(argv[10]);
// int integrator = lexical_cast<int>(argv[11]);
std::string intg = argv[11];
double dt = lexical_cast<double>(argv[12]);
#ifdef AMAZON
// path resdir("/home/ubuntu/Results/Canonical Transformation Dynamical Gutzwiller");
path resdir("/home/ubuntu/Dropbox/Amazon EC2/Simulation Results/CTDG");
#else
path resdir("/Users/Abuenameh/Documents/Simulation Results/Canonical Transformation Dynamical Gutzwiller 2");
// path resdir("/Users/Abuenameh/Documents/Simulation Results/Dynamical Gutzwiller Hartmann Comparison");
#endif
if (!exists(resdir)) {
cerr << "Results directory " << resdir << " does not exist!" << endl;
exit(1);
}
ostringstream oss;
oss << "res." << resi << ".txt";
path resfile = resdir / oss.str();
//#ifndef AMAZON
while (exists(resfile)) {
resi++;
oss.str("");
oss << "res." << resi << ".txt";
resfile = resdir / oss.str();
}
//#endif
if (seed < 0) {
resi = seed;
oss.str("");
oss << "res." << resi << ".txt";
resfile = resdir / oss.str();
}
vector<double> xi(L, 1);
rng.seed(seed);
if (seed > -1) {
for (int j = 0; j < L; j++) {
xi[j] = (1 + D * uni(rng));
}
}
// double Ui = UWi(Wi);
double mui = mu * Ui;
filesystem::ofstream os(resfile);
printMath(os, "int", resi, intg);
printMath(os, "seed", resi, seed);
printMath(os, "Delta", resi, D);
printMath(os, "dt", resi, dt);
printMath(os, "mures", resi, mui);
printMath(os, "Ures", resi, Ui);
printMath(os, "xires", resi, xi);
os << flush;
printMath(os, "Wires", resi, Wi);
printMath(os, "Wfres", resi, Wf);
os << flush;
cout << "Res: " << resi << endl;
struct shm_remove {
shm_remove() {
shared_memory_object::remove("SharedMemory");
}
~shm_remove() {
//.........这里部分代码省略.........
示例6: initialize
worker_input* initialize(double Wi, double Wf, double mu, vector<double>& xi, managed_shared_memory& segment) {
SX f = SX::sym("f", 2 * L * dim);
SX dU = SX::sym("dU", L);
SX J = SX::sym("J", L);
SX U0 = SX::sym("U0");
U0 = UW(Wi);
for (int i = 0; i < L; i++) {
J[i] = JWij(Wi * xi[i], Wi * xi[mod(i + 1)]);
dU[i] = UW(Wi * xi[i]) - U0;
}
SX E = energy(f, J, U0, dU, mu).real();
SX g = SX::sym("g", L);
for (int i = 0; i < L; i++) {
g[i] = 0;
for (int n = 0; n < dim; n++) {
g[i] += f[2 * (i * dim + n)] * f[2 * (i * dim + n)] + f[2 * (i * dim + n) + 1] * f[2 * (i * dim + n) + 1];
}
}
SXFunction nlp("nlp", nlpIn("x", f), nlpOut("f", E, "g", g));
NlpSolver solver("solver", "ipopt", nlp, make_dict("hessian_approximation", "limited-memory", "linear_solver", "ma86", "print_level", 0, "print_time", false, "obj_scaling_factor", 1));
boost::random::mt19937 rng;
boost::random::uniform_real_distribution<> uni(-1, 1);
vector<double> xrand(2 * L*dim, 1);
rng.seed();
for (int i = 0; i < 2 * L * dim; i++) {
xrand[i] = uni(rng);
}
map<string, DMatrix> arg;
arg["lbx"] = -1;
arg["ubx"] = 1;
arg["x0"] = xrand;
arg["lbg"] = 1;
arg["ubg"] = 1;
map<string, DMatrix> res = solver(arg);
vector<double> x0 = res["x"].nonzeros();
// vector<double> x0 = xrand;
// cout << "x0 = " << ::math(x0) << endl;
// cout << "E0 = " << ::math(res["f"].toScalar()) << endl;
vector<complex<double>> x0i(dim);
for (int i = 0; i < L; i++) {
for (int n = 0; n <= nmax; n++) {
x0i[n] = complex<double>(x0[2 * (i * dim + n)], x0[2 * (i * dim + n) + 1]);
}
double nrm = sqrt(abs(dot(x0i, x0i)));
for (int n = 0; n <= nmax; n++) {
x0[2 * (i * dim + n)] /= nrm;
x0[2 * (i * dim + n) + 1] /= nrm;
}
}
// cout << "nlp: " << ::math(nlp(vector<DMatrix>{x0, vector<double>()})[0].toScalar()) << endl;
void_allocator void_alloc(segment.get_segment_manager());
worker_input* input = segment.construct<worker_input>("input")(void_alloc);
input->U0 = UW(Wi);
for (int i = 0; i < L; i++) {
input->J0.push_back(JWij(Wi * xi[i], Wi * xi[mod(i + 1)]));
}
for (int i = 0; i < 2 * L * dim; i++) {
input->x0.push_back(x0[i]);
}
for (int i = 0; i < L; i++) {
complex_vector f0i(dim, void_alloc);
for (int n = 0; n <= nmax; n++) {
f0i[n] = complex<double>(x0[2 * (i * dim + n)], x0[2 * (i * dim + n) + 1]);
}
input->f0.push_back(f0i);
}
input->Wi = Wi;
input->Wf = Wf;
input->mu = mu;
for (int i = 0; i < L; i++) {
input->xi.push_back(xi[i]);
}
return input;
}
示例7: main
int main(int argc, char** argv) {
ptime begin = microsec_clock::local_time();
random::mt19937 rng;
random::uniform_real_distribution<> uni(-1, 1);
int seed = lexical_cast<int>(argv[1]);
double Wi = lexical_cast<double>(argv[2]);
double Wf = lexical_cast<double>(argv[3]);
double mu = lexical_cast<double>(argv[4]);
double Ui = UWi(Wi);
double D = lexical_cast<double>(argv[5]);
double taui = lexical_cast<double>(argv[6]);
double tauf = lexical_cast<double>(argv[7]);
int ntaus = lexical_cast<int>(argv[8]);
// double tf = 2*tau;
// int nsteps = lexical_cast<int>(argv[9]);
double dt = lexical_cast<double>(argv[9]);
// int dnsav = lexical_cast<int>(argv[8]);
// int nsteps = (int) ceil(2 * tau / dt);
// double h = 2 * tau / nsteps;
int numthreads = lexical_cast<int>(argv[10]);
int resi = lexical_cast<int>(argv[11]);
// int resi = 0;
// if (argc > 9) {
// resi = lexical_cast<int>(argv[9]);
// }
int subresi = -1;
int seed2 = 0;
if (argc > 12) {
// subresi = lexical_cast<int>(argv[12]);
seed2 = lexical_cast<int>(argv[12]);
}
#ifdef AMAZON
// path resdir("/home/ubuntu/Results/Canonical Transformation Dynamical Gutzwiller");
path resdir("/home/ubuntu/Dropbox/Amazon EC2/Simulation Results/Canonical Transformation Dynamical Gutzwiller 2");
#else
path resdir("/Users/Abuenameh/Documents/Simulation Results/Canonical Transformation Dynamical Gutzwiller 2");
// path resdir("/Users/Abuenameh/Documents/Simulation Results/Dynamical Gutzwiller Hartmann Comparison");
#endif
if (!exists(resdir)) {
cerr << "Results directory " << resdir << " does not exist!" << endl;
exit(1);
}
ostringstream oss;
if (subresi == -1) {
oss << "res." << resi << ".txt";
}
else {
oss << "res." << resi << "." << subresi << ".txt";
}
path resfile = resdir / oss.str();
//#ifndef AMAZON
while (exists(resfile)) {
resi++;
oss.str("");
if (subresi == -1) {
oss << "res." << resi << ".txt";
}
else {
oss << "res." << resi << "." << subresi << ".txt";
}
resfile = resdir / oss.str();
}
//#endif
// if (seed == -1) {
// resi = -1;
if (seed < 0) {
resi = seed;
oss.str("");
oss << "res." << resi << ".txt";
resfile = resdir / oss.str();
}
vector<double> xi(L, 1);
rng.seed(seed);
if (seed > -1) {
for (int j = 0; j < L; j++) {
xi[j] = (1 + D * uni(rng));
}
}
// double Ui = UWi(Wi);
double mui = mu * Ui;
filesystem::ofstream os(resfile);
printMath(os, "seed", resi, seed);
printMath(os, "Delta", resi, D);
//.........这里部分代码省略.........
开发者ID:Abuenameh,项目名称:Canonical-Transformation-Dynamical-Gutzwiller-Casadi-Cvodes,代码行数:101,代码来源:main.cpp
示例8: getRandomNumber
int Helper::getRandomNumber(const int _min, const int _max)
{
randomGenerator.seed(std::time(0));
boost::random::uniform_int_distribution<> dist(_min, _max);
return dist(randomGenerator);
}
示例9: random_initialize
// Initialize the seed of the random number generator
void random_initialize(unsigned int seed) {
random_gen.seed(seed);
}
示例10: seed
void seed(int seed)
{
gen.seed(seed);
}
示例11: reset
void reset(int min, int max, int seed)
{
dist = boost::random::uniform_int_distribution<>(min, max);
gen.seed(seed);
}
示例12: dist
RandomInt(int min, int max, int seed)
: dist(min, max)
{
gen.seed(seed);
}
示例13: init
void init(unsigned int seed, std::string outputDirectory,
std::string confFileName, bool overwrite, bool saveAll) {
// Seed random number generator
rng.seed(seed);
conf.reset(new EvolverConfiguration());
if (!conf->init(confFileName)) {
std::cerr << "Problems parsing the evolution configuration file. Quit."
<< std::endl;
exitRobogen(EXIT_FAILURE);
}
robotConf = ConfigurationReader::parseConfigurationFile(
conf->simulatorConfFile);
if (robotConf == NULL) {
std::cerr << "Problems parsing the robot configuration file. Quit."
<< std::endl;
exitRobogen(EXIT_FAILURE);
}
// ---------------------------------------
// Set up evolution
// ---------------------------------------
if (conf->selection == conf->DETERMINISTIC_TOURNAMENT) {
selector.reset(new DeterministicTournament(conf->tournamentSize, rng));
} else {
std::cerr << "Selection type id " << conf->selection << " unknown."
<< std::endl;
exitRobogen(EXIT_FAILURE);
}
mutator.reset(new Mutator(conf, rng));
log.reset(new EvolverLog());
try {
if (!log->init(conf, robotConf, outputDirectory, overwrite, saveAll)) {
std::cerr << "Error creating evolver log. Aborting." << std::endl;
exitRobogen(EXIT_FAILURE);
}
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
exitRobogen(EXIT_FAILURE);
} catch (...) {
std::cerr << "non standard exception " << std::endl;
exitRobogen(EXIT_FAILURE);
}
// ---------------------------------------
// parse robot from file & initialize population
// ---------------------------------------
boost::shared_ptr<RobotRepresentation> referenceBot(
new RobotRepresentation());
bool growBodies = false;
if (conf->evolutionMode == EvolverConfiguration::BRAIN_EVOLVER
&& conf->referenceRobotFile.compare("") == 0) {
std::cerr << "Trying to evolve brain, but no robot file provided."
<< std::endl;
exitRobogen(EXIT_FAILURE);
} else if (conf->referenceRobotFile.compare("") != 0) {
if (!referenceBot->init(conf->referenceRobotFile)) {
std::cerr << "Failed interpreting robot from text file"
<< std::endl;
exitRobogen(EXIT_FAILURE);
}
} else { //doing body evolution and don't have a reference robot
if (referenceBot->init()) {
growBodies = true;
} else {
std::cerr << "Failed creating base robot for body evolution"
<< std::endl;
exitRobogen(EXIT_FAILURE);
}
}
neat = (conf->evolutionaryAlgorithm == EvolverConfiguration::HYPER_NEAT);
population.reset(new Population());
if (!population->init(referenceBot, conf->mu, mutator, growBodies,
(!(conf->useBrainSeed || neat)) ) ) {
std::cerr << "Error when initializing population!" << std::endl;
exitRobogen(EXIT_FAILURE);
}
if (neat) {
neatContainer.reset(new NeatContainer(conf, population, seed, rng));
}
// ---------------------------------------
// open sockets for communication with simulator processes
// ---------------------------------------
#ifndef EMSCRIPTEN
sockets.resize(conf->sockets.size());
for (unsigned int i = 0; i < conf->sockets.size(); i++) {
sockets[i] = new TcpSocket;
#ifndef FAKEROBOTREPRESENTATION_H // do not bother with sockets when using
// benchmark
if (!sockets[i]->open(conf->sockets[i].first,
conf->sockets[i].second)) {
//.........这里部分代码省略.........
示例14: RandomSeed
/**
* Set the random seed used by the random functions (Random() and RandInt()).
* The seed is casted to a 32-bit integer before being given to the random
* number generator, but a size_t is taken as a parameter for API consistency.
*
* @param seed Seed for the random number generator.
*/
inline void RandomSeed(const size_t seed)
{
randGen.seed((uint32_t) seed);
srand((unsigned int) seed);
}
示例15: main
int main() {
string x, y, opcode;
string cmd;
boost::random::uniform_int_distribution<> dist32bit(0, 2147483647);
boost::random::uniform_int_distribution<> dist3bit(0, 4);
vector<pair<string,string> > db;
for(int i = 0; i < 5000; i++) {
gen.seed(static_cast<unsigned int>(time(0) + getpid()) + i);
int r0 = dist32bit(gen);
int r1 = dist32bit(gen);
int r2 = dist3bit(gen);
//cout << r0 << " " << r1 << " " << r2 << endl;
bitset<32> t0(r0);
bitset<32> t1(r1);
bitset<3> t2(r2);
x = t0.to_string();
y = t1.to_string();
opcode = t2.to_string();
//cout << x << " " << y << " " << opcode << endl;
cmd = "vvp a.out +x=" + x + " +y=" + y + " +opcode=" + opcode; // Program to run or "wrap"
string out = exec(cmd);
//cout << out;
int index;
string delay;
const char* process = out.c_str();
for(int i = strlen(process) - 1; i >= 0; i--) {
if(process[i] == ' ') { index = i; break; }
}
for(int i = index + 1; i < strlen(process); i++) {
delay = delay + process[i];
}
add(delay, opcode, db);
cout << i << endl;
}
int j;
ofstream f("5krandominputs.txt"); // Output file
for(vector<pair<string,string> >::const_iterator i = db.begin(); i != db.end(); ++i) {
string first = (*i).first;
string second = (*i).second;
trim(first);
trim(second);
string w = first + " " + second + '\n';
f << w;
int j;
cout << "writing..." << j++ << endl;
}
}