SpikeStream Library
0.2
|
00001 //SpikeStream includes 00002 #include "ConnectionGroup.h" 00003 #include "GlobalVariables.h" 00004 #include "SpikeStreamException.h" 00005 using namespace spikestream; 00006 00007 //Other includes 00008 #include <iostream> 00009 using namespace std; 00010 00011 //Outputs debugging information about memory 00012 //#define MEMORY_DEBUG 00013 00014 //Initialize static variables 00015 unsigned ConnectionGroup::connectionIDCounter = LAST_CONNECTION_ID + 1; 00016 00017 00019 ConnectionGroup::ConnectionGroup(){ 00020 #ifdef MEMORY_DEBUG 00021 cout<<"New connection group (empty constructor) with size: "<<sizeof(*this)<<endl; 00022 #endif//MEMORY_DEBUG 00023 connectionDeque = new deque<Connection>(); 00024 } 00025 00026 00028 ConnectionGroup::ConnectionGroup(const ConnectionGroupInfo& connGrpInfo){ 00029 this->info = connGrpInfo; 00030 connectionDeque = new deque<Connection>(); 00031 00032 #ifdef MEMORY_DEBUG 00033 cout<<"New connection group (standard constructor) with size: "<<sizeof(*this)<<endl; 00034 #endif//MEMORY_DEBUG 00035 } 00036 00037 00039 ConnectionGroup::~ConnectionGroup(){ 00040 #ifdef MEMORY_DEBUG 00041 cout<<"Connection group destructor size of class: "<<sizeof(*this)<<"; size of map: "<<sizeof(*connectionDeque)<<"; number of connections: "<<connectionDeque->size()<<endl; 00042 #endif//MEMORY_DEBUG 00043 00044 //Deletes connection map and all its dynamically allocated objects 00045 if(connectionDeque != NULL){ 00046 clearConnections(); 00047 delete connectionDeque; 00048 } 00049 } 00050 00051 00052 /*--------------------------------------------------------*/ 00053 /*------- PUBLIC METHODS -------*/ 00054 /*--------------------------------------------------------*/ 00055 00058 unsigned ConnectionGroup::addConnection(unsigned id, unsigned fromNeuronID, unsigned toNeuronID, float delay, float weight){ 00059 //Store connection 00060 connectionDeque->push_back(Connection(id, fromNeuronID, toNeuronID, delay, weight)); 00061 00062 //Return index of connection 00063 return connectionDeque->size() - 1; 00064 } 00065 00066 00069 unsigned ConnectionGroup::addConnection(unsigned int fromNeuronID, unsigned int toNeuronID, float delay, float weight){ 00070 unsigned tmpID = getTemporaryID(); 00071 00072 //Store connection and return index 00073 connectionDeque->push_back(Connection(tmpID, fromNeuronID, toNeuronID, delay, weight)); 00074 return connectionDeque->size() - 1; 00075 } 00076 00077 00079 ConnectionIterator ConnectionGroup::begin(){ 00080 return connectionDeque->begin(); 00081 } 00082 00083 00085 ConnectionIterator ConnectionGroup::end(){ 00086 return connectionDeque->end(); 00087 } 00088 00089 00091 void ConnectionGroup::clearConnections(){ 00092 connectionDeque->clear(); 00093 } 00094 00095 00098 double ConnectionGroup::getParameter(const QString& paramName){ 00099 if(!parameterMap.contains(paramName)) 00100 throw SpikeStreamException("Cannot find parameter with key: " + paramName + " in connection group with ID " + QString::number(info.getID())); 00101 return parameterMap[paramName]; 00102 } 00103 00104 00106 unsigned ConnectionGroup::getSynapseTypeID(){ 00107 return info.getSynapseTypeID(); 00108 } 00109 00110 00112 Connection& ConnectionGroup::operator[] (unsigned index){ 00113 if(index >= connectionDeque->size()) 00114 throw SpikeStreamException("Connection vector index out of range: " + QString::number(index)); 00115 return (*connectionDeque)[index]; 00116 } 00117 00118 00120 bool ConnectionGroup::parametersSet(){ 00121 if(getInfo().getSynapseType().getParameterCount() == parameterMap.size()) 00122 return true; 00123 return false; 00124 } 00125 00126 00128 void ConnectionGroup::print(bool printConnections){ 00129 cout<<"------------- Connection Group: id="<<info.getID()<<"; '"<<info.getDescription().toStdString()<<"' "; 00130 cout<<"From: "<<info.getFromNeuronGroupID()<<" To: "<<info.getToNeuronGroupID()<<" "; 00131 cout<<info.getSynapseType().getDescription().toStdString()<<" -------------"<<endl; 00132 if(printConnections){ 00133 ConnectionIterator endConGrp = this->end(); 00134 for(ConnectionIterator conIter = this->begin(); conIter != endConGrp; ++conIter){ 00135 conIter->print(); 00136 } 00137 } 00138 } 00139 00140 00142 void ConnectionGroup::setDescription(const QString& description){ 00143 info.setDescription(description); 00144 } 00145 00146 00148 void ConnectionGroup::setFromNeuronGroupID(unsigned id){ 00149 info.setFromNeuronGroupID(id); 00150 } 00151 00152 00155 void ConnectionGroup::setParameters(QHash<QString, double> ¶mMap){ 00156 //Get the neuron type associated with this neuron group 00157 SynapseType synType = getInfo().getSynapseType(); 00158 QList<ParameterInfo> paramInfoList = synType.getParameterInfoList(); 00159 if(paramInfoList.size() != paramMap.size()) 00160 throw SpikeStreamException("ConnectionGroup: failed to set parameters. Mismatch between number of parameters."); 00161 foreach(ParameterInfo paramInfo, paramInfoList){ 00162 if(!paramMap.contains(paramInfo.getName())) 00163 throw SpikeStreamException("ConnectionGroup: failed to set parameters. Missing parameter: " + paramInfo.getName()); 00164 } 00165 00166 //Parameters are ok - store map. 00167 this->parameterMap = paramMap; 00168 } 00169 00170 00172 void ConnectionGroup::setToNeuronGroupID(unsigned id){ 00173 info.setToNeuronGroupID(id); 00174 } 00175 00176 00177 /*--------------------------------------------------------*/ 00178 /*------- PRIVATE METHODS -------*/ 00179 /*--------------------------------------------------------*/ 00180 00182 unsigned ConnectionGroup::getTemporaryID(){ 00183 return ++connectionIDCounter; 00184 } 00185