123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- #ifndef _HPP_CONNECTION
- #define _HPP_CONNECTION
- #include "simelement.hpp"
-
-
- // forward declaration
- class layer;
- class learning;
- struct Synapse
- {
- Synapse(int snr, int tnr, float w, int d): Weight(w), SourceNr(snr), TargetNr(tnr), Delay(d) {};
- float Weight;
- int SourceNr;
- int TargetNr;
- int Delay;
- };
- struct SourceTargetDim
- {
- SourceTargetDim()
- : NSource(0), NSx(0), NSy(0), NTarget(0), NTx(0), NTy(0)
- {}
- SourceTargetDim(int _NSource, int _NSx, int _NSy, int _NTarget, int _NTx, int _NTy)
- : NSource(_NSource), NSx(_NSx), NSy(_NSy), NTarget(_NTarget), NTx(_NTx), NTy(_NTy)
- {}
- std::string stringify()
- {
- std::stringstream o;
- o << NSource << " " << NSx << " " << NSy << " " << NTarget << " " << NTx << " " << NTy;
- return o.str();
- }
- int NSource;
- int NSx;
- int NSy;
- int NTarget;
- int NTx;
- int NTy;
- };
- /** like SourceTargetDim plus one new item: ArrayOrderXFast
- */
- struct SourceTargetDim1
- {
- SourceTargetDim1()
- : NSource(0), NSx(0), NSy(0), NTarget(0), NTx(0), NTy(0)
- {}
- SourceTargetDim1(int _NSource, int _NSx, int _NSy, int _NTarget, int _NTx, int _NTy)
- : NSource(_NSource), NSx(_NSx), NSy(_NSy), NTarget(_NTarget), NTx(_NTx), NTy(_NTy)
- {}
- std::string stringify()
- {
- std::stringstream o;
- o << NSource << " " << NSx << " " << NSy << " " << NTarget << " " << NTx << " " << NTy << " " << ArrayOrderXFast;
- return o.str();
- }
- int NSource;
- int NSx;
- int NSy;
- int NTarget;
- int NTx;
- int NTy;
- int ArrayOrderXFast;
- };
- /*! \brief Klasse Connection
- * abstrakte Basis-Klasse für connection und VecConnection
- *
- * Detailed description starts here.
- */
- class Connection : public SimElement
- {
- protected:
- layer *TargetLayer, *SourceLayer;
- float *InputPointer;
- std::string WeightFileName;
- float connectivity;
- float Strength;
- float InitialWeight; // for rewiring
- bool AutoSave;
- bool learn;
- bool RewireOn;
- float RewireMaxConnectivity;
- float RewireNNewConnections;
- float RewireThreshold;
- clock_t cpu_start, cpu_end;
- double cpu_time_used;
- public:
- Connection();
- Connection(layer*, layer*, csimInputChannel _InputChannel=csimInputChannel_AMPA, bool _nonself=true);
- ~Connection();
- virtual int Save()=0;
- virtual int Save(int nr)=0;
- virtual int Save(const string&)=0;
- virtual bool Learning();
- virtual int SetLearn(bool) =0;
- virtual int DeleteLowWeights(float threshold) =0;
- virtual int SetAllWeights(float WeightValue) {};
- virtual int MultiplyAllTargetWeights(float Factor) {cout << "not implemented\n";};
- // BEGIN used by TomWaitsQt
- virtual float GetSourceWeights(int CurSource, vector<Synapse>& SynList, int &MaxDelay)=0;
- virtual float GetTargetWeights(int CurTarget, vector<Synapse>& SynList, int &MaxDelay)=0;
- virtual float GetMaxWeight()=0;
- virtual int GetMaxDelay()=0;
- virtual float GetMinWeight(){return 0;};
- virtual int GetMinDelay(){return 0;};
- virtual long calcMemoryConsumption(){return 0;};
- // END used by TomWaitsQt
-
- virtual bool CheckHeaderConsistency();
- int SetRewiring(float threshold, float maxCon, int NNewCon=1, float _InitialWeight=-1);
- void SetRewiringOff();
- int SetAutoSave(bool);
- void SetNonSelf(bool);
- // virtual int WriteSimInfo(fstream &fw) =0;
- // virtual int WriteSimInfo(fstream &fw, const string &ChildInfo) =0;
- layer* GetTargetLayer();
- int GetNTarget() {return nt;};
- int GetNSource() {return ns;};
- void GetSourceTargetDim(unsigned int& snx, unsigned int& sny, unsigned int& tnx, unsigned int& tny)
- {snx=SourceNx;sny=SourceNy;tnx=TargetNx;tny=TargetNy;};
- SourceTargetDim GetSourceTargetDim()
- {
- return SourceTargetDim(ns, SourceNx, SourceNy, nt, TargetNx, TargetNy);
- }
-
-
- bool NonSelf;
- csimInputChannel InputChannel;
- T_Delays Dmax; // global maximum delay
- T_Delays maximumDelay; // maximum delay of current delay distribution
- T_Delays minimumDelay; // minimum delay of current delay distribution
- T_Delays DelayDiff;
- bool ArrayOrderXFast;
- protected:
- int ns,nt;
- int SourceNx, SourceNy, TargetNx, TargetNy;
- float maxWeight;
- };
- /*! \brief Klasse connection
- * "alte" connection-Klasse, benutzt selbst generierte, mehrdimensionale c-Arrays
- *
- * Detailed description starts here.
- */
- class connection : public Connection
- {
- protected:
- learning* learnobj;
- int SetupPresynapticInfo_old();
- int SetupPresynapticInfo();
- int DeletePresynapticInfo();
- int CheckPresynapticInfo_old();
- int SetMinMaxDelay(float _MaxDelay, float _MinDelay);
- virtual int InitializeDynamicalArrays(
- const int _N, const int _M, const int Dmax);
- int DeleteDynamicalArrays();
- int Observe_s, Observe_m;
- public:
- connection(layer*, layer*, csimInputChannel _InputChannel=csimInputChannel_AMPA, bool _nonself=true);
- connection();
- ~connection();
- virtual int Save();
- virtual int Save(int nr);
- virtual int Save(const string&);
- float GetSourceWeights(int CurSource, vector<Synapse>& SynList, int &MaxDelay);
- float GetTargetWeights(int CurTarget, vector<Synapse>& SynList, int &MaxDelay);
- float GetMaxWeight();
- int GetMaxDelay();
-
- virtual bool CheckHeaderConsistency();
- int Load();
- int Load(const char* FileName);
- int Load(const char* FileName, const char* DirName);
- int ConnectMatrix(const vector<vector<float> > &WeightMatrix,
- float MaxDelay =20, float MinDelay=0);
- int ConnectRandom(float _connectivity,
- float _InitialWeights,
- float _maxDelay=20,
- float minDelay=0,
- bool RandomDelays=true);
- int ConnectRandom2(float _Connectivity,
- float _InitialWeights,
- float _maxDelay=20,
- float minDelay=0,
- bool RandomDelays=true);
- int ConnectRandom2(int NIncommingConnections,
- float _InitialWeights,
- float _maxDelay=20,
- float minDelay=0,
- bool RandomDelays=true);
- int ConnectPartialRandom(float _connectivity, float InitialWeights,
- int MaxTarget, int MaxSource, float =20, float =0);
- int ConnectDirectional(float, float);
- int ConnectGaussianProb(float Sigma, float MaxWeight,
- float MaxDelay =20, float MinDelay=0,
- float MinConDistance=0, float MaxConnectivity=1, bool Cyclic=false);
- int ConnectGaussian(float Sigma,
- float MaxWeight,
- float MaxDelay =20,
- float MinDelay=0,
- bool Cyclic=false);
- int ConnectGaussianColumnwise(float Sigma,
- float MaxWeight,
- int dimx,
- int dimy,
- bool Cyclic=false,
- bool Shifted=true,
- float MaxDelay =20,
- float MinDelay=0,
- bool divergent=true,
- bool notstraight=true);
- int ConnectIdenticalGaussian(float Sigma,
- float MaxWeight,
- float MaxDelay =20,
- float MinDelay=0,
- float mpx=0.5,
- float mpy=0.5);
- int ConnectProfile(DistanceProfile* profile,
- float MaxWeight,
- float MaxDelay =20,
- float MinDelay=0,
- bool Cyclic=false);
- int ConnectCircular(float PreConnectivity,
- float MaxWeight,
- float MaxDelay =20,
- float MinDelay=0);
- int ConnectCircularPre(float Connectivity,
- float MaxWeight,
- float MaxDelay =20,
- float MinDelay=0);
- int ConnectFull(float MaxWeight,
- float MaxDelay =20,
- float MinDelay =0,
- bool RandomWeights=false);
- int ConnectFullColumnwise(float MaxWeight,
- int dimx,
- int dimy,
- int sourcedimx,
- int sourcedimy,
- float MaxDelay =20,
- float MinDelay =0,
- bool divergentrow=false,
- float sigma_divrow=0.1,
- bool Cyclic=false,
- bool convergent=false);
-
- int ConnectGradientFields(float MaxWeight=1,
- float xslope=0.5,
- float yslope=0.5,
- int dimx=50,
- int dimy=50,
- int sourcedimx=50,
- int sourcedimy=50,
- float MaxDelay =20,
- float MinDelay =0);
- int ConnectSelf(float MaxWeight,
- float MaxDelay =20,
- float MinDelay =0);
- int ConnectPartial(int maxTarget,
- float MaxWeight,
- float MaxDelay =20,
- float MinDelay =0);
- int CheckPresynapticInfo();
- int CheckConnection();
- int DeleteWeight(int SourceNr, int ConnectionNr);
- int DeleteWeightCorrectPreInfo(int SourceNr, int ConnectionNr, int SupposedDelay=-1); // not tested
- int SetSystematicWeights(); // for test purpose only
- int CheckSystematicWeights(); // for test purpose only
- virtual int DeleteLowWeights(float threshold);
- int InsertNewWeight(int SourceNr, int TargetNr, float InitialWeight=0, int delay=1);
- int SetNewWeights(int NNewTargets, int NMaxTargets);
- int SetNewWeights2(int NNewTargets, int NMaxTargets);
- int Rewire(float minWeight, float maxConnectivity);
- int Print();
- int SetWeights(vector<vector<float> >& );
- int SetupDelays(float MaxDelay,float MinDelay=0);
- int SetupDelays();
- int SetupRandomDelays(float MaxDelay, float minDelay=0);
- int SetupRandomDelays();
- virtual int proceede(int =0);
- virtual int prepare(int =0);
- virtual void SetName(const char*);
- int SetFileName(char*);
- virtual int SetLearn(bool);
- int SetLearnObj(learning*);
- int ObserveSynapse(int SourceNumber=0, int MNumber=0, char* RecName="synapse.txt");
- int ObserveSynapsePrePost(int SourceNumber=0, int TargetNumber=0, char* RecName="synapse.txt");
- virtual int StartBinRec(int PostsynNum);
- ConnectionInfo GetConnectionInfo();
- virtual int WriteSimInfo(fstream &fw);
- virtual int WriteSimInfo(fstream &fw, const string &ChildInfo);
-
- int M,maxN_pre;
-
- /// limitation: all presynaptic neurons have the same number of target neurons (M!) ??
- /// not true!! --> no delay, no cry!!
-
- int *N_post; // number of synapses per presynaptic neuron;
- int **post; // 2D-Array with indices of target neurons. TargetNr=post[SourceNr][index]
- float **s; // 2D-Array with weight strenghes. weight=s[SourceNr][index]
- float **sd;
- short **delays_length;
- short ***delays;
- int *N_pre;
- int **I_pre, **D_pre;
- int **m_pre; // presynaptic connection index m in s[i][m] array
- pfloat **s_pre, **sd_pre;
- };
- /*! \brief Klasse DepressiveConnection
- * "alte" connection-Klasse, benutzt selbst generierte, mehrdimensionale c-Arrays
- *
- * Depressive Synapses
- * Tsodyks M, Pawelzik K, Markram H.
- * Neural networks with dynamic synapses.
- * Neural Comput. 1998 May 15;10(4):821-35.
- */
- class DepressiveConnection : public connection
- {
- protected:
- float U_se_fac; // (proportion of transmitter per spike)
- float U_SE;
- float TauRec; //recovery dynamics
- float **efficacy; // for every synapse
- int **LastEpsp; // for every synapse
- public:
- DepressiveConnection(
- layer*, layer*, csimInputChannel =csimInputChannel_AMPA,
- float _TauRec=20, float U_se=0.2);
- ~DepressiveConnection();
- /* boost::multi_array<float,2> efficacy; */
- /* boost::multi_array<int,2> LastEpsp; */
- virtual int proceede(int =0);
- virtual int prepare(int =0);
- virtual int reset(int t);
- virtual int InitializeDynamicalArrays(
- const int _N, const int _M, const int Dmax);
- virtual int WriteSimInfo(fstream &fw);
- };
- /*! \brief Klasse Facilitatory Synapses
- * Tsodyks M, Pawelzik K, Markram H.
- *
- * Tsodyks M, Pawelzik K, Markram H.
- * Neural networks with dynamic synapses.
- * Neural Comput. 1998 May 15;10(4):821-35.
- *
- * could be made faster if only one U_SE value per presynaptic neuron
- * instead one per synapse
- */
- class FacilitativeConnection : public DepressiveConnection
- {
- protected:
- float **U_SEvalue;
- float UseTauDec, UseInc, UseConst;
- public:
- FacilitativeConnection(
- layer*, layer*, csimInputChannel =csimInputChannel_AMPA,
- float _TauRec=20, float U_se=0.2, float _TauFac=20, float _UseInc=0.01);
- ~FacilitativeConnection();
- virtual int proceede(int =0);
- virtual int reset(int t);
- virtual int StartBinRec(int PostsynNum);
- virtual int InitializeDynamicalArrays(
- const int _N, const int _M, const int Dmax);
- };
- class PspConnection : public connection
- {
- protected:
- float *PspTemplate;
- float **Psp;
- int PspDuration;
- int PspArrayPointer;
- public:
- PspConnection(layer*, layer*, csimInputChannel InputChannel = csimInputChannel_AMPA, bool _nonself=true);
- ~PspConnection();
- /* ~PspConnection(); */
- /* virtual int proceede(int =0); */
- /* virtual int prepare(int =0); */
- };
- #endif /*_HPP_CONNECTION */
|