9 #include "CsNeuralModule.h"
10 #include "CsClassFactory.h"
46 {
Std_TraceMsg(0,
"Caught Error in desctructor of CsNeuralModule\r\n",
"", -1,
false,
true);}
51 void CsNeuralModule::SimMode(
int iMode)
59 int CsNeuralModule::SimMode() {
return m_iSimMode;}
71 unsigned int iInterval = 1;
73 iInterval = (
unsigned int) ((((float) (CARLSIM_STEP_SIZE*CARLSIM_STEP_INCREMENT)) /
m_lpSim->MinTimeStep())+0.5);
95 CStdMap<std::string, CsConnectionGenerator *>::iterator oPos;
99 lpItem = oPos->second;
101 THROW_TEXT_ERROR(Cs_Err_lConnectionGeneratorIDNotFound, Cs_Err_strConnectionGeneratorIDNotFound,
" Connection Generator ID: " + strID);
118 for(
int iIndex=0; iIndex<iCount; iIndex++)
139 for(
int iIndex=0; iIndex<iCount; iIndex++)
144 THROW_TEXT_ERROR(Cs_Err_lNeuronNotFound, Cs_Err_strNeuronNotFound,
"ID");
149 void CsNeuralModule::SetCARLSimulation()
161 m_lpSNN->setStepFeedback(
this);
165 for(
int iIndex=0; iIndex<iCount; iIndex++)
171 for(
int iIndex=0; iIndex<iCount; iIndex++)
177 CStdPtrMap<std::string, CsConnectionGenerator>::iterator oPos;
180 lpGen = oPos->second;
181 lpGen->SetCARLSimulation();
202 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
209 void CsNeuralModule::updateMonitors(
CpuSNN* s,
int step)
217 WaitForPhysicsToCatchUp();
220 void CsNeuralModule::WaitForPhysicsToCatchUp()
241 void CsNeuralModule::WaitForNeuralToCatchUp()
245 while(m_fltNeuralTime <= m_lpSim->Time())
264 void CsNeuralModule::CloseThread()
282 NeuralModule::SimStarting();
298 NeuralModule::SimStopping();
305 NeuralModule::ResetSimulation();
312 for(
int iIndex=0; iIndex<iCount; iIndex++)
317 for(
int iIndex=0; iIndex<iCount; iIndex++)
324 NeuralModule::Initialize();
326 Organism *lpOrganism =
dynamic_cast<Organism *
>(
m_lpStructure);
328 THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType,
"Organism");
331 for(
int iIndex=0; iIndex<iCount; iIndex++)
336 for(
int iIndex=0; iIndex<iCount; iIndex++)
343 NeuralModule::StepSimulation();
346 WaitForNeuralToCatchUp();
349 #pragma region DataAccesMethods
355 if(NeuralModule::SetData(strDataType, strValue,
false))
358 if(strType ==
"TIMESTEP")
364 if(strType ==
"SIMMODE")
366 SimMode(atoi(strValue.c_str()));
372 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
377 void CsNeuralModule::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
379 NeuralModule::QueryProperties(aryProperties);
381 aryProperties.Add(
new TypeProperty(
"TimeStep", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
382 aryProperties.Add(
new TypeProperty(
"SimMode", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
396 oXml.Deserialize(strXml);
397 oXml.FindElement(
"Root");
398 oXml.FindChildElement(
"NeuronGroup");
435 THROW_ERROR(Cs_Err_lSynapseToAddNull, Cs_Err_strSynapseToAddNull);
450 oXml.Deserialize(strXml);
451 oXml.FindElement(
"Root");
452 oXml.FindChildElement(
"Synapse");
470 THROW_ERROR(Std_Err_lInvalidIndex, Std_Err_strInvalidIndex);
502 THROW_ERROR(Std_Err_lInvalidIndex, Std_Err_strInvalidIndex);
522 for(
int iIndex=0; iIndex<iCount; iIndex++)
527 THROW_TEXT_ERROR(Cs_Err_lSynapseNotFound, Cs_Err_strSynapseNotFound,
"ID");
556 if(strType ==
"NEURONGROUP")
561 else if(strType ==
"SYNAPSE")
570 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
579 if(strType ==
"NEURONGROUP")
584 else if(strType ==
"SYNAPSE")
593 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
601 void CsNeuralModule::Load(CStdXml &oXml)
616 TRACE_DEBUG(
"Finished loading nervous system config file.");
629 short iNeuron, iTotalNeurons;
636 SimMode(oXml.GetChildInt(
"SimMode",
m_iSimMode));
642 oXml.IntoChildElement(
"NeuronGroups");
644 iTotalNeurons = oXml.NumberOfChildren();
645 for(iNeuron=0; iNeuron<iTotalNeurons; iNeuron++)
647 oXml.FindChildByIndex(iNeuron);
655 if(oXml.FindChildElement(
"Synapses",
false))
659 int iCount = oXml.NumberOfChildren();
660 for(
int iIndex=0; iIndex<iCount; iIndex++)
662 oXml.FindChildByIndex(iIndex);
691 strType = oXml.GetChildString(
"Type");
696 THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType,
"Neuron");
699 lpNeuron->Load(oXml);
704 catch(CStdErrorInfo oError)
706 if(lpNeuron)
delete lpNeuron;
712 if(lpNeuron)
delete lpNeuron;
713 THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
736 strType = oXml.GetChildString(
"Type");
741 THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType,
"Synapse");
744 lpSynapse->Load(oXml);
749 catch(CStdErrorInfo oError)
751 if(lpSynapse)
delete lpSynapse;
757 if(lpSynapse)
delete lpSynapse;
758 THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
Contains the classes for a firing rate neural model.
CStdArray< Adapter * > m_arySourceAdapters
An array of source adapters for this module.
virtual bool stepUpdate(CpuSNN *s, int step)
virtual int FindSynapseListPos(std::string strID, bool bThrowError=true)
Searches for a synapse with the specified ID and returns its position in the list.
virtual bool AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
Adds a new object to this parent.
virtual void Kill(bool bState=true)
Kills.
virtual float TimeStep()
Gets the time step for this moudle in time units.
virtual void Initialize()
Initializes this object.
void LoadNetworkXml(CStdXml &oXml)
Loads the network configuration.
virtual void StepThread()
This method is called from within the IO thread. It calls StepIO for each part.
IStdClassFactory * m_lpClassFactory
The pointer to the class factory for this module.
virtual std::string Type()
returns the string type name of this object.
virtual unsigned int SimulationStepInterval()
Tells the number of simulation steps that other components, like stimuli, will need to use for their ...
Simulator * m_lpSim
The pointer to a Simulation.
CsNeuronGroup * LoadNeuronGroup(CStdXml &oXml)
Loads a neuron.
virtual void RemoveNeuronGroup(std::string strID, bool bThrowError=true)
Removes the neuron with the specified ID.
virtual bool Paused()
Gets whether the Simulation is paused.
virtual std::string ID()
Gets the unique GUID ID of this object.
virtual void ClearSynapses()
Clears the synapses list.
int runNetwork(int _nsec, int _tstep=0, int simType=CPU_MODE, int ithGPU=0, bool enablePrint=false, int copyState=false)
run the simulation for n sec simType can either be CPU_MODE or GPU_MODE ithGPU: specify on which CUDA...
virtual CStdPtrArray< CsSynapseGroup > * GetSynapses()
Gets a pointer to the synapses array.
bool m_bPauseThread
Set to true to pause the thread processing. Set back to false to resume it.
virtual void AddSynapse(CsSynapseGroup *lpSynapse)
Adds a synapse to this module.
virtual std::string ModuleName()
Gets the module name.
CStdPtrArray< CsSynapseGroup > m_arySynapses
The array of synapses in this module.
virtual void RemoveSynapse(int iIndex)
Removes the synapse described by iIndex.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
std::string m_strID
The unique Id for this object.
bool m_bWaitingForNeuralToCatchUp
True if the physics simulation has finished and is waiting on the neural sim to catch up...
Firing rate synapse model.
std::string Std_Trim(std::string strVal)
Trims a string.
virtual CStdSerialize * CreateObject(std::string strModule, std::string strClassName, std::string strType, bool bThrowError=true)
Creates an object using a class factory.
virtual void Initialize()
Initializes this object.
CStdArray< Adapter * > m_aryTargetAdapters
An array of target adapters for this module.
virtual std::string Name()
Gets the name of this object.
virtual void Initialize()
Initializes this object.
float m_fltNeuralTime
The current time of the neural simulation.
virtual void SimStopping()
Called just before the simulation stops.
virtual bool RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError=true)
Removes a child item from this parent.
virtual void StepSimulation()
Step the simulation for this object.
Firing Rate Neuron model.
int m_iSimMode
The mode of the simulation. GPU vs CPU.
virtual void ResetSimulation()
Resets the simulation back to time 0.
CpuSNN * m_lpSNN
Pointer to the CARLsim simulator.
virtual int FindNeuronGroupListPos(std::string strID, bool bThrowError=true)
Searches for the neuron with the specified ID and returns its position in the list.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual int TotalSynapses()
Gets the total number of synapses.
CStdPtrMap< std::string, CsConnectionGenerator > m_aryGenerators
bool m_bThreadProcessing
True while the io thread processing loop is going on.
Firing rate neural module class factory.
bool m_bWaitingForPhysicsToCatchUp
True if the neural simulation has finished and is waiting on the physics sim to catch up...
CsNeuralModule()
Default constructor.
Firing rate synapse model.
bool m_bStopThread
Flags the thread processing loop to exit.
virtual ~CsNeuralModule()
Destructor.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void AddNeuronGroup(std::string strXml, bool bDoNotInit=false)
Adds a neuron to the module.
virtual CsConnectionGenerator * FindConnectionGenerator(std::string strID, bool bThrowError=true)
Searches for an item with the specified ID and sets its index in the array.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
CStdPtrArray< CsNeuronGroup > m_aryNeuronGroups
The array of neuron groups in this module.
virtual CsSynapseGroup * GetSynapse(int iIndex)
Gets a synapse by its index in the array.
bool m_bThreadPaused
Is set to true once the thread loop is paused.
float m_fltTimeStep
The DT time step for this neural module in seconds.
virtual float Time()
Gets the current simulation time in seconds.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
std::string m_strType
The type for this object. Examples are Box, Plane, Neuron, etc..
virtual void AddToObjectList(AnimatBase *lpItem)
Adds an object to the list of all simulation objects.
CsSynapseGroup * LoadSynapse(CStdXml &oXml)
Loads a synapse.
Contains all of CARLsim's core functionality.
virtual void SimStarting()
When the simulation is starting we need to configure our NN and start our processing thread...
std::string m_strName
The name for this object.
virtual void ShutdownThread()
This method is called just before the IO thread is closed down. It gives the IO objects a chance to d...