diff --git a/cpp_sources/ChemSyn.cpp b/cpp_sources/ChemSyn.cpp index be78c2f..63b8b2f 100755 --- a/cpp_sources/ChemSyn.cpp +++ b/cpp_sources/ChemSyn.cpp @@ -7,12 +7,10 @@ #include "ChemSyn.h" -ChemSyn::ChemSyn(const double dt_input, const int step_tot_input, const char delim_input, const char indicator_input){ +ChemSyn::ChemSyn(const double dt_input, const int step_tot_input){ dt = dt_input; step_tot = step_tot_input; - delim = delim_input; - indicator = indicator_input; // Default parameters V_ex = 0.0; // Excitatory reversal, 0.0 @@ -508,6 +506,7 @@ void ChemSyn::sample_data(const int step_current){ void ChemSyn::set_para(string para_str){ + const char delim = ','; if (!para_str.empty()){ istringstream para(para_str); string para_name, para_value_str; @@ -532,9 +531,10 @@ void ChemSyn::set_para(string para_str){ string ChemSyn::dump_para(){ + const char delim = ','; + stringstream dump; - dump << "pop_ind_pre" << delim << pop_ind_pre << delim << endl; dump << "pop_ind_post" << delim << pop_ind_post << delim << endl; dump << "syn_type" << delim << syn_type << delim << endl; @@ -589,44 +589,6 @@ void ChemSyn::start_cov_record(const int time_start, const int time_end){ } -void ChemSyn::output_results(ofstream& output_file){ - // SYND001 # synapse parameters - // count number of variables - stringstream dump_count; - string para_str = dump_para(); - dump_count << para_str; - string str_temp; - int var_number = 0; - while(getline(dump_count,str_temp)){++var_number;} // count number of variables - output_file << indicator << " SYND001" << endl; - output_file << var_number << delim << endl; - output_file << para_str; - - - // SYND002 # sampled synapse data - if (!sample.neurons.empty()){ - output_file << indicator << " SYND002" << endl; - output_file << pop_ind_pre << delim << pop_ind_post << delim << syn_type << delim << sample.neurons.size() << delim << endl; - write2file(output_file, sample.data); // 2D matrix - } - - - // SYND003 # currents mean and std - if (stats.record){ - output_file << indicator << " SYND003" << endl; - output_file << pop_ind_pre << delim << pop_ind_post << delim << syn_type << delim << endl; - write2file(output_file, stats.I_mean); - write2file(output_file, stats.I_std); - } - - // tmp data - if (tmp_data.size() != 0){ - output_file << indicator << " SYND004" << endl; - output_file << pop_ind_pre << delim << pop_ind_post << delim << syn_type << delim << tmp_data.size() << delim << endl; - write2file(output_file, tmp_data); - } -} - void ChemSyn::add_JH_Learning(vector &NeuronPopArray,int isteps, double iscaleE, double iscaleI,double lrate_E, double lrateall_E,double lrate_I, double lrateall_I,int intau, double innoise,int type_pre,int type_post){ jh_learn_syn.on=true; //indicates this learning is to be used @@ -960,9 +922,6 @@ void ChemSyn::record_stats(int step_current){ } } - -#ifdef HDF5 - void ChemSyn::import_restart(H5File& file, int syn_ind){ string str; @@ -1297,4 +1256,3 @@ void ChemSyn::output_results(H5File& file, int syn_ind){ } } -#endif diff --git a/cpp_sources/ChemSyn.h b/cpp_sources/ChemSyn.h index 0c49bb4..f34984b 100755 --- a/cpp_sources/ChemSyn.h +++ b/cpp_sources/ChemSyn.h @@ -15,7 +15,7 @@ class ChemSyn { public: ChemSyn(); /// default constructor - ChemSyn(const double dt, const int step_tot, const char delim, const char indicator); /// parameterised constructor + ChemSyn(const double dt, const int step_tot); /// parameterised constructor void init(const int syn_type, const int pop_ind_pre, const int pop_ind_post, const int N_pre, const int N_post, const vector &C_i, const vector &C_j, const vector &K_ij, const vector &D_ij); /// initialise chemical synapses by reading already prepared connections @@ -51,18 +51,15 @@ class ChemSyn void old_pre_spikes_K_JH_Learn(vector &NeuronPopArray); void record_V_post_JH_Learn(vector &NeuronPopArray); -#ifdef HDF5 void import_restart(H5File& file, int syn_ind); void export_restart(Group& Group, int syn_ind); void output_results(H5File& file_HDF5, int syn_ind); -#endif + const int & get_syn_type(); /// get synapse type const int & get_pop_ind_pre(); /// get index of pre-synaptic population const int & get_pop_ind_post(); /// get index of post-synaptic population private: - char delim; /// delimiter for input and output files, usually comma - char indicator; /// indicator for protocols, usually a single greater than operator void init(); /// parameter-dependent initialisation string dump_para(); // dump all the parameter values used diff --git a/cpp_sources/MyIO.cpp b/cpp_sources/MyIO.cpp index ee44ebc..a7c6912 100644 --- a/cpp_sources/MyIO.cpp +++ b/cpp_sources/MyIO.cpp @@ -56,10 +56,6 @@ void write2file(ofstream& output_file, const vector& v){ } - - -#ifdef HDF5 - /*--------------------------------------- HDF5 --------------------------------------------*/ void write_scalar_HDF5(Group & group, unsigned int s, const string & v_name){ vector v_tmp; @@ -485,4 +481,3 @@ template int read_scalar_HDF5(const H5File & file, const string & name); template unsigned int read_scalar_HDF5(const H5File & file, const string & name); -#endif \ No newline at end of file diff --git a/cpp_sources/MyIO.h b/cpp_sources/MyIO.h index 07e9099..4b70096 100644 --- a/cpp_sources/MyIO.h +++ b/cpp_sources/MyIO.h @@ -5,49 +5,47 @@ #include // cout/cin, ofstream: Stream class to write on files, ifstream : Stream class to read from files, istringstream is for input, ostringstream for output #include // fstream : Stream class to both read and write from / to files -#ifdef HDF5 - #include - #include - #ifndef H5_NO_NAMESPACE - using namespace H5; - #endif +#include +#include +#ifndef H5_NO_NAMESPACE + using namespace H5; #endif + using namespace std; const char delim = ','; /// Bad practice: this is hard-coded here! -#ifdef HDF5 - void write_vector_HDF5(Group & group, const vector & v, const string & v_name); - void write_vector_HDF5(Group & group, const vector & v, const string & v_name); - void write_vector_HDF5(Group & group, const vector & v, const string & v_name); - void write_vector_HDF5(Group & group, const vector & v, const string & v_name); - void append_vector_to_matrix_HDF5(DataSet & dataset_tmp, const vector & v, const int colNum); - void append_vector_to_matrix_HDF5(DataSet & dataset_tmp, const vector & v, const int colNum); - void write_matrix_HDF5(Group & group, const vector< vector > & m, const string & m_name); - void write_matrix_HDF5(Group & group, const vector< vector > & m, const string & m_name); - void write_matrix_HDF5(Group & group, const vector< vector > & m, const string & m_name); +void write_vector_HDF5(Group & group, const vector & v, const string & v_name); +void write_vector_HDF5(Group & group, const vector & v, const string & v_name); +void write_vector_HDF5(Group & group, const vector & v, const string & v_name); +void write_vector_HDF5(Group & group, const vector & v, const string & v_name); +void append_vector_to_matrix_HDF5(DataSet & dataset_tmp, const vector & v, const int colNum); +void append_vector_to_matrix_HDF5(DataSet & dataset_tmp, const vector & v, const int colNum); +void write_matrix_HDF5(Group & group, const vector< vector > & m, const string & m_name); +void write_matrix_HDF5(Group & group, const vector< vector > & m, const string & m_name); +void write_matrix_HDF5(Group & group, const vector< vector > & m, const string & m_name); - void write_string_HDF5(Group & group, const string & s, const string & s_name); - void write_scalar_HDF5(Group & group, unsigned int s, const string & v_name); - void write_scalar_HDF5(Group & group, int s, const string & v_name); - void write_scalar_HDF5(Group & group, double s, const string & v_name); +void write_string_HDF5(Group & group, const string & s, const string & s_name); +void write_scalar_HDF5(Group & group, unsigned int s, const string & v_name); +void write_scalar_HDF5(Group & group, int s, const string & v_name); +void write_scalar_HDF5(Group & group, double s, const string & v_name); - void read_string_HDF5(const H5File & file, const string & s_name, string & s); - void read_matrix_HDF5(const H5File & file, const string & name, vector< vector > & m_tmp); - void read_matrix_HDF5(const H5File & file, const string & name, vector< vector > & m_tmp); - void read_matrix_HDF5(const H5File & file, const string & name, vector< vector > & m_tmp); - void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); - void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); - void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); - void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); - bool dataset_exist_HDF5(const H5File & file, const string & name); - bool group_exist_HDF5(const H5File & file, const string & name); - bool group_exist_HDF5(const string & filename, const string & name); - template < typename Type > Type read_scalar_HDF5(const H5File & file, const string & name); -#endif - void write2file(ofstream& output_file, const vector< vector >& v); /// write integer matrix to output file - void write2file(ofstream& output_file, const vector< vector >& v); /// write double matrix to output file - void write2file(ofstream& output_file, const vector& v); /// write integer vector to output file - void write2file(ofstream& output_file, const vector& v); /// write double vector to output file +void read_string_HDF5(const H5File & file, const string & s_name, string & s); +void read_matrix_HDF5(const H5File & file, const string & name, vector< vector > & m_tmp); +void read_matrix_HDF5(const H5File & file, const string & name, vector< vector > & m_tmp); +void read_matrix_HDF5(const H5File & file, const string & name, vector< vector > & m_tmp); +void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); +void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); +void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); +void read_vector_HDF5(const H5File & file, const string & name, vector & v_tmp); +bool dataset_exist_HDF5(const H5File & file, const string & name); +bool group_exist_HDF5(const H5File & file, const string & name); +bool group_exist_HDF5(const string & filename, const string & name); +template < typename Type > Type read_scalar_HDF5(const H5File & file, const string & name); + +void write2file(ofstream& output_file, const vector< vector >& v); /// write integer matrix to output file +void write2file(ofstream& output_file, const vector< vector >& v); /// write double matrix to output file +void write2file(ofstream& output_file, const vector& v); /// write integer vector to output file +void write2file(ofstream& output_file, const vector& v); /// write double vector to output file #endif \ No newline at end of file diff --git a/cpp_sources/NeuroNet.cpp b/cpp_sources/NeuroNet.cpp index da2804a..2280ecc 100755 --- a/cpp_sources/NeuroNet.cpp +++ b/cpp_sources/NeuroNet.cpp @@ -10,13 +10,11 @@ using namespace std; -NeuroNet::NeuroNet(vector N_array_input, double dt_input, int step_tot_input, char delim_input, char indicator_input){ +NeuroNet::NeuroNet(vector N_array_input, double dt_input, int step_tot_input){ N_array = N_array_input; dt = dt_input; step_tot = step_tot_input; - delim = delim_input; - indicator = indicator_input; Num_pop = N_array.size(); runaway_killed = false; step_killed = -1; @@ -88,35 +86,11 @@ void NeuroNet::update(int step_current){ } - - -void NeuroNet::output_results(ofstream& output_file){ - - // write data - // cout << "Outputting results into text file..." << endl; - - // KILL002 # step at which runaway activity is killed - output_file << indicator << " KILL002" << endl; - output_file << step_killed << delim << endl; - - // dump population data - for (int i = 0; i < Num_pop; i++){ - NeuroPopArray[i]->output_results(output_file); - } - - // dump synapse data - for (unsigned int i = 0; i < ChemSynArray.size(); i++){ - ChemSynArray[i]->output_results(output_file); - } - -} - -#ifdef HDF5 void NeuroNet::import_restart(H5File & file,string out_filename){ Num_pop=read_scalar_HDF5(file,string("/Net/Num_pop")); for (unsigned int ind = 0; ind < N_array.size(); ++ind){ - NeuroPopArray.push_back(new NeuroPop(ind, N_array[ind], dt, step_tot, delim, indicator)); + NeuroPopArray.push_back(new NeuroPop(ind, N_array[ind], dt, step_tot)); cout << "\t Initialising neuron pop " << ind+1 << "..." << endl; NeuroPopArray[ind]->import_restart(file,ind,out_filename); @@ -126,7 +100,7 @@ void NeuroNet::import_restart(H5File & file,string out_filename){ int n_syns=read_scalar_HDF5(file,syn_str+"n_syns"); for (int ind = 0; ind < n_syns; ++ind){ - ChemSynArray.push_back(new ChemSyn(dt, step_tot, delim, indicator)); + ChemSynArray.push_back(new ChemSyn(dt, step_tot)); // network.ChemSynArray.back()->init(type, i_pre, j_post, N_array[i_pre], N_array[j_post], I, J, K, D); ChemSynArray[ind]->import_restart(file,ind); @@ -178,6 +152,3 @@ void NeuroNet::output_results(H5File & file_HDF5){ } } - -#endif - diff --git a/cpp_sources/NeuroNet.h b/cpp_sources/NeuroNet.h index fd21f1b..419805c 100755 --- a/cpp_sources/NeuroNet.h +++ b/cpp_sources/NeuroNet.h @@ -10,7 +10,7 @@ using namespace std; class NeuroNet{ public: NeuroNet(); - NeuroNet(vector N_array, double dt, int step_tot, char delim, char indicator); // parameterised constructor for heterogeneous coupling + NeuroNet(vector N_array, double dt, int step_tot); // parameterised constructor for heterogeneous coupling vector N_array; // number of neurons in each pupolation double dt; // (ms) @@ -24,18 +24,10 @@ class NeuroNet{ int step_killed; // initialised as -1 void update(int step_current); // update the network to current time step, use "virtual" if want override by derived class - - char delim; - char indicator; - void output_results(ofstream& output_file); - - -#ifdef HDF5 void import_restart(H5File & file, string out_filename); void export_restart(H5File& file_HDF5, int restart_no); void output_results(H5File& file_HDF5); -#endif diff --git a/cpp_sources/NeuroPop.cpp b/cpp_sources/NeuroPop.cpp index 1a95198..4b533c0 100755 --- a/cpp_sources/NeuroPop.cpp +++ b/cpp_sources/NeuroPop.cpp @@ -9,14 +9,12 @@ #include "NeuroPop.h" #include // for bind(), plus -NeuroPop::NeuroPop(const int pop_ind_input, const int N_input, const double dt_input, const int step_tot_input, const char delim_input, const char indicator_input) +NeuroPop::NeuroPop(const int pop_ind_input, const int N_input, const double dt_input, const int step_tot_input) { pop_ind = pop_ind_input; N = N_input; dt = dt_input; step_tot = step_tot_input; // this parameter is designed to be self-adapting (step_killed), so should be any other stuff that relies on it!! - delim = delim_input; - indicator = indicator_input; // Using consistant units: msec+mV+nF+miuS+nA // Initialise default parameters @@ -200,6 +198,7 @@ void NeuroPop::start_LFP_record(const vector >& LFP_neurons_inpu } void NeuroPop::set_para(string para_str) { + const char delim = ','; if (!para_str.empty()) { istringstream para(para_str); string para_name, para_value_str; @@ -427,10 +426,7 @@ void NeuroPop::update_V(const int step_current) { // Data sampling, which must be done here! // sample_data(step_current); // this is deprecated due to poor memory performance -#ifdef HDF5 output_sampled_data_real_time_HDF5(step_current); -#endif - output_sampled_data_real_time(step_current); // update menbrane potentials double Vdot; @@ -460,58 +456,6 @@ void NeuroPop::update_V(const int step_current) { } -void NeuroPop::add_sampling_real_time(const vector& sample_neurons_input, const vector& sample_type_input, const vector& sample_time_points_input, string sample_file_name_input) { - sample.file_type = 1; - sample.neurons = sample_neurons_input; - sample.type = sample_type_input; - sample.time_points = sample_time_points_input; - - sample.file_name = sample_file_name_input.append(to_string(pop_ind)).append(".ygout_samp"); - sample.file.open(sample.file_name); - - sample.N_steps = 0; - for (int tt = 0; tt < step_tot; ++tt) { - if (sample.time_points[tt]) {sample.N_steps += 1;} - } - sample.N_neurons = sample.neurons.size(); -} - - - - -void NeuroPop::output_sampled_data_real_time(const int step_current) { - if (!sample.neurons.empty() && step_current == 0 && sample.file_type == 1) { - - sample.file << indicator << " POPD006" << endl; - sample.file << pop_ind << delim << sample.N_neurons << delim << sample.N_steps << delim << endl; - vector< string > data_types = { "V", "I_leak", "I_AMPA", "I_GABA", "I_NMDA", "I_GJ", "I_ext", "I_K" }; - for (unsigned int tt = 0; tt < data_types.size(); ++tt) { - if (sample.type[tt]) {sample.file << data_types[tt] << delim; } - } - sample.file << endl; - } - - if (!sample.neurons.empty() && sample.file_type == 1) { - if (sample.time_points[step_current]) { // push_back is amazing - for (int i = 0; i < sample.N_neurons; ++i) { // performance issue when sampling many neurons? - int ind_temp = sample.neurons[i]; - if (sample.type[0]) {sample.file << V[ind_temp] << delim;} - if (sample.type[1]) {sample.file << I_leak[ind_temp] << delim;} - if (sample.type[2]) {sample.file << I_AMPA[ind_temp] << delim;} - if (sample.type[3]) {sample.file << I_GABA[ind_temp] << delim;} - if (sample.type[4]) {sample.file << I_NMDA[ind_temp] << delim;} - if (sample.type[5]) {sample.file << I_GJ[ind_temp] << delim;} - if (sample.type[6]) {sample.file << I_ext[ind_temp] << delim;} - if (sample.type[7]) {sample.file << I_K[ind_temp] << delim;} - sample.file << endl; - } - } - } - -} - - - void NeuroPop::add_sampling(const vector& sample_neurons_input, const vector& sample_type_input, const vector& sample_time_points_input) { sample.neurons = sample_neurons_input; sample.type = sample_type_input; @@ -642,82 +586,6 @@ void NeuroPop::reset_Q() { } -void NeuroPop::output_results(ofstream& output_file) { - - // POPD001 # spike history of neuron population - output_file << indicator << " POPD001" << endl; - output_file << pop_ind << delim << endl; - write2file(output_file, spike_hist_tot); - write2file(output_file, num_spikes_pop); - write2file(output_file, num_ref_pop); - - // POPD002 # neuron parameters in the population - stringstream dump_count; - string para_str = dump_para(); - dump_count << para_str; - string str_temp; - int var_number = 0; - while (getline(dump_count, str_temp)) {++var_number;} // count number of variables - output_file << indicator << " POPD002" << endl; - output_file << pop_ind << delim << var_number << delim << endl; - output_file << para_str; - - // POPD003 # membrane potential mean and std - if (stats.record) { - output_file << indicator << " POPD003" << endl; - output_file << pop_ind << delim << endl; - write2file(output_file, stats.V_mean); - write2file(output_file, stats.V_std); - write2file(output_file, stats.I_input_mean); - write2file(output_file, stats.I_input_std); - } - - // POPD007 # local field potential - if (LFP.record) { - output_file << indicator << " POPD007" << endl; - output_file << pop_ind << delim << LFP.data.size() << delim << endl; - write2file(output_file, LFP.data); - } - - // POPD005 # E-I ratio for each neuron - if (stats.record) { - output_file << indicator << " POPD005" << endl; - output_file << pop_ind << delim << endl; - write2file(output_file, stats.IE_ratio); - } - - // SAMF001 # sampled data file name - if (!sample.file_name.empty()) { - output_file << indicator << " SAMF001" << endl; - output_file << sample.file_name << endl; - } - - - /* // This following output protocol is deprecated due to poor memeory performance - // POPD004 # sampled neuron data - if (!sample_neurons.empty()){ - output_file << indicator << " POPD004" << endl; - output_file << pop_ind << delim << sample.neurons.size() << delim << endl; - - vector< string > data_types = { "V", "I_leak", "I_AMPA", "I_GABA", "I_NMDA", "I_GJ", "I_ext", "I_K" }; - for (unsigned int tt = 0; tt < data_types.size(); ++tt){ - if (sample.type[tt] == true){output_file << data_types[tt] << delim;} - } - output_file << endl; - - - for (unsigned int c = 0; c < sample.type.size(); ++c){ - if (!sample.data[c].empty()){ - NeuroPop::write2file(output_file, sample.data[c]); // 2D matrix - } - } - } - */ - -} - - - void NeuroPop::record_LFP() { if (LFP.record) { for (unsigned int ind = 0; ind < LFP.neurons.size(); ++ind) { @@ -857,10 +725,6 @@ void Welford_online(const vector& new_data, vector& M, const int } - - -#ifdef HDF5 - void NeuroPop::load_file_current_input(string fname) { cout << "\t\tLoading currents from file... " << fname; H5File file( fname, H5F_ACC_RDONLY ); @@ -1373,5 +1237,3 @@ void NeuroPop::output_sampled_data_real_time_HDF5(const int step_current) { } -#endif - diff --git a/cpp_sources/NeuroPop.h b/cpp_sources/NeuroPop.h index b982e8f..236c1d4 100755 --- a/cpp_sources/NeuroPop.h +++ b/cpp_sources/NeuroPop.h @@ -30,16 +30,12 @@ using namespace std; class NeuroPop { public: NeuroPop(); /// default constructor - NeuroPop(const int pop_ind, const int N_input, const double dt_input, const int step_tot, const char delim, const char indicator); /// parameterised constructor + NeuroPop(const int pop_ind, const int N_input, const double dt_input, const int step_tot); /// parameterised constructor void init(); // initialise neurons, called by constructor after parameter assignment void set_para(string para); /// set parameters if not using default ones void set_seed(int seed); /// manually set RNG seed - void output_results(ofstream& output_file); - - - void recv_I(vector& I_add, const int pop_ind_pre, const int syn_type); const vector< int >& get_spikes_current(); const vector< double >& get_V(); @@ -64,9 +60,6 @@ class NeuroPop { void set_gaussian_I_ext(const vector& mean, const vector& std); void set_gaussian_g_ext(const vector& mean, const vector& std); - void add_sampling(const vector& sample_neurons, const vector& sample_type, const vector& sample_time_points); - void add_sampling_real_time(const vector& sample_neurons_input, const vector& sample_type_input, const vector& sample_time_points_input, string samp_file_name); - void load_file_spike_input(string fname); void load_file_current_input(string fname); void get_current_from_file(); @@ -84,12 +77,11 @@ class NeuroPop { // However it is tolerable in development. // Once the JH learning algorithm is published, consider fix it. -#ifdef HDF5 void import_restart(H5File & file, int pop_ind, string out_filename); void export_restart(Group & group); void output_results(H5File& file_HDF5); void add_sampling_real_time_HDF5(const vector& sample_neurons_input, const vector& sample_type_input, const vector& sample_time_points_input, string samp_file_name); -#endif + void add_sampling(const vector& sample_neurons_input, const vector& sample_type_input, const vector& sample_time_points_input); void init_runaway_killer(const double min_ms, const double Hz, const double Hz_ms); /// kill the simulation when runaway activity of the network is detected: // mean number of refractory neurons over previous steps "runaway_steps" in any population exceeding "mean_num_ref" @@ -100,14 +92,8 @@ class NeuroPop { private: void generate_I_ext(const int step_current); void record_stats(const int step_current); - void output_sampled_data_real_time(const int step_current); - -#ifdef HDF5 void output_sampled_data_real_time_HDF5(const int step_current); -#endif string dump_para(); /// dump all the parameter values used - char delim; - char indicator; void sample_data(const int step_current); void runaway_check(const int step_current); void record_LFP(); @@ -231,14 +217,10 @@ class NeuroPop { int file_type; /// 0 for no sample, 1 for text-based, 2 for hdf5-based string file_name; /// the file name for sampled time series - ofstream - file; /// the output file stream for sampled time series -#ifdef HDF5 H5File * file_HDF5; DataSet V_dataset, I_leak_dataset, I_AMPA_dataset, I_GABA_dataset, I_NMDA_dataset, I_GJ_dataset, I_ext_dataset, I_K_dataset; -#endif int ctr = 0; /// counter that counts how many steps have been sampled vector diff --git a/cpp_sources/SimuInterface.cpp b/cpp_sources/SimuInterface.cpp index 9c1e658..c21424c 100755 --- a/cpp_sources/SimuInterface.cpp +++ b/cpp_sources/SimuInterface.cpp @@ -8,677 +8,9 @@ using namespace std; SimuInterface::SimuInterface(){ // define default output data file format output_suffix = ".ygout"; // filename extension - delim = ','; - indicator = '>'; - commentor = '#'; } -bool SimuInterface::import(string in_filename_input){ - // read main input file - in_filename = in_filename_input; - inputfile.open(in_filename, ifstream::in); - if (inputfile){ - cout << "------------------------------------------------------------" << endl; - cout << "Importing " << in_filename << "..." << endl; - } - else { - cout << "Error: cannot open file " << in_filename << endl; - return 0; - } - - // claim variables to be assigned - int Num_pop; - double dt; - int step_tot; - vector N_array; - // temporary data storage - vector pop_para; // parameters of neuron popluation - string syn_para; // parameters of synapses - vector< vector > ext_spike_settings; // (int pop_ind, int type_ext, double K_ext, int Num_ext, double rate_ext) - vector< vector > rate_ext_t; // vector rate_ext(t) - vector< vector > ext_spike_neurons; // - - vector ext_current_settings_pop_ind; // (int pop_ind) - vector< vector > ext_current_settings; // (vector mean, vector std) - vector ext_conductance_settings_pop_ind; // (int pop_ind) - vector< vector > ext_conductance_settings; // (vector mean, vector std) - - vector init_condition_settings_depre; // (double p_fire) - vector< vector > init_condition_settings; // (double r_V0, double p_fire) - - vector neuron_sample_pop_ind; // - vector< vector > neuron_sample_neurons; // - vector< vector > neuron_sample_type; // - vector< vector > neuron_sample_time_points; // the length of time vector - - vector< vector > syn_sample_pop_ind; // - vector< vector > syn_sample_neurons; // - vector< vector > syn_sample_time_points; // the length of time vector - - vector neuron_stats_setting; - vector< vector > syn_stats_setting; - vector< vector > STD_setting; - vector< vector > inh_STDP_setting; - vector spike_freq_adpt_setting; // - - vector LFP_record_pop_ind; // - vector< vector < vector > > LFP_record_setting; // - - string syn_filename; // name of file that defines synaptic connection - vector< vector > runaway_killer_setting; // [pop_ind, min_ms, runaway_Hz, Hz_ms] - - vector< vector > step_perturb_setting; // [pop_ind step_perturb] - - int synapse_model_choice = 0; - - // read data - string line_str, entry_str; // temporary container for the entire while loop - size_t found; - while (getline(inputfile, line_str)){ - istringstream line_ss(line_str); // local variable: lifetime is only a signle loop (scope is within "{}")! reusing it by ".str()" may cause fatal error because the internal error flag remains the same. Everytime using "while(getline(...)){}" will change internal error flag! - if (line_str.empty()){continue;} - else if (line_str.front() == commentor){continue;} - else if (line_str.front() == indicator){// read data-info line - - // read number of neurons in each population - found = line_str.find("INIT001"); - if (found != string::npos){// if found match - cout << "\t Reading number of neurons in each population..." << endl; - read_next_line_as_vector(N_array); - - // Infer number of populations - Num_pop = N_array.size(); - pop_para.resize(Num_pop); // ?????? - continue; // move to next line - } - - - // read time step length and total steps - found = line_str.find("INIT002"); - if (found != string::npos){// if found match - cout << "\t Reading time step length and total steps..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - - dt = read_next_entry(line_ss); - step_tot = read_next_entry(line_ss); - continue; // move to next line - } - - - - // Random initial distributions for membrane potentials (deprecated) - found = line_str.find("INIT003"); - if (found != string::npos){// if found match - cout << "\t Reading random initial distributions for membrane potentials..." << endl; - read_next_line_as_vector(init_condition_settings_depre); // p_fire - continue; // move to next line - } - - // read external current setting - found = line_str.find("INIT004"); - if (found != string::npos){// if found match - cout << "\t Reading external current settings..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - ext_current_settings_pop_ind.push_back(read_next_entry(line_ss)); - ext_current_settings.resize(ext_current_settings.size()+1); - read_next_line_as_vector(ext_current_settings.back()); // vector mean - ext_current_settings.resize(ext_current_settings.size()+1); - read_next_line_as_vector(ext_current_settings.back()); // vector std - continue; // move to next line - } - - - - // read external spike setting - found = line_str.find("INIT005"); - if (found != string::npos){// if found match - cout << "\t Reading external spike settings..." << endl; - // [pop_ind,type_ext,K_ext,Num_ext] - ext_spike_settings.resize(ext_spike_settings.size()+1); - read_next_line_as_vector(ext_spike_settings.back()); - // ext_spike_neurons - ext_spike_neurons.resize(ext_spike_neurons.size()+1); - read_next_line_as_vector(ext_spike_neurons.back()); - // [rate_ext_t] - rate_ext_t.resize(rate_ext_t.size()+1); - read_next_line_as_vector(rate_ext_t.back()); - continue; // move to next line - } - - // read perturbation setting - found = line_str.find("INIT007"); - if (found != string::npos){// if found match - cout << "\t Reading perturbation settings..." << endl; - // [pop_ind, step_perturb] - step_perturb_setting.resize(step_perturb_setting.size()+1); - read_next_line_as_vector(step_perturb_setting.back()); - continue; // move to next line - } - - found = line_str.find("INIT008"); - if (found != string::npos){// if found match - cout << "\t Reading short term depression settings..." << endl; - // [pop_ind_pre, pop_ind_post, STD_on_step] - STD_setting.resize(STD_setting.size()+1); - read_next_line_as_vector(STD_setting.back()); - continue; // move to next line - } - - found = line_str.find("INIT009"); - if (found != string::npos){// if found match - cout << "\t Reading inhibitory STDP settings..." << endl; - // [pop_ind_pre, pop_ind_post, inh_STDP_on_step] - inh_STDP_setting.resize(inh_STDP_setting.size()+1); - read_next_line_as_vector(inh_STDP_setting.back()); - continue; // move to next line - } - - found = line_str.find("INIT010"); - if (found != string::npos){// if found match - cout << "\t Reading spike-frequency adaptation settings..." << endl; - // [pop_ind] - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - spike_freq_adpt_setting.push_back(read_next_entry(line_ss)); - continue; // move to next line - } - - // Random initial distributions for membrane potentials and initial firing probabilities - found = line_str.find("INIT011"); - if (found != string::npos){// if found match - cout << "\t Reading random initial distributions for membrane potentials and initial firing probabilities..." << endl; - init_condition_settings.resize(2); - read_next_line_as_vector(init_condition_settings[0]); // r_V0 - read_next_line_as_vector(init_condition_settings[1]); // p_fire - continue; // move to next line - } - - // read external conductance setting - found = line_str.find("INIT012"); - if (found != string::npos){// if found match - cout << "\t Reading external conductance settings..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - ext_conductance_settings_pop_ind.push_back(read_next_entry(line_ss)); - ext_conductance_settings.resize(ext_conductance_settings.size()+1); - read_next_line_as_vector(ext_conductance_settings.back()); // vector mean - ext_conductance_settings.resize(ext_conductance_settings.size()+1); - read_next_line_as_vector(ext_conductance_settings.back()); // vector std - continue; // move to next line - } - - // read synapse model choice - found = line_str.find("INIT013"); - if (found != string::npos){// if found match - cout << "\t Reading synapse model choice..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - synapse_model_choice = read_next_entry(line_ss); - continue; // move to next line - } - - // read neuron population parameter setting - found = line_str.find("PARA001"); - if (found != string::npos){// if found match - cout << "\t Reading non-default neuron population parameters..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - // pop_ind and number of parameters - int pop_ind = read_next_entry(line_ss); - int num_para = read_next_entry(line_ss); - // store parameter settings - for (int c = 0; c < num_para; ++c){ - getline(inputfile, line_str); // read next line - pop_para[pop_ind] += line_str; // append (+=) - } - continue; // move to next line - } - - // read synapse parameter setting - found = line_str.find("PARA002"); - if (found != string::npos){// if found match - cout << "\t Reading non-default synapse parameters..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - // number of parameters - int num_para = read_next_entry(line_ss); - // store parameter settings - for (int c = 0; c < num_para; ++c){ - getline(inputfile, line_str); // read next line - syn_para += line_str; // append (+=) - } - continue; // move to next line - } - - - - // read runaway killer setting - found = line_str.find("KILL001"); - if (found != string::npos){ - cout << "\t Reading runaway killer setting..." << endl; - // double pop_ind, min_ms, double Hz, double Hz_ms - runaway_killer_setting.resize(runaway_killer_setting.size()+1); - read_next_line_as_vector(runaway_killer_setting.back()); - continue; - } - - - - // read neuron data sampling setting - found = line_str.find("SAMP001"); - if (found != string::npos){// if found match - cout << "\t Reading neuron data sampling settings..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - // int pop_ind; - neuron_sample_pop_ind.push_back(read_next_entry(line_ss)); - // sample_type - neuron_sample_type.resize(neuron_sample_type.size()+1); - read_next_line_as_vector(neuron_sample_type.back()); - // sample_neurons - neuron_sample_neurons.resize(neuron_sample_neurons.size()+1); - read_next_line_as_vector(neuron_sample_neurons.back()); - // sample_t_ind - neuron_sample_time_points.resize(neuron_sample_time_points.size()+1); - read_next_line_as_vector(neuron_sample_time_points.back()); - continue; // move to next line - } - - // read synapase data sampling setting - found = line_str.find("SAMP002"); - if (found != string::npos){// if found match - cout << "\t Reading synapse data sampling settings..." << endl; - // pop indices - syn_sample_pop_ind.resize(syn_sample_pop_ind.size()+1); - read_next_line_as_vector(syn_sample_pop_ind.back()); - // sample_neurons - syn_sample_neurons.resize(syn_sample_neurons.size()+1); - read_next_line_as_vector(syn_sample_neurons.back()); - // sample_t_ind - syn_sample_time_points.resize(syn_sample_time_points.size()+1); - read_next_line_as_vector(syn_sample_time_points.back()); - continue; // move to next line - } - - // neuron_stats_record - found = line_str.find("SAMP003"); - if (found != string::npos){// if found match - cout << "\t Reading neuron stats record settings..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - // int pop_ind; - neuron_stats_setting.push_back(read_next_entry(line_ss)); - continue; // move to next line - } - - - // syn_stats_record - found = line_str.find("SAMP004"); - if (found != string::npos){// if found match - cout << "\t Reading synaptic stats record settings..." << endl; - syn_stats_setting.resize(syn_stats_setting.size()+1); - read_next_line_as_vector(syn_stats_setting.back()); - continue; // move to next line - } - - // LFP record - found = line_str.find("SAMP005"); - if (found != string::npos){// if found match - cout << "\t Reading LFP record settings..." << endl; - getline(inputfile, line_str);istringstream line_ss(line_str);// Read next line - // int pop_ind, sample_number; - LFP_record_pop_ind.push_back(read_next_entry(line_ss)); - int n = read_next_entry(line_ss); - LFP_record_setting.resize(LFP_record_setting.size()+1); - for (int ind = 0; ind < n; ++ind){ - LFP_record_setting.back().resize(LFP_record_setting.back().size()+1); - read_next_line_as_vector(LFP_record_setting.back().back()); - } - continue; // move to next line - } - - - // read non-default synapse definition file name - found = line_str.find("SYNF001"); - if (found != string::npos){ - cout << "\t Reading non-default synapse definition file name..." << endl; - getline(inputfile, syn_filename); // Read next line - cout << "\t\t non-default synapse definition: " << syn_filename << endl; - continue; - } - - else{ - cout << "Unrecognized command sequence: " << line_str << endl; - } - - } //read data-info line - - } // while - inputfile.close(); - inputfile.clear(); - - // read synapse definition input file - if (syn_filename.empty()){ // default file name - syn_filename = in_filename; - syn_filename.append("_syn"); // .ygin_syn - } - inputfile.open(syn_filename, ifstream::in); // close, clear and then open: reusing is a bad practice? - if (inputfile){} - else { - cout << "Error: cannot open syn file " << syn_filename << endl; - return 0; - } - - // temporary data storage - vector< vector > I_temp, J_temp; //for chemical synapses - vector< vector > K_temp, D_temp; //for chemical synapses - vector< vector > IJKD_chem_info; // {Type(0:AMPA/1:GABAa/2:NMDA),Pre_pop_ind(0/1/...),Post_pop_ind(0/1/...)} - - // read data - while (getline(inputfile, line_str)){ - istringstream line_ss(line_str); - if (line_str.empty()){continue;} - else if (line_str.front() == commentor){continue;} - else if (line_str.front() == indicator){// read data-info line - - // read connection data: [I;J;K;D] (chemical) - found = line_str.find("INIT006"); - if (found != string::npos){// if found match - cout << "\t Reading chemical connection..." << endl; - // [type, pre_pop_ind, post_pop_ind] - IJKD_chem_info.resize(IJKD_chem_info.size()+1); - read_next_line_as_vector(IJKD_chem_info.back()); - // I_temp - I_temp.resize(I_temp.size()+1); - read_next_line_as_vector(I_temp.back()); - // J_temp - J_temp.resize(J_temp.size()+1); - read_next_line_as_vector(J_temp.back()); - // K_temp - K_temp.resize(K_temp.size()+1); - read_next_line_as_vector(K_temp.back()); - // D_temp - D_temp.resize(D_temp.size()+1); - read_next_line_as_vector(D_temp.back()); - - continue; // move to next line - } - }//read data-info line - - - } // while - - inputfile.close(); - inputfile.clear(); - - out_filename = gen_out_filename(); - - - // build NeuroNet based on data imported - network = NeuroNet(N_array, dt, step_tot, delim, indicator); - cout << "\t Network created." << endl; - cout << "\t Initialising neuron populations..."; - for (unsigned int ind = 0; ind < N_array.size(); ++ind){ - network.NeuroPopArray.push_back(new NeuroPop(ind, N_array[ind], network.dt, network.step_tot, delim, indicator)); - network.NeuroPopArray.back()->set_para(pop_para[ind]); - cout << ind+1 << "..."; - } - cout << "done." << endl; - - // chemical connections - if (I_temp.size() != 0){ - cout << "\t Initialising chemical synapses... "; - for (unsigned int ind = 0; ind < I_temp.size(); ++ind){ - int type = IJKD_chem_info[ind][0]; - int i_pre = IJKD_chem_info[ind][1]; - int j_post = IJKD_chem_info[ind][2]; - network.ChemSynArray.push_back(new ChemSyn(network.dt, network.step_tot, delim, indicator)); - network.ChemSynArray.back()->init(type, i_pre, j_post, network.N_array[i_pre], network.N_array[j_post], I_temp[ind], J_temp[ind], K_temp[ind], D_temp[ind]); - network.ChemSynArray.back()->set_para(syn_para); - if (synapse_model_choice != 0){ - network.ChemSynArray.back()->set_synapse_model(synapse_model_choice); - } - cout << ind+1 << "..."; - } - cout << "done." << endl; - } - - // external spike setting (int pop_ind, int type_ext, double K_ext, int Num_ext, - // vector rate_ext_t, int ia, int ib) - if (ext_spike_settings.size() != 0){ - cout << "\t External spike settings..."; - for (unsigned int ind = 0; ind < ext_spike_settings.size(); ++ind){ - int j_post = int(ext_spike_settings[ind][0]); - int type_ext = int(ext_spike_settings[ind][1]); - double K_ext = ext_spike_settings[ind][2]; - int Num_ext = int(ext_spike_settings[ind][3]); - network.ChemSynArray.push_back(new ChemSyn(network.dt, network.step_tot, delim, indicator)); - network.ChemSynArray.back()->init(type_ext, j_post, network.N_array[j_post], K_ext, Num_ext, rate_ext_t[ind], ext_spike_neurons[ind]); - network.ChemSynArray.back()->set_para(syn_para); - cout << ind+1 << "..."; - } - cout << "done." << endl; - } - - // external current setting - if (ext_current_settings_pop_ind.size() != 0){ - cout << "\t External current settings..."; - for (unsigned int ind = 0; ind < ext_current_settings_pop_ind.size(); ++ind){ - int pop_ind = ext_current_settings_pop_ind[ind]; - vector mean = ext_current_settings[ ind*2 ]; - vector std = ext_current_settings[ ind*2+1 ]; - network.NeuroPopArray[pop_ind]->set_gaussian_I_ext(mean, std); - cout << ind+1 << "..."; - } - cout << "done." << endl; - } - - // external conductance setting - if (ext_conductance_settings_pop_ind.size() != 0){ - cout << "\t External conductance settings..."; - for (unsigned int ind = 0; ind < ext_conductance_settings_pop_ind.size(); ++ind){ - int pop_ind = ext_conductance_settings_pop_ind[ind]; - vector mean = ext_conductance_settings[ ind*2 ]; - vector std = ext_conductance_settings[ ind*2+1 ]; - network.NeuroPopArray[pop_ind]->set_gaussian_g_ext(mean, std); - cout << ind+1 << "..."; - } - cout << "done." << endl; - } - - // random initial condition settings (double p_fire) - if (init_condition_settings_depre.size() != 0){ - cout << "\t Random initial condition settings..."; - for (unsigned int pop_ind = 0; pop_ind < init_condition_settings_depre.size(); ++pop_ind){ - double p_fire = init_condition_settings_depre[pop_ind]; - network.NeuroPopArray[pop_ind]->random_V(p_fire); - cout << pop_ind+1 << "..."; - } - cout << "done." << endl; - } - - // random initial condition settings (double r_V0, double p_fire) - if (init_condition_settings.size() != 0){ - cout << "\t Random initial condition settings..."; - for (unsigned int pop_ind = 0; pop_ind < init_condition_settings.size(); ++pop_ind){ - double r_V0 = init_condition_settings[0][pop_ind]; - double p_fire = init_condition_settings[1][pop_ind]; - network.NeuroPopArray[pop_ind]->set_init_condition(r_V0, p_fire); - cout << pop_ind+1 << "..."; - } - cout << "done." << endl; - } - - - // perturbation setting - if (step_perturb_setting.size() != 0){ - cout << "\t Perturbation settings..."; - for (unsigned int i = 0; i < step_perturb_setting.size(); ++i){ - int pop_ind = step_perturb_setting[i][0]; - int step_perturb = step_perturb_setting[i][1]; - network.NeuroPopArray[pop_ind]->add_perturbation(step_perturb); - cout << pop_ind+1 << "..."; - } - cout << "done." << endl; - } - - - - if (STD_setting.size() != 0){ - cout << "\t Short-term depression settings..."; - for (unsigned int i = 0; i < STD_setting.size(); ++i){ - int pop_ind_pre = STD_setting[i][0]; - int pop_ind_post = STD_setting[i][1]; - int STD_on_step = STD_setting[i][2]; - - int syn_match = false; - for (unsigned int s = 0; s < network.ChemSynArray.size(); ++s){ - if (network.ChemSynArray[s]->get_pop_ind_pre() == pop_ind_pre && - network.ChemSynArray[s]->get_pop_ind_post() == pop_ind_post){ // find the right synapse object - network.ChemSynArray[s]->add_short_term_depression(STD_on_step); - cout << i+1 << "..."; - syn_match = true; - } - } - if (!syn_match){ - cout << "(no match found!)..."; - } - } - cout << "done." << endl; - } - - if (inh_STDP_setting.size() != 0){ - cout << "\t Inhibitory STDP settings..."; - - for (unsigned int i = 0; i < inh_STDP_setting.size(); ++i){ - int pop_ind_pre = inh_STDP_setting[i][0]; - int pop_ind_post = inh_STDP_setting[i][1]; - int inh_STDP_on_step = inh_STDP_setting[i][2]; - - int syn_match = false; - for (unsigned int s = 0; s < network.ChemSynArray.size(); ++s){ - if (network.ChemSynArray[s]->get_pop_ind_pre() == pop_ind_pre && - network.ChemSynArray[s]->get_pop_ind_post() == pop_ind_post){ // find the right synapse object - network.ChemSynArray[s]->add_inh_STDP(inh_STDP_on_step); - cout << i+1 << "..."; - syn_match = true; - } - } - if (!syn_match){ - cout << "(no match found!)..."; - } - } - cout << "done." << endl; - } - - if (spike_freq_adpt_setting.size() != 0){ - cout << "\t Spike-frequency adaptation settings..."; - for (unsigned int i = 0; i < spike_freq_adpt_setting.size(); ++i){ - int pop_ind = spike_freq_adpt_setting[i]; - network.NeuroPopArray[pop_ind]->add_spike_freq_adpt(); - cout << pop_ind+1 << "..."; - } - cout << "done." << endl; - } - - // neuron data sampling settings - if (neuron_sample_pop_ind.size() != 0){ - cout << "\t Neuron data sampling settings..."; - for (unsigned int ind = 0; ind < neuron_sample_pop_ind.size(); ++ind){ - int pop_ind = neuron_sample_pop_ind[ind]; - network.NeuroPopArray[pop_ind]->add_sampling_real_time(neuron_sample_neurons[ind], neuron_sample_type[ind], neuron_sample_time_points[ind], out_filename); - cout << ind+1 << "..."; - } - cout << "done." << endl; - } - - // neuron V mean std record settings - if (neuron_stats_setting.size() != 0){ - cout << "\t Neuron stats record settings..."; - for (unsigned int ind = 0; ind < neuron_stats_setting.size(); ++ind){ - int pop_ind = neuron_stats_setting[ind]; - network.NeuroPopArray[pop_ind]->start_stats_record(); - cout << ind+1 << "..."; - } - cout << "done." << endl; - } - - // LFP record settings - if (LFP_record_pop_ind.size() != 0){ - cout << "\t LFP record settings..."; - for (unsigned int ind = 0; ind < LFP_record_pop_ind.size(); ++ind){ - int pop_ind = LFP_record_pop_ind[ind]; - network.NeuroPopArray[pop_ind]->start_LFP_record(LFP_record_setting[ind]); - cout << ind+1 << "..."; - } - cout << "done." << endl; - } - - // syn data sampling settings - if (syn_sample_pop_ind.size() != 0){ - cout << "\t Synapse data sampling settings..."; - for (unsigned int ind = 0; ind < syn_sample_pop_ind.size(); ++ind){ - - int pop_ind_pre = syn_sample_pop_ind[ind][0]; - int pop_ind_post = syn_sample_pop_ind[ind][1]; - int syn_type = syn_sample_pop_ind[ind][2]; - - int syn_sample_match = false; - for (unsigned int s = 0; s < network.ChemSynArray.size(); ++s){ - if (network.ChemSynArray[s]->get_pop_ind_pre() == pop_ind_pre && - network.ChemSynArray[s]->get_pop_ind_post() == pop_ind_post && - network.ChemSynArray[s]->get_syn_type() == syn_type){ // find the right synapse object - network.ChemSynArray[s]->add_sampling(syn_sample_neurons[ind], syn_sample_time_points[ind]); - cout << ind+1 << "..."; - syn_sample_match = true; - } - } - if (!syn_sample_match){ - cout << "(no match found!)..."; - } - } - cout << "done." << endl; - } - - - - // syn I mean std record settings - if (syn_stats_setting.size() != 0){ - cout << "\t Synapse stats record settings..."; - for (unsigned int ind = 0; ind < syn_stats_setting.size(); ++ind){ - - int pop_ind_pre = syn_stats_setting[ind][0]; - int pop_ind_post = syn_stats_setting[ind][1]; - int syn_type = syn_stats_setting[ind][2]; - - int syn_I_match = false; - for (unsigned int s = 0; s < network.ChemSynArray.size(); ++s){ - if (network.ChemSynArray[s]->get_pop_ind_pre() == pop_ind_pre && - network.ChemSynArray[s]->get_pop_ind_post() == pop_ind_post && - network.ChemSynArray[s]->get_syn_type() == syn_type){ // find the right synapse object - network.ChemSynArray[s]->start_stats_record(); - cout << ind+1 << "..."; - syn_I_match = true; - } - } - if (!syn_I_match){ - cout << "(no match found!)..."; - } - } - cout << "done." << endl; - } - - // initialise runaway-killer - if (runaway_killer_setting.size() != 0){ - cout << "\t Runaway killer licensing for pop..."; - for (unsigned int ind = 0; ind < runaway_killer_setting.size(); ++ind){ - int pop_ind = int(runaway_killer_setting[ind][0]); - network.NeuroPopArray[pop_ind]->init_runaway_killer(runaway_killer_setting[ind][1], runaway_killer_setting[ind][2], runaway_killer_setting[ind][3]); - cout << pop_ind+1 << "..."; - } - cout << "done." << endl; - cout << "\t \t No women, no kids." << endl; - } - - - cout << "Importing done." << endl; - return 1; -} - void SimuInterface::simulate(){ clock_t begin = clock(); @@ -712,40 +44,10 @@ void SimuInterface::simulate(){ cout << "Simulation done." << endl; // output results into HDF5 file -#ifdef HDF5 - if(in_filename.substr(in_filename.find_last_of(".") + 1) == "h5") - { - export_restart_HDF5(); - output_results_HDF5(); - } - else if (in_filename.substr(in_filename.find_last_of(".") + 1) == "ygin") - { - output_results(); - } -#else - // output results into text file - output_results(); -#endif - -} - -void SimuInterface::output_results(){ - // output results into text file - ofstream output_file; - cout << "Creating text output file..."; - output_file.open(out_filename.append(output_suffix)); - network.output_results(output_file); - // attach input file (.ygin) to the output file for data completeness - ifstream in_file_attach( in_filename ); - output_file << in_file_attach.rdbuf(); + export_restart_HDF5(); + output_results_HDF5(); - cout << "done." << endl; - cout << "Data file name is: " << endl; - cout << " " << out_filename << endl; - cout << "------------------------------------------------------------" << endl; - // Write data file name to stdout and use "grep ygout" to extract it! - } string SimuInterface::gen_out_filename(){ @@ -764,37 +66,6 @@ string SimuInterface::gen_out_filename(){ return convert_temp.str(); // set 'Result' to the contents of the stream } - -template < typename Type > Type SimuInterface::read_next_entry(istringstream &line_ss){ - string entry_str; - Type entry; - getline(line_ss, entry_str, delim); - if (entry_str.empty()){ - cout << "ERROR: SimuInterface::read_next_entry: empty content!" << endl; - } - stringstream(entry_str) >> entry; - return entry; -} - -template < typename Type, typename A > void SimuInterface::read_next_line_as_vector(vector &vec){ - - string line_str, entry_str; - Type entry; - getline(inputfile, line_str); istringstream line_ss(line_str); // read next line - if (line_str.empty()){ - cout << "ERROR: SimuInterface::read_next_line_as_vector: empty string!" << endl; - } - while (getline(line_ss, entry_str, delim)){ - stringstream(entry_str) >> entry; - vec.push_back(entry); - } - -} - - - - -#ifdef HDF5 bool SimuInterface::import_restart_HDF5(string in_filename_input){ out_filename = gen_out_filename(); @@ -811,7 +82,7 @@ bool SimuInterface::import_restart_HDF5(string in_filename_input){ int step_tot=read_scalar_HDF5(file,string("/Net/step_tot")); double dt=read_scalar_HDF5(file,string("/Net/dt")); - network = NeuroNet( N_array, dt, step_tot, delim, indicator); + network = NeuroNet( N_array, dt, step_tot); cout << "\t Network created." << endl; network.import_restart(file, out_filename); return 1; @@ -890,7 +161,6 @@ void SimuInterface::output_results_HDF5(){ } - bool SimuInterface::import_HDF5(string in_filename_input){ in_filename = in_filename_input; @@ -905,12 +175,12 @@ bool SimuInterface::import_HDF5(string in_filename_input){ read_vector_HDF5(file, string("/config/Net/INIT001/N"), N_array); int step_tot = read_scalar_HDF5(file, string("/config/Net/INIT002/step_tot")); double dt = read_scalar_HDF5(file, string("/config/Net/INIT002/dt")); - network = NeuroNet( N_array, dt, step_tot, delim, indicator); + network = NeuroNet( N_array, dt, step_tot); cout << "\t Network created." << endl; for (unsigned int ind = 0; ind < N_array.size(); ++ind){ - network.NeuroPopArray.push_back(new NeuroPop(ind, N_array[ind], network.dt, network.step_tot, delim, indicator)); + network.NeuroPopArray.push_back(new NeuroPop(ind, N_array[ind], network.dt, network.step_tot)); cout << "\t Initialising neuron pop " << ind+1 << "..." << endl; string pop_n = "/config/pops/pop" + to_string(ind); @@ -1111,7 +381,7 @@ bool SimuInterface::import_HDF5(string in_filename_input){ read_vector_HDF5(file, syn_n + string("/INIT006/J"), J); read_vector_HDF5(file, syn_n + string("/INIT006/K"), K); read_vector_HDF5(file, syn_n + string("/INIT006/D"), D); - network.ChemSynArray.push_back(new ChemSyn(network.dt, network.step_tot, delim, indicator)); + network.ChemSynArray.push_back(new ChemSyn(network.dt, network.step_tot)); network.ChemSynArray.back()->init(type, i_pre, j_post, network.N_array[i_pre], network.N_array[j_post], I, J, K, D); // parameters @@ -1222,7 +492,7 @@ bool SimuInterface::import_HDF5(string in_filename_input){ read_vector_HDF5(file, syn_n + string("/INIT005/neurons"), neurons); vector rate_ext_t; read_vector_HDF5(file, syn_n + string("/INIT005/rate_ext_t"), rate_ext_t); - network.ChemSynArray.push_back(new ChemSyn(network.dt, network.step_tot, delim, indicator)); + network.ChemSynArray.push_back(new ChemSyn(network.dt, network.step_tot)); network.ChemSynArray.back()->init(type_ext, j_post, network.N_array[j_post], K_ext, Num_ext, rate_ext_t, neurons); // network.ChemSynArray.back()->set_para(syn_para); @@ -1264,6 +534,5 @@ bool SimuInterface::import_HDF5(string in_filename_input){ // return convert_temp.str(); // set 'Result' to the contents of the stream // } -#endif diff --git a/cpp_sources/SimuInterface.h b/cpp_sources/SimuInterface.h index cefa169..59067d7 100644 --- a/cpp_sources/SimuInterface.h +++ b/cpp_sources/SimuInterface.h @@ -13,16 +13,10 @@ class SimuInterface{ SimuInterface(); NeuroNet network; // use container? - // Format - char delim; // delim used to delimit the entries in the same line in files, note that the last entry of each line also has a delim - char indicator; // indicator of data-info line, always the first char in a line, followed by infomation about following data, say, name of the data variable, population index, etc - char commentor; // indicator of comment lines - // Import Network Setup Data string in_filename; // path+name ifstream inputfile; // current input file (.ygin or .ygin_syn) - - bool import(string in_filename); + void simulate(); // output data @@ -30,20 +24,14 @@ class SimuInterface{ string out_filename; // without suffix string gen_out_filename(); // generate unique file name using time stamp - void output_results(); - -#ifdef HDF5 - + bool import_restart_HDF5(string in_filename_input); void export_restart_HDF5(); // string gen_restart_filename(); void output_results_HDF5(); bool import_HDF5(string in_filename); -#endif - // Helper functions - template < typename Type > Type read_next_entry(istringstream &line_ss); - template < typename T, typename A > void read_next_line_as_vector( vector &vec ); + }; #endif diff --git a/cpp_sources/main.cpp b/cpp_sources/main.cpp index 1abf893..fdfb6f0 100755 --- a/cpp_sources/main.cpp +++ b/cpp_sources/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char* argv[]){// arguments should be input file path cout << "Processing input file No." << i << " out of " << argc-1 << "..." << endl; SimuInterface simulator; bool success = false; -#ifdef HDF5 + string filename = string(argv[i]); if(filename.substr(filename.find_last_of(".") + 1) == "h5") { @@ -19,13 +19,10 @@ int main(int argc, char* argv[]){// arguments should be input file path success = simulator.import_HDF5(argv[i]); } } - else if (filename.substr(filename.find_last_of(".") + 1) == "ygin") + else { - success = simulator.import(argv[i]); + cout << "Unrecogized input filename extension. " << endl; } -#else - success = simulator.import(argv[i]); -#endif if (success){ // return true if import is successful simulator.simulate(); diff --git a/makefile.in b/makefile.in index e3ca06e..9bc7679 100755 --- a/makefile.in +++ b/makefile.in @@ -5,8 +5,6 @@ SRC_FILES = $(SRC_DIR)/*.cpp HEADER_FILES = $(SRC_DIR)/*.h OBJ = main.o NeuroPop.o NeuroNet.o ChemSyn.o SimuInterface.o MyIO.o - -HDF5FLAG = -DHDF5 HDF5INCLUDE = @HDF5_CPPFLAGS@ #-I/usr/local/include HDF5LIBS = @HDF5_LDFLAGS@ -lhdf5_cpp -lhdf5 -lhdf5_hl @@ -14,7 +12,7 @@ HDF5LIBS = @HDF5_LDFLAGS@ -lhdf5_cpp -lhdf5 -lhdf5_hl ########################################################################### CXX = @CXX@ # must use version that MATLAB supp -CXXFLAGS = -std=c++11 @CXXFLAGS@ $(HDF5FLAG) +CXXFLAGS = -std=c++11 @CXXFLAGS@ CXXINCLUDE = $(HDF5INCLUDE)