void Config::init(string path, SoftMax &SMR) { m_configStr = read_2_string(path); deleteComment(); deleteSpace(); get_layers_config(m_configStr,SMR); use_log = get_word_bool(m_configStr, "USE_LOG"); batch_size = get_word_int(m_configStr, "BATCH_SIZE"); non_linearity = get_word_type(m_configStr, "NON_LINEARITY"); training_epochs = get_word_int(m_configStr, "TRAINING_EPOCHS"); lrate_w = get_word_float(m_configStr, "LRATE_W"); lrate_b = get_word_float(m_configStr, "LRATE_B"); iter_per_epo = get_word_int(m_configStr, "ITER_PER_EPO"); ngram = get_word_int(m_configStr, "NGRAM"); training_percent = get_word_float(m_configStr, "TRAINING_PERCENT"); cout << "****************************************************************************" << endl << "** READ CONFIG FILE COMPLETE " << endl << "****************************************************************************" << endl << endl; for (int i = 0; i < HiddenConfigs.size(); i++) { cout << "***** hidden layer: " << i << " *****" << endl; cout << "NumHiddenNeurons = " << HiddenConfigs[i].get_NeuronNum() << endl; cout << "WeightDecay = " << HiddenConfigs[i].get_WeightDecay() << endl; cout << "DropoutRate = " << HiddenConfigs[i].get_DropoutRate() << endl << endl; } cout << "***** softmax layer: *****" << endl; // cout<<"NumClasses = "<<softmaxConfig.NumClasses<<endl; cout << "WeightDecay = " << SMR.get_WeightDecay() << endl << endl; cout << "***** general config *****" << endl; cout << "use_log = " << use_log << endl; cout << "batch size = " << batch_size << endl; cout << "non-linearity method = " << non_linearity << endl; cout << "training epochs = " << training_epochs << endl; cout << "learning rate for weight matrices = " << lrate_w << endl; cout << "learning rate for bias = " << lrate_b << endl; cout << "iteration per epoch = " << iter_per_epo << endl; cout << "ngram = " << ngram << endl; cout << "training percent = " << training_percent << endl; cout << endl; }
void Memory::initialize(const std::string & str) { std::ifstream ifs(str); std::string s; if (ifs.fail()) { std::cerr << str + " does not exist." << std::endl; exit(0); } int i = 0; while(std::getline(ifs, s)) { s = deleteSpace(s); s = deleteComment(s); if (s.size() == 0) { continue; } memory[i] = s; i++; } int size = memory.size(); for (; i < size; i++) { memory[i] = "0000000000000000"; } }
bool Scanner::scan() { deleteComment(); tokens.clear(); int line = 1; bool success = true; index = 0; Types type; string str; DFAState state = START; char ch; while(1) { if (state == START)//初始状态,空格 { str = ""; ch = getNext(); if (ch == '\0') break; if (ch == '\n') line++; state = getstate(ch); if (state != START && (state != DFACHAR) && (state != DFASTR)) str += ch; } else if(state == DFANUM) { if (ch == '-') { ch = getNext(); if (ch < '0' || ch > '9') { state = DONE; getBack(); state = SYM; } else { getBack(); } } else { bool isdouble = false; while(1) { ch = getNext(); if (ch == '\0') return false; state = getstate(ch); if (state != DFANUM) { if (ch == '.'&& !isdouble) { isdouble = true; str += ch; } else { if (state == DFAID) { type = ERROR; str += ch; break; } getBack(); state = DONE; type = NUM; break; } } else str += ch; } } } else if (state == DFACHAR) { bool isstr = false; while(!isstr) { ch = getNext(); if (ch != '\'') { if (ch == '\n') { cout <<line<<":"<<"缺少单引号!"<< endl; success = false; getBack(); state = START; break; } if (ch == '\0') { cout <<line<<":"<<"缺少单引号!"<< endl; return false; } str+=ch; } else { if (str.length() > 1) { cout <<line<<":"<<"Char长度非法!"<< endl; success = false; state = START; break; } isstr = true; type = STR; state = DONE; } } } else if (state == DFASTR) { bool isstr = false; while(!isstr) { ch = getNext(); if (ch != '\"') { if (ch == '\n') { cout <<line<<":"<<"缺少双引号!"<< endl; success = false; getBack(); state = START; break; } if (ch == '\0') { cout <<line<<":"<<"缺少双引号!"<< endl; return false; } char temp = getNext(); if (ch == '\\' && temp == 'n') str += 10; else { getBack(); str+=ch; } } else { isstr = true; type = STR; state = DONE; } } } else if (state == DFAID) { while(1) { ch = getNext(); if (ch == '\0') return false; state = getstate(ch); if (state != DFAID && state != DFANUM || ch == '-') { getBack(); state = DONE; break; } else str += ch; } } else if (state == SYM) { char temp = ch; ch = getNext(); if (ch == '\0') return false; else if (ch == '=') str += ch; else if ((ch == '+' && temp == '+')||(ch == '-' && temp == '-')) str += ch; else getBack(); state = DONE; } else if (state == DONE) { Token temp; if (type == ERROR) { cout <<line<<":"<< "非法变量!"<< endl; success =false; } else if (type == NUM||type == STR) { temp.type = type; temp.value = str; temp.linenode = line; tokens.push_back(temp); } else { temp.type = getType(str); if (temp.type == ERROR) { cout <<line<<":"<< "字符无法识别!"<< endl; success = false; } else { if (temp.type == ID) temp.value = str; temp.linenode = line; tokens.push_back(temp); } } state = START; type = ELSE; } } // this->success = success; for (int i = 0;i < tokens.size();i++) { if (tokens[i].type == ID && i + 1 < tokens.size() && tokens[i+1].type == LMBRACKET) { tokens[i].type = ARRAY; } } return success; }