123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- #ifndef _HPP_VCONNECTION
- #define _HPP_VCONNECTION
- #include <stdexcept>
- #include "connection.hpp"
-
- /**
- @page WeightFileFormatDescription Weight file format description
- - FileFormatStringLength (64 bit)
- - FileFormatString
- - FileData
- - File Data is Chunk based. Chunk has the following form:
- - Chunk Name Length: 1 byte
- - Chunk Name
- - Chunk Length: 64 bit integer
- - Chunk Data
- - HeaderChunk:
- - Chunk Name: "Header"
- - Chunk Length: 64 bit integer
- - NSource, NSx, NSy, NTarget, NTx, NTy
- - SourceNameLength, SourceName
- - TargetNameLength, TargetName
- - SourceNrChunk:
- - Chunk Name: „SourceNr“,
- - Chunk Length: 64 bit integer
- - sizeof(T_NNeurons)
- - Nweights,
- - SourceNr-Array
- - TargetNrChunk:
- - Chunk Name: „TargeteNr“,
- - Chunk Length: 64 bit integer
- - sizeof(T_NNeurons)
- - Nweights,
- - TargeteNr-Array
- - WeightsChunk:
- - Chunk Name: „Weights“
- - Chunk Length: 64 bit integer
- - sizeof(T_Weights)
- - NWeights
- - Weights-Array
- - DelaysChunk:
- - Chunk Name: „Delays“
- - Chunk Length: 64 bit integer
- - sizeof(T_Delays)
- - NWeights
- - Delays-Array
- */
- // forward declaration
- class VecNormalize;
- class layer;
- class Matrix4D;
- Connection* LoadConnection(const char* filename);
- // Zugriff auf vector <int> 10% - 15% schneller als Zugriff auf
- // Element von vector <class synapse>
- // daher SynWeights, SynSourceNr, ...
- class NotSupportedWithMemsave: public domain_error
- {
- public:
- explicit NotSupportedWithMemsave(const string& what_arg): domain_error(what_arg){};
- };
- class RequestedDelayTooLarge: public std::out_of_range
- {
- public:
- explicit RequestedDelayTooLarge (const std::string& what_arg): out_of_range(what_arg) {};
- explicit RequestedDelayTooLarge ()
- : std::out_of_range("requested Delay is larger than DMAX") {};
- explicit RequestedDelayTooLarge (long RequestedDelay)
- : std::out_of_range("requested Delay=" + stringify( RequestedDelay ) + " is larger than DMAX=" + stringify(DMAX)) {};
- };
- class RangeConnectionParameters: public ParameterSet
- {
- public:
- RangeConnectionParameters()
- : Range(0), Strength(0), MaxDelay(1), MinDelay(0), Cyclic(false), Connectivity(1)
- {}
- RangeConnectionParameters(float _Range, float _Strength)
- : Range(_Range), Strength(_Strength), Connectivity(1), MaxDelay(1), MinDelay(0), Cyclic(false)
- {}
- RangeConnectionParameters(float _Range,
- float _Strength,
- float _MaxDelay,
- float _MinDelay,
- float _Connectivity,
- bool _Cyclic)
- : Range(_Range),
- Strength(_Strength),
- MaxDelay(_MaxDelay),
- MinDelay(_MinDelay),
- Connectivity(_Connectivity),
- Cyclic(_Cyclic)
- {}
- float Range;
- float Strength;
- float MaxDelay;
- float MinDelay;
- float Connectivity;
- bool Cyclic;
- };
- /*! \brief Klasse VecConnection
- * Neu-Implementierung der connection mit std::vector statt c-Arrays
- *
- * Detailed description starts here.
- */
- class VecConnection : public Connection
- {
- friend class VecNormalize;
- protected:
- veclearning* learnobj;
- int Observe_s, Observe_m;
- string FileTypeString; // identifyer for loading weight file correctly (e.g. in IDL)
- public:
- VecConnection();
- VecConnection(layer*, layer*,
- csimInputChannel _InputChannel=csimInputChannel_AMPA, bool _nonself=true);
- ~VecConnection();
- virtual int proceede(int TotalTime);
- virtual int prepare(int TotalTime);
- int SetMinMaxDelay(float _MaxDelay, float _MinDelay);
- int SetupDelaysArray();
- int SetupPreSynNrArray();
- virtual int CleanupArrays();
- int SetRandomDelays();
- int DeleteSynapse(int SynNr);
- virtual void SetName(const char*);
-
- virtual int Save();
- virtual int Save(int nr);
- virtual int Save(const string&);
- virtual void Save_VecConnection_2_0(const string& SaveWeightFileName);
- virtual void Save_VecConnection_1_0(const string& SaveWeightFileName);
-
- int Load();
- int Load(const string& FileName);
- int Load(const string& FileName, const string& DirName);
- int Load_VecConnection_1_0(const string& FileNameWithDir);
- void Load_VecConnection_2_0(const string& FileName);
- void Load_VecConnection_2_1(const string& FileName);
-
- virtual long calcMemoryConsumption();
- float GetSourceWeights(int SourceNr, vector<float>& WeightMatrix);
- float GetSourceWeights(int SourceNr, vector<Synapse>& SynList, int& MaxDelay);
- float GetTargetWeights(int TargetNr, vector<float>& WeightMatrix);
- float GetTargetWeights(int TargetNr, vector<Synapse>& SynList, int& MaxDelay);
- float GetMaxWeight();
- float GetMinWeight();
- int GetMaxDelay();
-
- void GetWeightMatrix4D(Matrix4D& matrix);
- int DeleteLowWeights(float threshold);
- int SetAllWeights(float WeightValue);
- int MultiplyTargetWeights(int TargetNr, float Factor);
- int MultiplyAllTargetWeights(float Factor);
- int ScrambleSynTargets();
- float GetWeightSum(int TargetNr, bool quadratic);
- float GetMeanWeight();
- int Rewire(float minWeight, float maxConnectivity);
- virtual int WriteSimInfo(fstream &fw);
- virtual int WriteSimInfo(fstream &fw, const string &ChildInfo);
-
- int SetLearn(bool);
- int SetLearnObj(veclearning*);
-
- VecConnectionInfo GetConnectionInfo();
-
- virtual int DeleteSynapseArrays();
- virtual int PushBackNewSynapse(int SourceNr, int TargetNr, float Weight, int Delay);
- virtual int ReserveSynapses(int nsyn);
- int ConnectFull(float MaxWeight,
- float MaxDelay =20,
- float MinDelay =0,
- bool RandomWeights=false);
- int ConnectRandomIncomming(double _connectivity,
- float _InitialWeights,
- float _maxDelay=20,
- float minDelay=0,
- bool RandomDelays=true);
- int ConnectRandomIncomming(int _NIncommingConnections,
- float _InitialWeights,
- float _maxDelay=20,
- float minDelay=0,
- bool RandomDelays=true);
- int ConnectSelf(float MaxWeight, float MaxDelay =20, float MinDelay =0);
- int ConnectGaussian(float Sigma, float MaxWeight,
- float MaxDelay =20, float MinDelay=0, bool Cyclic=false);
- void ConnectCircular(const RangeConnectionParameters& Paras);
- // Delay-Typen als enum: random, distance-dependent (todo?)
- int SetNewWeights(float IncommingConnectivity, float InitialWeights);
- int SetNewWeights(vector<int>* NNewWeights, float InitialWeights);
-
- bool hasEqualSynapses(const VecConnection& OtherVecCon);
-
- protected:
- void updateNSynapses();
-
- /** @brief number of valid synapses\n (!=SynWeights.size(),
- because deleted synapses are still stored in thevectors)
- */
- int NSynapses;
- vector <float> SynWeights; //!< strength of synaptic weights
- vector <T_NNeurons> SynTargetNr; //!< index of target neuron
- vector <T_NNeurons> SynSourceNr; //!< index of source neuron
- vector <T_Delays> SynDelays; //!< synaptic delay of the synapse.
- //!< If synapse i is deleted, SynDelays[i]==-1
- //! helper array for finding all synapses of a postsynaptic neuron
- vector < vector <T_NSynapses> > PreSynNr;
-
- //! helper array for finding all synapses with a given SourceNr and DelayIndex
- //! delays[SourceNr][DelayIndex][Index] == SynapseNr //
- vector < vector <vector <T_NSynapses> > > delays;
- };
- /*! \brief Klasse VecDepressiveConnection
- *
- *
- * Depressive Synapses
- * Tsodyks M, Pawelzik K, Markram H.
- * Neural networks with dynamic synapses.
- * Neural Comput. 1998 May 15;10(4):821-35.
- */
- class VecDepressiveConnection : public VecConnection
- {
- protected:
- float U_se_fac; //!< efficacy reduction factor after transmitter release (after spike)
- float U_SE; //!< proportion of transmitter per spike
- float TauRec; //!< recovery dynamics in ms
- float E0; //!< initialize Efficacy;
- public:
- VecDepressiveConnection(
- layer*, layer*, csimInputChannel =csimInputChannel_AMPA,
- float _TauRec=20, float U_se=0.2, float InitializeFrequency=0);
- // ~VecDepressiveConnection(); // es werden keine dynamischen Objekte angelegt, daher kein Destruktor noetig
- virtual int DeleteSynapseArrays();
- virtual int PushBackNewSynapse(int SourceNr, int TargetNr, float Weight, int Delay);
- virtual int ReserveSynapses(int nsyn);
- virtual int proceede(int =0);
- virtual int prepare(int =0);
- virtual int reset(int t);
- virtual void SetParameter(ParaType p, double value);
- virtual int WriteSimInfo(fstream &fw);
- virtual float InitializeEfficacy(float frequency);
- vector <int> LastEpsp;
- vector <float> Efficacy;
- virtual long calcMemoryConsumption();
-
- };
- #endif /*_HPP_VCONNECTION */
|