bool Learning::run() { Config config; config.addDef(LCONF_MODE, LCONF_MODE_BATCH); config.addDef(LCONF_KIFU, ""); config.addDef(LCONF_DEPTH, "3"); config.addDef(LCONF_THREADS, "1"); config.addDef(LCONF_ITERATION, "10"); // 設定読み込み if (!config.read(CONFPATH)) { return false; } Loggers::message << config.toString(); if (config.getString(LCONF_MODE) == LCONF_MODE_BATCH) { BatchLearning learning(config); learning.run(); } else if (config.getString(LCONF_MODE) == LCONF_MODE_ONLINE) { OnlineLearning learning(config); learning.run(); } else { Loggers::error << "Invalid learning mode [" << config.getString(LCONF_MODE) << "]"; return false; } return true; }
void solve() { // TODO if(!check()) { ; } auto local_parser = [] (const string & line) { return paracel::str_split(line, ','); }; auto f_parser = paracel::gen_parser(local_parser); pt->paracel_load_as_graph(bi_G, bigraph_input, f_parser); // load and init score, pl, pr vector<string> linelst; try { linelst = pt->paracel_loadall(dis_input); } catch (const std::runtime_error & e) { std::cerr << e.what(); abort(); } for(auto & line : linelst) { auto lst = paracel::str_split(line, ','); string key = lst[0]; double value = std::stod(lst[1]); score[key] = value; if(paracel::endswith(lst[0], "L")) { pl[key] = value; } else { // paracel::endswith(lst[0], 'R') pr[key] = value; } } // train model learning(); for(auto & kv : score) { if(paracel::endswith(kv.first, "R")) { score_new[kv.first] = kv.second; } } // calculate transfer prob matrix for(auto & kv_outside : pl) { vector<std::pair<string, double> > ktop_lst_tmp; auto i = kv_outside.first; for(auto & kv_inside : pr) { auto j = kv_inside.first; double prob = trans_prob(i, j); if(prob > 0.) { // save mem ktop_lst_tmp.push_back(std::make_pair(j.substr(0, j.size() - 1), prob)); } } std::sort(ktop_lst_tmp.begin(), ktop_lst_tmp.end(), [] (std::pair<string, double> a, std::pair<string, double> b) { return a.second > b.second; }); if((int)ktop_lst_tmp.size() >= ktop) { ktop_lst_tmp.resize(ktop); } if(ktop_lst_tmp.size() > 1e-10) { transfer_prob_mtx[i.substr(0, i.size() - 1)] = ktop_lst_tmp; } } // for }
int AILearner::generateMove(int board[8][8],int type){ simulate.setBoard(board); int ansi = -1, ansj; static int temp[8][8]; double maxScore; for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ if(!simulate.canPut(i,j,type)) continue; simulate.putChess(i,j,type); simulate.getBoard(temp); double get = evaluate(temp,type); if(get>maxScore||ansi==-1){ ansi = i; ansj = j; maxScore = get; } simulate.setBoard(board); } } //printf("%.18f\n",maxScore); learning(lastCharacteristic[type-1],maxScore,type); simulate.putChess(ansi,ansj,type); simulate.getBoard(temp); encode(temp,lastCharacteristic[type-1]); return ansi<<3|ansj; }
void Mlp::run(std::vector< std::vector<double> >* examples_features, std::vector< std::vector<double> >* tests_features, int neurones_caches, double learning_err) { int errors; double time; // Create perceptron create(neurones_caches, examples_features->at(0).size()); // Start timer time_t seconds; seconds = clock(); // Learning std::cout << "Learning with " << neurones_caches << " neurons and acceptance error of " << learning_err << " ..." << std::endl; learning(examples_features, learning_err); // Time calculation time = ((double) (clock() - seconds) / CLOCKS_PER_SEC); // Test errors = test(tests_features); // write_results(neurones_caches, learning_err, time, errors); std::cout << " -> " << errors << " % errors in a learning time of " << time << "s" << std::endl; }
void GameOfLife::run() { while ( true ) { QThread::msleep ( m_delay ); if ( !paused ) { ++m_time; development(); learning(); latticeIndex = ( latticeIndex+1 ) %2; emit cellsChanged ( lattices[latticeIndex], predictions ); } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , dir_weight_("0") , step_(0) , stop_learning_(false) { ui->setupUi(this); connect(ui->learn, SIGNAL(clicked()), SLOT(learning())); connect(ui->load, SIGNAL(clicked()), SLOT(load_img())); connect(ui->open, SIGNAL(clicked()), SLOT(open())); connect(ui->close, SIGNAL(clicked()), SLOT(close())); connect(ui->save, SIGNAL(clicked()), SLOT(save())); ui->textEdit->setReadOnly(true); ui->load->setDisabled(true); connect(this, SIGNAL(ready_result(QString)),SLOT(print_result(QString))); }
void GameOfLife::run() { while ( true ) { QThread::msleep ( m_delay ); if ( !paused ) { ++m_time; development(); learning(); latticeIndex = ( latticeIndex+1 ) %2; emit cellsChanged ( lattices[latticeIndex], predictions ); ++m_frame_num; { QMutexLocker lck(m_mutex); if(m_stopped) break; } } } }
virtual void solve() { auto lines = paracel_load(input); local_parser(item_vects, lines); std::cout << "parser done" << std::endl; if(learning_method == "default") { auto all_lines = paracel_loadall(input); local_parser(all_item_vects, all_lines); std::cout << "loadall done" << std::endl; normalize(item_vects); normalize(all_item_vects); std::cout << "normalize done" << std::endl; sync(); learning(); } else if(learning_method == "limit_storage") { normalize(item_vects); // normalize here to reduce calculation init_paras(); sync(); mls_learning(); } else {} }
void solve() { auto lines = pt->paracel_load(input); init_data(lines); learning(); translating(); }
void solve() { load(); learning(); }
//****************************************对抽取的语料库按类别进行分类**************************************** void corpus_category(string filename_path, string path_read, string path_write) //参数1:文件名列表路径 参数2:读取文件的目录 参数3:写入文件的目录 { string file_name; //存储读取的各个文件的名字 ifstream read_filename(filename_path); //从LIST.TXT读取文件名 ofstream sports(path_write+"sports.txt");//属于sport类的存放在sport.txt文件中 ofstream house(path_write+"house.txt"); ofstream it(path_write+"it.txt"); ofstream test_2008(path_write+"2008.txt"); ofstream news(path_write+"news.txt"); ofstream yule(path_write+"yule.txt"); ofstream business(path_write+"business.txt"); ofstream travel(path_write+"travel.txt"); ofstream mil_news(path_write+"mil.news.txt"); ofstream women(path_write+"women.txt"); ofstream health(path_write+"health.txt"); ofstream test_auto(path_write+"auto.txt"); ofstream cul(path_write+"cul.txt"); ofstream learning(path_write+"learning.txt"); ofstream test_else(path_write+"else.txt"); string path_in, str_line,cut_str;//path_in:存放读文件路径 str_line:读取的一行文件 cut_str:存放截取的字符串 string::size_type pos1, pos2; int number = 0; while (getline(read_filename, file_name)) { number++; cout << number << endl; path_in = path_read + file_name; ifstream infile(path_in); while (getline(infile, str_line)) //读取各个文件的每一行字符串 { pos1 = 0; pos2 = str_line.find("####"); cut_str = str_line.substr(pos1, pos2 - pos1); if (string(cut_str) == string("sports")) //字符串匹配 是否为sports类 { sports << str_line << endl; //如果是sports类就把该行输出到sports.txt文件 } else if (cut_str == "house") { house << str_line << endl; } else if (cut_str == "it") { it << str_line << endl; } else if (cut_str == "2008") { test_2008 << str_line << endl; } else if (cut_str == "news") { news << str_line << endl; } else if (cut_str == "yule") { yule << str_line << endl; } else if (cut_str == "business") { business << str_line << endl; } else if (cut_str == "travel") { travel << str_line << endl; } else if (cut_str == "mil.news") { mil_news << str_line << endl; } else if (cut_str == "women") { women << str_line << endl; } else if (cut_str == "health") { health << str_line << endl; } else if (cut_str == "auto") { test_auto << str_line << endl; } else if (cut_str == "cul") { cul << str_line << endl; } else if (cut_str == "learning") { learning << str_line << endl; } else { test_else << str_line << endl; } } infile.close(); //每次结束都得关闭文件. } }
void solve() { auto lines = pt->paracel_load(input); local_parser(lines); learning(); }
void solve() { init_paras(); paracel_sync(); learning(); }