SpikeStream Nemo Plugin
0.2
|
00001 #ifndef NEMOWRAPPER_H 00002 #define NEMOWRAPPER_H 00003 00004 //SpikeStream includes 00005 #include "AbstractDeviceManager.h" 00006 #include "AbstractSimulation.h" 00007 #include "ArchiveDao.h" 00008 #include "ArchiveInfo.h" 00009 #include "NetworkDao.h" 00010 #include "ParameterInfo.h" 00011 #include "Pattern.h" 00012 #include "SpikeStreamTypes.h" 00013 00014 //Qt includes 00015 #include <QHash> 00016 #include <QMutex> 00017 #include <QThread> 00018 00019 //Nemo includes 00020 #include "nemo.h" 00021 00022 //Other includes 00023 #include <vector> 00024 using namespace std; 00025 00026 00027 namespace spikestream { 00028 00031 class NemoWrapper : public QThread, public AbstractSimulation { 00032 Q_OBJECT 00033 00034 public: 00035 NemoWrapper(); 00036 ~NemoWrapper(); 00037 void addDeviceManager(AbstractDeviceManager* deviceManager); 00038 void cancelLoading(); 00039 void cancelResetWeights(); 00040 void cancelSaveWeights(); 00041 void clearWaitForGraphics() { waitForGraphics = false; } 00042 unsigned getArchiveID() { return archiveInfo.getID(); } 00043 int getCurrentTask() { return currentTaskID; } 00044 QString getErrorMessage() { return errorMessage; } 00045 QList<neurid_t> getFiringNeuronIDs() { return firingNeuronList; } 00046 nemo_configuration_t getNemoConfig(){ return nemoConfig; } 00047 unsigned getSTDPFunctionID() { return stdpFunctionID; } 00048 timestep_t getTimeStep() { return timeStepCounter; } 00049 unsigned getUpdateInterval_ms() { return this->updateInterval_ms; } 00050 unsigned getWaitInterval_ms() { return waitInterval_ms; } 00051 bool isError() { return error; } 00052 bool isMonitorFiringNeurons() { return monitorFiringNeurons; } 00053 bool isMonitorWeights() { return monitorWeights; } 00054 bool isWaitForGraphics() { return waitForGraphics; } 00055 bool isWeightsReset() { return weightsReset; } 00056 bool isWeightsSaved() { return weightsSaved; } 00057 bool isSimulationLoaded() { return simulationLoaded; } 00058 bool isSimulationRunning(); 00059 void resetWeights(); 00060 void run(); 00061 void saveWeights(); 00062 void setArchiveMode(bool mode, const QString& archiveDescription = ""); 00063 void setFrameRate(unsigned int frameRate); 00064 void setInjectCurrent(unsigned neuronGroupID, double percentage, double current, bool sustain); 00065 void setFiringNeuronIDs(QList<neurid_t>& neurIDList); 00066 void setInjectCurrentNeuronIDs(QList<neurid_t>& neurIDList, double current); 00067 void setInjectNoise(unsigned neuronGroupID, double percentage, bool sustain); 00068 void setFiringInjectionPattern(const Pattern& pattern, unsigned neuronGroupID, bool sustain); 00069 void setCurrentInjectionPattern(const Pattern& pattern, float current, unsigned neuronGroupID, bool sustain); 00070 void setMonitor(bool mode); 00071 void setMonitorNeurons(bool firing, bool membranePotential); 00072 void setNemoConfig(nemo_configuration_t nemoConfig) { this->nemoConfig = nemoConfig; } 00073 void setMonitorWeights(bool enable); 00074 void setNeuronParameters(unsigned neuronGroupID, QHash<QString, double> parameterMap); 00075 void setSynapseParameters(unsigned connectionGroupID, QHash<QString, double> parameterMap); 00076 void setSTDPFunctionID(unsigned stdpFunctionID) { this->stdpFunctionID = stdpFunctionID; } 00077 void setSustainNoise(bool sustain) { this->sustainNoise = sustain; this->sustainCurrent = sustain; } 00078 void setSustainPattern(bool sustainPattern) { this->sustainPattern = sustainPattern; } 00079 void setUpdateFiringNeurons(bool updateFiringNeurons){ this->updateFiringNeurons = updateFiringNeurons; } 00080 void setWaitInterval(unsigned waitInterval_ms) { this->waitInterval_ms = waitInterval_ms; } 00081 void playSimulation(); 00082 void stepSimulation(); 00083 void stopSimulation(); 00084 void unloadSimulation(); 00085 00086 00088 00089 static const int NO_TASK_DEFINED = 0; 00090 00092 static const int RESET_WEIGHTS_TASK = 1; 00093 00095 static const int RUN_SIMULATION_TASK = 2; 00096 00098 static const int SAVE_WEIGHTS_TASK = 3; 00099 00101 static const int SET_NEURON_PARAMETERS_TASK = 4; 00102 00104 static const int STEP_SIMULATION_TASK = 5; 00105 00106 00107 signals: 00108 void progress(int stepsComplete, int totalSteps); 00109 void simulationStopped(); 00110 void timeStepChanged(unsigned int timeStep); 00111 void timeStepChanged(unsigned int timeStep, const QList<unsigned>& neuronIDList); 00112 void timeStepChanged(unsigned int timeStep, const QHash<unsigned, float>& membranePotentialMap); 00113 00114 00115 private slots: 00116 void updateProgress(int stepsComplete, int totalSteps); 00117 00118 00119 private: 00120 //====================== VARIABLES ======================== 00122 NetworkDao* networkDao; 00123 00125 ArchiveDao* archiveDao; 00126 00128 ArchiveInfo archiveInfo; 00129 00131 int currentTaskID; 00132 00134 bool simulationLoaded; 00135 00137 bool archiveMode; 00138 00140 bool monitorFiringNeurons; 00141 00144 bool monitorMembranePotential; 00145 00147 bool monitorWeights; 00148 00150 bool monitor; 00151 00153 bool updateFiringNeurons; 00154 00156 unsigned int timeStepCounter; 00157 00159 bool error; 00160 00162 QString errorMessage; 00163 00165 bool stopThread; 00166 00168 nemo_configuration_t nemoConfig; 00169 00171 nemo_simulation_t nemoSimulation; 00172 00174 unsigned updateInterval_ms; 00175 00177 unsigned waitInterval_ms; 00178 00181 bool waitForGraphics; 00182 00184 QMutex mutex; 00185 00187 QMutex runMutex; 00188 00190 unsigned stdpFunctionID; 00191 00193 QList<neurid_t> firingNeuronList; 00194 00197 QHash<unsigned, unsigned> injectNoiseMap; 00198 00200 bool sustainNoise; 00201 00206 QHash<unsigned, QPair<unsigned, double> > injectCurrentMap; 00207 00209 bool sustainCurrent; 00210 00212 QList<neurid_t> neuronIDsToFire; 00213 00215 QHash<neurid_t, double> neuronIDCurrentMap; 00216 00218 QHash<unsigned, float> membranePotentialMap; 00219 00224 QHash<unsigned, synapse_id*> volatileConGrpMap; 00225 00227 QList<unsigned> preSynapticNeuronIDs; 00228 00230 bool weightsSaved; 00231 00233 bool weightsReset; 00234 00236 bool weightSaveCancelled; 00237 00239 bool weightResetCancelled; 00240 00242 float stdpReward; 00243 00245 timestep_t applySTDPInterval; 00246 00248 unsigned neuronGroupID; 00249 00251 QHash<QString, double> neuronParameterMap; 00252 00254 vector<unsigned> injectionPatternVector; 00255 00257 vector<unsigned> injectionCurrentNeurIDVector; 00258 00260 vector<float> injectionCurrentVector; 00261 00263 bool sustainPattern; 00264 00266 unsigned patternNeuronGroupID; 00267 00269 QList<AbstractDeviceManager*> deviceManagerList; 00270 00271 00272 //====================== METHODS ======================== 00273 unsigned addInjectCurrentNeuronIDs(); 00274 unsigned addInjectFiringNeuronIDs(); 00275 void checkNemoOutput(nemo_status_t result, const QString& errorMessage); 00276 void clearError(); 00277 void fillInjectNoiseArray(unsigned*& array, int* arraySize); 00278 void getMembranePotential(); 00279 void loadNemo(); 00280 void resetNemoWeights(); 00281 void runNemo(); 00282 void saveNemoWeights(); 00283 void setError(const QString& errorMessage); 00284 void setExcitatoryNeuronParameters(NeuronGroup* neuronGroup); 00285 void setInhibitoryNeuronParameters(NeuronGroup* neuronGroup); 00286 void setNeuronParametersInNemo(); 00287 void stepNemo(); 00288 void unloadNemo(); 00289 void updateNetworkWeights(); 00290 }; 00291 00292 } 00293 00294 #endif//NEMOWRAPPER_H