bool SpikingGroup::write_to_file(const char * filename) { if ( !evolve_locally() ) return true; ofstream outfile; outfile.open(filename,ios::out); if (!outfile) { cerr << "Can't open output file " << filename << endl; throw AurynOpenFileException(); } outfile << "# Auryn SpikingGroup state file for n="<< get_rank_size() <<" neurons (ver. " << VERSION << ")" << endl; outfile << "# Field order: "; for ( map<string,gsl_vector_float *>::const_iterator iter = state_vector.begin() ; iter != state_vector.end() ; ++iter ) { outfile << scientific << iter->first << " "; } outfile << "(plus traces)"; outfile << endl; boost::archive::text_oarchive oa(outfile); oa << *(delay); outfile << endl; for ( NeuronID i = 0 ; i < get_rank_size() ; ++i ) { outfile << get_output_line(i); } outfile.close(); return true; }
bool SpikingGroup::load_from_file(const char * filename) { if ( !evolve_locally() ) return true; stringstream oss; oss << "Loading SpikingGroup from " << filename; logger->msg(oss.str(),NOTIFICATION); ifstream infile (filename); if (!infile) { stringstream oes; oes << "Can't open input file " << filename; logger->msg(oes.str(),ERROR); throw AurynOpenFileException(); } NeuronID count = 0; char buffer[1024]; infile.getline (buffer,1024); // skipping header TODO once could make this logic a bit smarter infile.getline (buffer,1024); // skipping header boost::archive::text_iarchive ia(infile); ia >> *delay; infile.getline (buffer,1024); // jumpting to next line while ( infile.getline (buffer,1024) ) { load_input_line(count,buffer); count++; } if ( get_rank_size() != count ) { // issue warning stringstream oes; oes << "SpikingGroup:: NeuronState file corrupted. Read " << count << " entries, but " << get_rank_size() << " expected in " << filename; logger->msg(oes.str(),WARNING); } infile.close(); return true; }
bool RateModulatedConnection::write_to_file(string filename) { stringstream oss; oss << filename << ".cstate"; ofstream outfile; outfile.open(oss.str().c_str(),ios::out); if (!outfile) { cerr << "Can't open output file " << filename << endl; throw AurynOpenFileException(); } boost::archive::text_oarchive oa(outfile); oa << rate_estimate ; oa << rate_modulation_mul ; outfile.close(); return SparseConnection::write_to_file(filename); }
bool RateModulatedConnection::load_from_file(string filename) { stringstream oss; oss << filename << ".cstate"; ifstream infile (oss.str().c_str()); if (!infile) { stringstream oes; oes << "Can't open input file " << filename; logger->msg(oes.str(),ERROR); throw AurynOpenFileException(); } boost::archive::text_iarchive ia(infile); ia >> rate_estimate; ia >> rate_modulation_mul; infile.close(); return SparseConnection::load_from_file(filename); }
void StimulusGroup::load_patterns( string filename ) { ifstream fin (filename.c_str()); if (!fin) { stringstream oss; oss << "StimulusGroup:: " << "There was a problem opening file " << filename << " for reading." << endl; logger->msg(oss.str(),ERROR); throw AurynOpenFileException(); } char buffer[256]; string line; stimuli.clear(); type_pattern pattern; int total_pattern_size = 0; while(!fin.eof()) { line.clear(); fin.getline (buffer,255); line = buffer; if (line[0] == '#') continue; if (line == "") { if ( total_pattern_size > 0 ) { stringstream oss; oss << "StimulusGroup:: Read pattern " << stimuli.size() << " with pattern size " << total_pattern_size << " ( " << pattern.size() << " on rank )"; logger->msg(oss.str(),DEBUG); stimuli.push_back(pattern); pattern.clear(); total_pattern_size = 0; } continue; } stringstream iss (line); NeuronID i ; iss >> i ; if ( localrank( i ) ) { pattern_member pm; pm.gamma = 1 ; iss >> pm.gamma ; pm.i = global2rank( i ) ; pattern.push_back( pm ) ; } total_pattern_size++; } fin.close(); // initializing all probabilities as a flat distribution flat_distribution(); stringstream oss; oss << "StimulusGroup:: Finished loading " << stimuli.size() << " patterns"; logger->msg(oss.str(),NOTIFICATION); }