int initialize(const configuration &conf, const std::string &outputDirectory, const std::string &) { if (conf.get(maxFlows, "max-flows", "sensor_dns") != configuration::OK) { cerr << "sensor_dns: missing or invalid max-flows" << endl; return 1; } if (conf.get(queryTimeout, "query-timeout", "sensor_dns") != configuration::OK) { cerr << "sensor_dns: missing or invalid query-timeout" << endl; return 1; } flowTable.rehash(maxFlows); boost::shared_ptr<StrftimeWriteEnumerator<DNS> > enumerator(new StrftimeWriteEnumerator<DNS>( outputDirectory, "%Y/%m/%d/dns_%H")); boost::shared_ptr<InferFileWriter<FlatFileWriter<DNS> > > inferWriter(new InferFileWriter<FlatFileWriter<DNS> >(enumerator)); writer = new AsynchronousWriter<InferFileWriter<FlatFileWriter<DNS> > >(inferWriter); flowTableLocks = new pthread_mutex_t[flowTable.bucket_count()]; for (size_t bucket = 0; bucket < flowTable.bucket_count(); ++bucket) { if (pthread_mutex_init(&(flowTableLocks[bucket]), NULL) != 0) { abort(); } } pthread_mutex_init(&flushLock, NULL); return 0; }
std::size_t configuration_hasher::hash(const configuration& v) { std::size_t seed(0); combine(seed, hash_std_unordered_set_std_string(v.enabled_kernels())); combine(seed, v.enable_kernel_directories()); return seed; }
dcomplex attempt() { auto k = config->perturbation_order(); if (k <= 0) return 0; // Config is empty, trying to remove makes no sense int p = rng(k); // Choose one of the operators for removal auto det_ratio = config->Mmatrices[up].try_remove(p, p) * config->Mmatrices[down].try_remove(p, p); return -k / (beta * U) * det_ratio; // The Metropolis ratio }
dcomplex attempt() { // Insert an interaction vertex at time tau with aux spin s double tau = rng(beta); int s = rng(2); auto k = config->perturbation_order(); auto det_ratio = config->Mmatrices[up].try_insert(k, k, {tau, s}, {tau, s}) * config->Mmatrices[down].try_insert(k, k, {tau, s}, {tau, s}); return -beta * U / (k + 1) * det_ratio; // The Metropolis ratio }
//----------------------------------------------------------------------------- roi_stack get_roi_stack(const configuration &config) { roi_stack stack; if(config.has_option("roi")) stack.push_back(get_roi_from_string(config.value<string>("roi"))); return stack; }
void configuration::readGeneralConfig(string cfgFile){ ifstream config(ofToDataPath(cfgFile).c_str()); while (config.peek()!=EOF) { string nextLine; getline(config, nextLine); vector<string> token=ofSplitString(nextLine, "=\r\n"); if(token.size()){ if(token[0]=="QUAKE_DIR"){ eqDir=ofToDataPath(token[1]); } else if(token[0]=="VERBOSE"){ verbose=ofToInt(token[1]); } else if(token[0]=="TIMEOUT"){ timeout=ofToInt(token[1]); } else if(token[0]=="HOME_CURRENT"){ homeCurrent=ofToInt(token[1]); } else if(token[0]=="SCALE_ALL_QUAKES"){ scaleToAll=ofToInt(token[1]); } else if(token[0]=="SMOOTHING"){ smoothing=ofToInt(token[1]); } else if(token[0]=="AUTO_TRIM"){ autoTrim=ofToInt(token[1]); } else if(token[0]=="NO_TABLE"){ noTable=ofToInt(token[1]); } else if(token[0]=="MAX_DISPLACEMENT"){ maxDisp=ofToInt(token[1]); } else if(token[0]=="FULLSCREEN"){ ofSetFullscreen(ofToInt(token[1])); } else if(token[0]=="SAMPLE_TIME"){ sampleTime=ofToFloat(token[1]); } } } config.close(); }
bool load_table(configuration &conf, const std::string &module_name, idx<intg>& table, intg thickness, intg noutputs) { std::string name = module_name; name << "_table"; // table name std::string name_in = name; name_in << "_in"; // table max input std::string name_out = name; name_out << "_out"; // table max output if (conf.exists(name)) // request to load table from file { std::string filename = conf.get_string(name.c_str()); if (!file_exists(filename)) eblerror("cannot find table file declared in variable " << name << ": " << filename); table = load_matrix<intg>(filename); eblprint("Loaded " << name << " (" << table << ") from " << filename << endl); return true; } else if (conf.exists(name_in) && conf.exists(name_out)) { intg in, out; // special case, if in == "thickness", use current thickness std::string val_in = conf.get_string(name_in); if (!val_in.compare("thickness")) in = thickness; else // regular case, use string as int in = conf.get_int(name_in.c_str()); // special case, if out == "noutputs", use current thickness std::string val_out = conf.get_string(name_out); if (!val_out.compare("noutputs")) out = noutputs; else // regular case, use string as int out = conf.get_int(name_out.c_str()); // create table table = full_table(in, out); eblprint("Using a full table for " << name << ": " << in << " -> " << out << " (" << table << ")" << std::endl); return true; } eblwarn("Failed to load table " << name << std::endl); return false; }
std::string detection_thread<T>:: get_output_directory(configuration &conf) { std::string s; if (conf.exists("output_dir")) s << conf.get_string("output_dir"); else s << conf.get_string("current_dir"); if (conf.exists("detections_dir")) s << conf.get_string("detections_dir"); else { s << "/detections"; if (conf.exists_true("nms")) s << "_" << tstamp(); } s << "/"; mkdir_full(s); return s; }
void init_speedo(void) { Millis.init(); Serial.init(USART1, 115200L); Serial.init(USART2, 115200L); Serial.init(USART3, 115200L); Serial.puts_ln(USART1, "=== Speedoino ==="); Serial.puts(USART1, GIT_REV); // print Software release Serial.puts(USART1, " HW:"); Serial.puts_ln(USART1, Config.get_hw_version()); // print Hardware release // first, set all variables to a zero value Sensors.init(); Speedo.clear_vars(); // refresh cycle // read configuration file from sd card SD.init(); // try open SD Card SD.open(); Config.read(CONFIG_FOLDER, "BASE.TXT", READ_MODE_CONFIGFILE, ""); // load base config Config.read(CONFIG_FOLDER, "SPEEDO.TXT", READ_MODE_CONFIGFILE, ""); // speedovalues, avg,max,time Config.read(CONFIG_FOLDER, "GANG.TXT", READ_MODE_CONFIGFILE, ""); // gang Config.read(CONFIG_FOLDER, "TEMPER.TXT", READ_MODE_CONFIGFILE, ""); // Temperatur Config.read_skin(); // skinning // check if read SD read was okay, if not: load your default backup values Aktors.check_vars(); // check if color of outer LED are OK Sensors.check_vars(); // check if config read was successful Speedo.check_vars(); // rettet das Skinning wenn SD_failed von den sensoren auf true gesetzt wird Sensors.single_read(); // read all sensor values once to ensure we are ready to show them Aktors.init(); // Start outer LEDs // ausschlag des zeigers // Motorausschlag und block bis motor voll ausgeschlagen, solange das letzte intro bild halten TFT.init(); // SD.prefetched_animation(37); // 37 Menu.init(); // Start butons // adds the connection between pins and vars Menu.display(); // execute this AFTER pOLED.init_speedo!! this will show the menu and, if state==11, draws speedosymbols Speedo.reset_bak(); // reset all storages, to force the redraw of the speedo Config.ram_info(); Serial.puts_ln(USART1, "=== Setup finished ==="); }
void detection_thread<T>::init_detector(detector<T> &detect, configuration &conf, std::string &odir, bool silent) { // multi-scaling parameters double maxs = conf.try_get_double("max_scale", 2.0); double mins = conf.try_get_double("min_scale", 1.0); t_scaling scaling_type = (t_scaling) conf.try_get_uint("scaling_type", SCALES_STEP); double scaling = conf.try_get_double("scaling", 1.4); std::vector<midxdim> scales; switch (scaling_type) { case MANUAL: if (!conf.exists("scales")) eblerror("expected \"scales\" variable to be defined in manual mode"); scales = string_to_midxdimvector(conf.get_cstring("scales")); detect.set_resolutions(scales); break ; case ORIGINAL: detect.set_scaling_original(); break ; case SCALES_STEP: detect.set_resolutions(scaling, maxs, mins); break ; case SCALES_STEP_UP: detect.set_resolutions(scaling, maxs, mins); detect.set_scaling_type(scaling_type); break ; default: detect.set_scaling_type(scaling_type); } // remove pads from target scales if requested if (conf.exists_true("scaling_remove_pad")) detect.set_scaling_rpad(true); // optimize memory usage by using only 2 buffers for entire flow state<T> input(1, 1, 1), output(1, 1, 1); if (!conf.exists_false("mem_optimization")) detect.set_mem_optimization(input, output, true); // TODO: always keep inputs, otherwise detection doesnt work. fix this. // conf.exists_true("save_detections") || // (display && !mindisplay)); // zero padding float hzpad = conf.try_get_float("hzpad", 0); float wzpad = conf.try_get_float("wzpad", 0); detect.set_zpads(hzpad, wzpad); if (conf.exists("input_min")) // limit inputs size detect.set_min_resolution(conf.get_uint("input_min")); if (conf.exists("input_max")) // limit inputs size detect.set_max_resolution(conf.get_uint("input_max")); if (silent) detect.set_silent(); if (conf.exists_bool("save_detections")) { std::string detdir = odir; detdir += "detections"; uint nsave = conf.try_get_uint("save_max_per_frame", 0); bool diverse = conf.exists_true("save_diverse"); detdir = detect.set_save(detdir, nsave, diverse); } detect.set_scaler_mode(conf.exists_true("scaler_mode")); if (conf.exists("bbox_decision")) detect.set_bbox_decision(conf.get_uint("bbox_decision")); if (conf.exists("bbox_scalings")) { mfidxdim scalings = string_to_fidxdimvector(conf.get_cstring("bbox_scalings")); detect.set_bbox_scalings(scalings); } // nms configuration ////////////////////////////////////////////////////// t_nms nms_type = (t_nms) conf.try_get_uint("nms", 0); float pre_threshold = conf.try_get_float("pre_threshold", 0.0); float post_threshold = conf.try_get_float("post_threshold", 0.0); float pre_hfact = conf.try_get_float("pre_hfact", 1.0); float pre_wfact = conf.try_get_float("pre_wfact", 1.0); float post_hfact = conf.try_get_float("post_hfact", 1.0); float post_wfact = conf.try_get_float("post_wfact", 1.0); float woverh = conf.try_get_float("woverh", 1.0); float max_overlap = conf.try_get_float("max_overlap", 0.0); float max_hcenter_dist = conf.try_get_float("max_hcenter_dist", 0.0); float max_wcenter_dist = conf.try_get_float("max_wcenter_dist", 0.0); float vote_max_overlap = conf.try_get_float("vote_max_overlap", 0.0); float vote_mhd = conf.try_get_float("vote_max_hcenter_dist", 0.0); float vote_mwd = conf.try_get_float("vote_max_wcenter_dist", 0.0); detect.set_nms(nms_type, pre_threshold, post_threshold, pre_hfact, pre_wfact, post_hfact, post_wfact, woverh, max_overlap, max_hcenter_dist, max_wcenter_dist, vote_max_overlap, vote_mhd, vote_mwd); if (conf.exists("raw_thresholds")) { std::string srt = conf.get_string("raw_thresholds"); std::vector<float> rt = string_to_floatvector(srt.c_str()); detect.set_raw_thresholds(rt); } if (conf.exists("outputs_threshold")) detect.set_outputs_threshold(conf.get_double("outputs_threshold"), conf.try_get_double("outputs_threshold_val", -1)); /////////////////////////////////////////////////////////////////////////// if (conf.exists("netdims")) { idxdim d = string_to_idxdim(conf.get_string("netdims")); detect.set_netdim(d); } if (conf.exists("smoothing")) { idxdim ker; if (conf.exists("smoothing_kernel")) ker = string_to_idxdim(conf.get_string("smoothing_kernel")); detect.set_smoothing(conf.get_uint("smoothing"), conf.try_get_double("smoothing_sigma", 1), &ker, conf.try_get_double("smoothing_sigma_scale", 1)); } if (conf.exists("background_name")) detect.set_bgclass(conf.get_cstring("background_name")); if (conf.exists_true("bbox_ignore_outsiders")) detect.set_ignore_outsiders(); if (conf.exists("corners_inference")) detect.set_corners_inference(conf.get_uint("corners_inference")); if (conf.exists("input_gain")) detect.set_input_gain(conf.get_double("input_gain")); if (conf.exists_true("dump_outputs")) { std::string fname; fname << odir << "/dump/detect_out"; detect.set_outputs_dumping(fname.c_str()); } }
void configuration::readGeneralConfig(string cfgFile){ cout << ofToDataPath(cfgFile) << endl; ifstream config(ofToDataPath(cfgFile).c_str()); while (config.peek()!=EOF) { string nextLine; getline(config, nextLine); vector<string> token=ofSplitString(nextLine, "="); if(token.size()){ cout << token[0] << endl; if(token[0]=="MCU") mcu=token[1]; else if(token[0]=="TRANSFER_RATE") baud=token[1]; else if(token[0]=="PROGRAMMER") programmer=token[1]; else if(token[0]=="F_CPU"){ if(token[1]=="16M") freq="16000000L"; else if(token[1]=="8M") freq="8000000L"; else if(token[1]=="20M") freq="20000000L"; else freq=token[1]; } else if(token[0]=="BOARD"){ if(token[1]=="UNO") mcu="atmega328p", programmer="arduino", freq="16000000L",baud="115200"; else if(token[1]=="DUEM") mcu="atmega328p", programmer="arduino", freq="16000000L",baud="57600"; else if(token[1]=="PEAPOD") mcu="attiny85", programmer="usbtiny", freq="8000000L",baud=""; } else if(token[0]=="EXCLUDE_PORT"){ excludedPort.push_back(token[1]); if(verbose) cout << "Port " << token[1] << " will not be used to program."<<endl; } else if(token[0]=="INSTALL_DIR"){ rootDir=ofToDataPath(token[1]); toolDir=rootDir+"hardware/tools/avr/bin/"; } else if(token[0]=="PERIPHERAL"){ addonLib=ofToDataPath(token[1]); } else if(token[0]=="VERBOSE"){ verbose=ofToInt(token[1]); } else if(token[0]=="TIMEOUT"){ timeout=ofToInt(token[1]); cout << "timeout is " << timeout/1000 << "seconds" << endl; } else if(token[0]=="ROBOT"){ if(verbose) cout << token[1] << " is the current robot configuration." << endl; robotRoot=ofToDataPath("robots/"+token[1]); } else if(token[0]=="TEST_AVAILABLE"){ test=ofToInt(token[1]); } else if(token[0]=="SCROLL_SCREEN"){ scroll=ofToInt(token[1]); } else if(token[0]=="PORTRAIT_MODE"){ portraitMode=ofToInt(token[1]); //ofSetWindowShape(ofGetScreenWidth(),ofGetScreenHeight()); } else if(token[0]=="NEW_USER_BUTTON"){ if(token[1].length()>1){ drawNewUser=true; //newUser.setTextSize(ofToInt(token[1])); newUser.setup(token[1],buttonFontSize); } else drawNewUser=false; } else if(token[0]=="WRAPPER"){ wrapperFile=token[1]; } else if(token[0]=="BLOCK_FONT_SIZE"){ blockFontSize=ofToInt(token[1]); } else if(token[0]=="BUTTON_FONT_SIZE"){ buttonFontSize=ofToInt(token[1]); } else if(token[0]=="UPLOADED_MESSAGE"){ uploadedMessage=token[1]; } else if(token[0]=="CONNECT_MESSAGE"){ connectMessage=token[1]; } else if(token[0]=="DISCONNECT_MESSAGE"){ disconnectMsg=token[1]; } else if(token[0]=="DEMO_MESSAGE"){ demoMsg=token[1]; } else if(token[0]=="CREATE_MESSAGE"){ createMsg=token[1]; } else if(token[0]=="EDIT_MESSAGE"){ editMsg=token[1]; } else if(token[0]=="CLEAR_MESSAGE"){ clearMsg=token[1]; } else if(token[0]=="BOARD_DETECT"){ boardDetect=ofToInt(token[1]); } else if(token[0]=="LEVEL_FOLDER"){ levelFolders.push_back(token[1]); } else if(token[0]=="ABS_SAVE_DIR"){ programDir=token[1]; if(verbose) cout << "The directory to which programs are saved is " << programDir <<endl; } else if(token[0]=="SAVED_PROGRAM_DIR"){ programDir=ofToDataPath(token[1]); } else if(token[0]=="SAVE_PROGRAMS"){ savePrograms=ofToInt(token[1]); } else if(token[0]=="FULLSCREEN"){ ofSetFullscreen(ofToInt(token[1])); } else if(token[0]=="TITLE_BAR_SIZE"){ titleBarSize=ofToInt(token[1]); if(titleBarSize) showTitle=true; } else if(token[0]=="DEMO_AVAILABLE"){ demoAvailable=ofToInt(token[1]); } else if(token[0]=="CONTROL_BAR_COLOR"){ controlBarColor=ofColor(strtol(token[1].c_str(),NULL,0)); controlBarColor.a=255; } else if(token[0]=="BG_COLOR"){ backgroundColor=ofColor(strtol(token[1].c_str(),NULL,0)); backgroundColor.a=255; } else if(token[0]=="SIDE_BAR_COLOR"){ sideBarColor=ofColor(strtol(token[1].c_str(),NULL,0)); sideBarColor.a=255; } else if(token[0]=="LINE_COLOR"){ lineColor=ofColor(strtol(token[1].c_str(),NULL,0)); lineColor.a=255; } else if(token[0]=="TEXT_COLOR"){ textColor=ofColor(strtol(token[1].c_str(),NULL,0)); textColor.a=255; } else if(token[0]=="SUBTITLE_COLOR"){ subtitleColor=ofColor::fromHex(strtol(token[1].c_str(),NULL,0)); cout << subtitleColor << endl; subtitleColor.a=255; } else if(token[0]=="DEFAULT_COLORS"){ defaultColor=ofToInt(token[1]); } else if(token[0]=="BUTTONS_ON_SIDEBAR"){ buttonsOnSidebar=ofToInt(token[1]); } else if(token[0]=="SAVE_NOT_UNDO"){ saveNotUndo=ofToInt(token[1]); } } } config.close(); if(!wrapperFile.length()) wrapperFile = robotRoot+"/wrapper.wrp"; }
void test_and_save(uint iter, configuration &conf, string &conffname, parameter<Tnet> &theparam, supervised_trainer<Tnet,Tdata,Tlabel> &thetrainer, labeled_datasource<Tnet,Tdata,Tlabel> &train_ds, labeled_datasource<Tnet,Tdata,Tlabel> &test_ds, classifier_meter &trainmeter, classifier_meter &testmeter, infer_param &infp, gd_param &gdp, string &shortname) { timer ttest; ostringstream wname, wfname; // // some code to average several random solutions // cout << "Testing..."; // if (original_tests > 1) cout << " (" << original_tests << " times)"; // cout << endl; // ttest.restart(); // for (uint i = 0; i < original_tests; ++i) { // if (test_only && original_tests > 1) { // // we obviously wanna test several random solutions // cout << "Initializing weights from random." << endl; // thenet.forget(fgp); // } // if (!no_training_test) // thetrainer.test(train_ds, trainmeter, infp); // thetrainer.test(test_ds, testmeter, infp); // cout << "testing_time="; ttest.pretty_elapsed(); cout << endl; // } // if (test_only && original_tests > 1) { // // display averages over all tests // testmeter.display_average(test_ds.name(), test_ds.lblstr, // test_ds.is_test()); // trainmeter.display_average(train_ds.name(), train_ds.lblstr, // train_ds.is_test()); // } cout << "Testing..." << endl; uint maxtest = conf.exists("max_testing") ? conf.get_uint("max_testing") :0; ttest.start(); if (!conf.exists_true("no_training_test")) thetrainer.test(train_ds, trainmeter, infp, maxtest); // test if (!conf.exists_true("no_testing_test")) thetrainer.test(test_ds, testmeter, infp, maxtest); // test cout << "testing_time="; ttest.pretty_elapsed(); cout << endl; // save samples picking statistics if (conf.exists_true("save_pickings")) { string fname; fname << "pickings_" << iter; train_ds.save_pickings(fname.c_str()); } // save weights and confusion matrix for test set wname.str(""); if (conf.exists("job_name")) wname << conf.get_string("job_name"); wname << "_net" << setfill('0') << setw(5) << iter; wfname.str(""); wfname << wname.str() << ".mat"; if (conf.exists_false("save_weights")) cout << "Not saving weights (save_weights set to 0)." << endl; else { cout << "saving net to " << wfname.str() << endl; theparam.save_x(wfname.str().c_str()); // save trained network cout << "saved=" << wfname.str() << endl; } // detection test if (conf.exists_true("detection_test")) { uint dt_nthreads = 1; if (conf.exists("detection_test_nthreads")) dt_nthreads = conf.get_uint("detection_test_nthreads"); timer dtest; dtest.start(); // copy config file and augment it and detect it string cmd, params; if (conf.exists("detection_params")) { params = conf.get_string("detection_params"); params = string_replaceall(params, "\\n", "\n"); } cmd << "cp " << conffname << " tmp.conf && echo \"silent=1\n" << "nthreads=" << dt_nthreads << "\nevaluate=1\nweights_file=" << wfname.str() << "\n" << params << "\" >> tmp.conf && detect tmp.conf"; if (std::system(cmd.c_str())) cerr << "warning: failed to execute: " << cmd << endl; cout << "detection_test_time="; dtest.pretty_elapsed(); cout << endl; } // set retrain to next iteration with current saved weights ostringstream progress; progress << "retrain_iteration = " << iter + 1 << endl << "retrain_weights = " << wfname.str() << endl; // save progress job::write_progress(iter + 1, conf.get_uint("iterations"), progress.str().c_str()); // save confusion if (conf.exists_true("save_confusion")) { string fname; fname << wname.str() << "_confusion_test.mat"; cout << "saving confusion to " << fname << endl; save_matrix(testmeter.get_confusion(), fname.c_str()); } #ifdef __GUI__ // display static supervised_trainer_gui<Tnet,Tdata,Tlabel> stgui(shortname.c_str()); static supervised_trainer_gui<Tnet,Tdata,Tlabel> stgui2(shortname.c_str()); bool display = conf.exists_true("show_train"); // enable/disable display uint ninternals = conf.exists("show_train_ninternals") ? conf.get_uint("show_train_ninternals") : 1; // # examples' to display bool show_train_errors = conf.exists_true("show_train_errors"); bool show_train_correct = conf.exists_true("show_train_correct"); bool show_val_errors = conf.exists_true("show_val_errors"); bool show_val_correct = conf.exists_true("show_val_correct"); bool show_raw_outputs = conf.exists_true("show_raw_outputs"); bool show_all_jitter = conf.exists_true("show_all_jitter"); uint hsample = conf.exists("show_hsample") ?conf.get_uint("show_hsample"):5; uint wsample = conf.exists("show_wsample") ?conf.get_uint("show_wsample"):5; if (display) { cout << "Displaying training..." << endl; if (show_train_errors) { stgui2.display_correctness(true, true, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui2.display_correctness(true, false, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } if (show_train_correct) { stgui2.display_correctness(false, true, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui2.display_correctness(false, false, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } if (show_val_errors) { stgui.display_correctness(true, true, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui.display_correctness(true, false, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } if (show_val_correct) { stgui.display_correctness(false, true, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui.display_correctness(false, false, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } stgui.display_internals(thetrainer, test_ds, infp, gdp, ninternals); } #endif }
/// Construct object /// \param config A configuration object from which the deflector will extract /// all relevant settings explicit settings(const configuration& config) { _opening_angle = config.get_deflection_engine_property("opening_angle", 1.0); }
::dcs::shared_ptr< ::dcs::math::random::base_generator<UIntT> > make_random_number_generator(configuration<RealT,UIntT> const& conf) { typedef RealT real_type; typedef UIntT uint_type; typedef ::dcs::math::random::base_generator<uint_type> rng_type; rng_engine_category engine_category = conf.rng().engine; rng_seeder_category seeder_category = conf.rng().seeder; uint_type seed = conf.rng().seed; ::dcs::shared_ptr<rng_type> ptr_rng; switch (engine_category) { case minstd_rand0_rng_engine: { typedef ::dcs::math::random::uniform_int_adaptor< ::dcs::math::random::minstd_rand0, uint_type > rng_impl_type; ptr_rng = ::dcs::make_shared<rng_impl_type>(); // ptr_rng = ::dcs::shared_ptr<rng_type>(new rng_impl_type()); } break; case minstd_rand1_rng_engine: { typedef ::dcs::math::random::uniform_int_adaptor< ::dcs::math::random::minstd_rand1, uint_type > rng_impl_type; ptr_rng = ::dcs::make_shared<rng_impl_type>(); // ptr_rng = ::dcs::shared_ptr<rng_type>(new rng_impl_type()); } break; case minstd_rand2_rng_engine: { typedef ::dcs::math::random::uniform_int_adaptor< ::dcs::math::random::minstd_rand2, uint_type > rng_impl_type; ptr_rng = ::dcs::make_shared<rng_impl_type>(); // ptr_rng = ::dcs::shared_ptr<rng_type>(new rng_impl_type()); } break; case rand48_rng_engine: { typedef ::dcs::math::random::uniform_int_adaptor< ::dcs::math::random::rand48, uint_type > rng_impl_type; ptr_rng = ::dcs::make_shared<rng_impl_type>(); // ptr_rng = ::dcs::shared_ptr<rng_type>(new rng_impl_type()); } break; case mt11213b_rng_engine: { typedef ::dcs::math::random::uniform_int_adaptor< ::dcs::math::random::mt11213b, uint_type > rng_impl_type; ptr_rng = ::dcs::make_shared<rng_impl_type>(); // ptr_rng = ::dcs::shared_ptr<rng_type>(new rng_impl_type()); } break; case mt19937_rng_engine: { typedef ::dcs::math::random::uniform_int_adaptor< ::dcs::math::random::mt19937, uint_type > rng_impl_type; ptr_rng = ::dcs::make_shared<rng_impl_type>(); // ptr_rng = ::dcs::shared_ptr<rng_type>(new rng_impl_type()); } break; default: throw ::std::runtime_error("[dcs::des::cloud::config::make_random_number_generator] Unhandled random number generator category."); } ptr_rng->seed(seed); return ptr_rng; }
::dcs::shared_ptr< ::dcs::des::engine<RealT> > make_des_engine(configuration<RealT,UIntT> const& conf) { typedef RealT real_type; typedef UIntT uint_type; typedef ::dcs::des::engine<real_type> engine_type; ::dcs::shared_ptr<engine_type> ptr_eng; switch (conf.simulation().output_analysis.category) { case independent_replications_output_analysis: { typedef independent_replications_output_analysis_config<real_type,uint_type> output_analysis_config_type; typedef ::dcs::des::replications::engine<real_type,uint_type> engine_impl_type; output_analysis_config_type const& analysis = ::boost::get<output_analysis_config_type>(conf.simulation().output_analysis.category_conf); real_type min_replication_size(0); uint_type min_num_replications(0); switch (analysis.num_replications_category) { case constant_num_replications_detector: { typedef typename output_analysis_config_type::constant_num_replications_detector_type num_replications_detector_config_type; num_replications_detector_config_type const& num_replications_detector_conf = ::boost::get<num_replications_detector_config_type>(analysis.num_replications_category_conf); min_num_replications = num_replications_detector_conf.num_replications; } break; case banks2005_num_replications_detector: { typedef typename output_analysis_config_type::banks2005_num_replications_detector_type num_replications_detector_config_type; num_replications_detector_config_type const& num_replications_detector_conf = ::boost::get<num_replications_detector_config_type>(analysis.num_replications_category_conf); min_num_replications = num_replications_detector_conf.min_num_replications; } break; } switch (analysis.replication_size_category) { case fixed_duration_replication_size_detector: { typedef typename output_analysis_config_type::fixed_duration_replication_size_detector_type replication_size_detector_config_type; replication_size_detector_config_type const& replication_size_detector_conf = ::boost::get<replication_size_detector_config_type>(analysis.replication_size_category_conf); min_replication_size = replication_size_detector_conf.replication_duration; } break; case fixed_num_obs_replication_size_detector: { typedef typename output_analysis_config_type::fixed_num_obs_replication_size_detector_type replication_size_detector_config_type; //replication_size_detector_config_type const& replication_size_detector_conf = ::boost::get<replication_size_detector_config_type>(analysis.replication_size_category_conf); //min_replication_size = ::dcs::math::constants::infinity<uint_type>::value; min_replication_size = uint_type(1); } break; } ptr_eng = ::dcs::make_shared<engine_impl_type>( min_replication_size, min_num_replications ); } break; default: throw ::std::runtime_error("[dcs::des::cloud::config::make_des_engine] Unhandled output analysis category."); } return ptr_eng; }
void server::configure_port(const configuration &conf) { _port = boost::lexical_cast<unsigned short int>(conf.get_value("server/port")); }
void load_gd_param(configuration &conf, gd_param &gdp) { // mandatory learning parameters gdp.eta = conf.get_double("eta"); // optional learning parameters if (conf.exists("reg_time")) gdp.decay_time = conf.get_intg("reg_time"); if (conf.exists("reg_l1")) gdp.decay_l1 = conf.get_double("reg_l1"); if (conf.exists("reg_l2")) gdp.decay_l2 = conf.get_double("reg_l2"); if (conf.exists("inertia")) gdp.inertia = conf.get_double("inertia"); if (conf.exists("anneal_value")) gdp.anneal_value = conf.get_double("anneal_value"); if (conf.exists("anneal_period")) gdp.anneal_period = conf.get_intg("anneal_period"); if (conf.exists("gradient_threshold")) gdp.gradient_threshold = conf.get_double("gradient_threshold"); // printing parameters eblprint(gdp << std::endl); }