Comrade::Osiris::FastSOM_Neuron::FastSOM_Neuron(int num_ip) { num_inputs=num_ip; weight_vector.resize(num_inputs,0); input_vector.resize(num_inputs,0); set_activation_function(Comrade::Osiris::unipolar_hardlimiting); }
void model::readConfig(ifstream &config_file) { string line; vector<string> fields; int ngram_size, vocab_size, input_embedding_dimension, num_hidden, output_embedding_dimension; activation_function_type activation_function = this->activation_function; while (getline(config_file, line) && line != "") { splitBySpace(line, fields); if (fields[0] == "ngram_size") ngram_size = lexical_cast<int>(fields[1]); else if (fields[0] == "vocab_size") input_vocab_size = output_vocab_size = lexical_cast<int>(fields[1]); else if (fields[0] == "input_vocab_size") input_vocab_size = lexical_cast<int>(fields[1]); else if (fields[0] == "output_vocab_size") output_vocab_size = lexical_cast<int>(fields[1]); else if (fields[0] == "input_embedding_dimension") input_embedding_dimension = lexical_cast<int>(fields[1]); else if (fields[0] == "num_hidden") num_hidden = lexical_cast<int>(fields[1]); else if (fields[0] == "output_embedding_dimension") output_embedding_dimension = lexical_cast<int>(fields[1]); else if (fields[0] == "activation_function") activation_function = string_to_activation_function(fields[1]); else if (fields[0] == "version") { int version = lexical_cast<int>(fields[1]); if (version != 1) { cerr << "error: file format mismatch (expected 1, found " << version << ")" << endl; exit(1); } } else cerr << "warning: unrecognized field in config: " << fields[0] << endl; } resize(ngram_size, input_vocab_size, output_vocab_size, input_embedding_dimension, num_hidden, output_embedding_dimension); set_activation_function(activation_function); }
void ann::set_output_activation_function(int activation_function) { set_activation_function(activation_function, LAYER_OUTPUT); }
void ann::set_hidden_activation_function(int activation_function) { set_activation_function(activation_function, LAYER_HIDDEN); }
void ann::set_input_activation_function(int activation_function) { set_activation_function(activation_function, LAYER_INPUT); }
void Perceptron::load(const char* filename) { std::fstream file; file.open(filename, std::ios::in); if(!file.is_open()) { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Cannot open perceptron XML-type file." << std::endl; exit(1); } std::string line; std::string word; // Declaration getline(file, line); if(line != "<Flood version='3.0' class='Perceptron'>") { // std::cerr << "Flood Error: Perceptron class." << std::endl // << "void load(const char*) method." << std::endl // << "Unknown file declaration: " << line << std::endl; // // exit(1); } // Number of inputs file >> word; if(word != "<InputsNumber>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown inputs number begin tag: " << line << std::endl; exit(1); } int new_inputs_number; file >> new_inputs_number; set_inputs_number(new_inputs_number); file >> word; if(word != "</InputsNumber>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown inputs number end tag: " << line << std::endl; exit(1); } // Activation function file >> word; if(word != "<ActivationFunction>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown activation function begin tag: " << line << std::endl; exit(1); } std::string new_activation_function_name; file >> new_activation_function_name; set_activation_function(new_activation_function_name); file >> word; if(word != "</ActivationFunction>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown activation function end tag: " << line << std::endl; exit(1); } // Bias file >> word; if(word != "<Bias>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown bias begin tag: " << line << std::endl; exit(1); } double new_bias; file >> new_bias; set_bias(new_bias); file >> word; if(word != "</Bias>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown bias end tag: " << line << std::endl; exit(1); } // Synaptic weights file >> word; if(word != "<SynapticWeights>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown synaptic weights begin tag: " << line << std::endl; exit(1); } Vector<double> new_synaptic_weights(inputs_number); file >> new_synaptic_weights; set_synaptic_weights(new_synaptic_weights); file >> word; if(word != "</SynapticWeights>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown synaptic weights end tag: " << line << std::endl; exit(1); } // Display file >> word; if(word != "<Display>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown display begin tag: " << line << std::endl; exit(1); } bool new_display; file >> new_display; set_display(new_display); file >> word; if(word != "</Display>") { std::cerr << "Flood Error: Perceptron class." << std::endl << "void load(const char*) method." << std::endl << "Unknown display end tag: " << line << std::endl; exit(1); } file.close(); }