123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- /*Copyright (C) 2005, 2006, 2007, 2008 Frank Michler, Philipps-University Marburg, Germany
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- #ifndef _H_LIBCSIM
- #define _H_LIBCSIM
- #include "libvector.h"
- #include <vector>
- #include <cassert>
- #include "anyoption.h"
- #include <time.h>
- #include <sys/stat.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <stdexcept>
- #include <fstream>
- #include <map>
- #include "lut.hpp"
- #include "typedefs.hpp"
- #include "stringutils.h"
- //#include <idlrpc/idl_rpc.h>
- using namespace std;
- inline string AddSpaces(const string &st)
- {
- string Spaces = " ";
- string out=st;
- string::size_type i;
- out.replace(0,0,Spaces);
- i=0;
- i = out.find("\n", i+1);
- while (i != string::npos) {
- if (i+1 < out.size()) out.replace(i+1, 0, Spaces);
- i = out.find("\n", i+1);
- }
- return out;
- }
- #define getrandom(max1) ((rand()%(int)((max1)))) // random integer between 0 and max-1
- #define ExpDec(t) (LutExpDec(int(t)))
- const int NLutExpDec=100000;
- const float TauLut=NLutExpDec/10;
- static LUT_function<0, NLutExpDec> LutExpDec(exp,-1./(TauLut));
- //define lookup table for NMDA current
- inline double NmdaCurrent(double Voltage)
- {
- // from Deco&Rolls 2005
- // (they cite Jahr and Stevens 1990).
- return -0.327*Voltage/(1+exp(-0.062*Voltage)/3.57);
- }
- const int NLutNmda=10000;
- const float NmdaV0=-200;
- const float NmdaV1=50;
- const float NmdaVRange=NmdaV1-NmdaV0;
- const float NmdaVToIntFactor=NLutNmda/NmdaVRange;
- const float NmdaIntToVFactor=NmdaVRange/NLutNmda;
- //!static LUT_function<int(NmdaV0*NmdaVToIntFactor), int(NmdaV1*NmdaVToIntFactor)>
- static LUT_function<-8000, 2000> LutNmdaCurrent(NmdaCurrent,0.0250000);
- // FixMe clean up this, converted const expressions into literals after
- // transition to debian etch g++ 4.1.2
- #define INmda(v) (LutNmdaCurrent(int(NmdaVToIntFactor*v)))
- double gauss(double x, double sigma=1, double x0=0);
- int fexist(const char *filename );
- int FileSize(const char *filename );
- // alpha function: f(t) = t*exp(-t/tau)/(tau/e)
- inline float* AlphaFktLut(
- int &N, float TauPeak=10, float Amp=1, float BaseLine=0, float dt=0.25)
- {
- float Bound = 10*TauPeak;
- N = int(Bound/dt);
- float* Lut = new float [N];
- float Em1 = exp(-1.0); // 1/e
- for (int n=0;n<N;++n) {
- Lut[n] = BaseLine + Amp*n*dt*exp(-n*dt/TauPeak)/(TauPeak*Em1);
- }
- return Lut;
- }
- // exp decay function
- inline float* ExpDecayLut(
- int &N, float TauDecay=10, float Amp=1, float BaseLine=0, float dt=0.25, float BoundFkt=5)
- {
- float Bound = BoundFkt*TauDecay;
- N = int(Bound/dt);
- float* Lut = new float [N];
- for (int n=0;n<N;++n) {
- Lut[n] = BaseLine + Amp*exp(-n*dt/TauDecay);
- }
- return Lut;
- }
- inline const char* testfunction()
- {
- return "Hallo Welt\n";
- }
- inline vector<vector2d> Rectangle(float x0, float x1, float y0, float y1, int N)
- {
- vector<vector2d> tmp;
- if (N>=4)
- {
- float circumference =2*(x1+y1-x0-y0);
- float corners [4] = {0, x1-x0, circumference/2, circumference-(y1-y0)};
- // float corners[4] = {3,3,3,3};
- float CurMP=0;
- float StepSize=circumference/(N);
- while ((circumference-CurMP)>(StepSize/2))
- {
- cout << "CurMP=" << CurMP << " circ=" << circumference << "diff=" << circumference-CurMP << "\n";
- if (CurMP< corners[1]) tmp.push_back(vector2d(x0 + CurMP, y0));
- else if (CurMP<corners[2]) tmp.push_back(vector2d(x1, y0+CurMP-(corners[1])));
- else if (CurMP<corners[3]) tmp.push_back(vector2d(x1- (CurMP - corners[2]), y1));
- else tmp.push_back(vector2d(x0, y0+(circumference-CurMP)));
- CurMP += StepSize;
- }
- }
- return tmp;
- }
- typedef float* pfloat;
- template<class T>
- T** NewArray2d(T** &temp, int a, int b)
- {
- temp = new T*[a];
- for (int i=0; i<a;++i) temp[i] = new T[b];
- }
- template<class T>
- int DeleteArray2d(T** &ArrayPointer, int a)
- {
- int i;
- for (i=0; i<a;++i) delete []ArrayPointer[i];
- delete []ArrayPointer;
- return 0;
- }
- template<class T>
- T*** NewArray3d(T*** &temp, int a, int b, int c)
- {
- temp = new T**[a];
- for (int i=0; i<a;++i)
- {
- temp[i] = new T*[b];
- for (int j=0;j<b;++j) temp[i][j] = new T[c];
- }
- }
- template<class T>
- int DeleteArray3d(T*** &ArrayPointer, int a, int b)
- {
- int i,j;
- for (i=0;i<a;++i)
- {
- for (j=0;j<b;++j) delete [] ArrayPointer[i][j];
- delete [] ArrayPointer[i];
- }
- delete []ArrayPointer;
- return 0;
- }
- enum LookUpType {loNONE, loEXP, loNMDA};
- class LookUpTable
- {
- protected:
- float xRange0, xRange1, RDiff;
- int LBound, UBound;
- float IndexFactor;
- public:
- float* tmpvalue;
- float* value;
- int N;
- LookUpTable();
- ~LookUpTable();
- void InitExp(int N, float Tau, float v0=1, float Range0=0, float Range1=0);
- float GetValue(int index);
- double GetValue(double X);
- void Reset();
- };
- class Recorder
- {
- FILE* fs;
- string FileName;
- public:
- Recorder(char* ="data.txt");
- ~Recorder();
- int record(float, float);
- int record(float, float, float);
- };
- typedef struct _BinRecHeader
- {
- char finfo[7]; // "BinRec" + \0
- char version[5]; // "0.05" + \0
- int N, M, ValueSize, FrameSize;
- float dt;
- } BinRecHeader;
- enum ParaType {
- PARA_U_SE,
- PARA_TAU_REC,
- };
- class BinRecorder
- {
- FILE* fs;
- string FileName;
- string BaseFileName;
- string SimTag;
- float** PBuffer;
- float* RecBuffer;
- float* RecBuffPointer;
- float* RecBuffMax;
- int N, M;
- int MacroTimeStep;
- BinRecHeader Header;
- public:
- BinRecorder(int _MacroTimeStep, int _N, int _M, float** _PBuffer, float _dt=0.25, const char* ="data.bin");
- ~BinRecorder();
- int record();
- int restart();
- int restart(string _SimTag);
- int WriteToFile();
- };
- class DistanceProfile
- {
- protected:
- int N;
- float* profile;
- float* xscale;
- public:
- DistanceProfile(int N);
- DistanceProfile(int N, float Sigma1, float Sigma2);
- DistanceProfile(const vector<float> &Profile);
- ~DistanceProfile();
- float GetValue(float dist);
- float GetMaxConDistance(float minweight);
- void print();
- };
- class CircleDistanceProfile: public DistanceProfile
- {
- public:
- CircleDistanceProfile(int N, float Radius, bool invers=false);
- };
- enum DirType {CSIM_left=-1, CSIM_right=1};
- /** @brief input channels
- */
- enum csimInputChannel {
- csimInputChannel_AMPA, //!< AMPA: fast excitatory
- csimInputChannel_GABAa, //!< GABAa: fast inhibitory
- //! NMDA_AMPA: combined NMDA and AMPA input, NMDA is long lasting excitatory
- csimInputChannel_NMDA_AMPA,
- csimInputChannel_GABAb, //!< GABAb: long lasting inhibitory
- csimInputChannel_AMPA2, //!<
- csimInputChannel_Linking, //!<
- csimInputChannel_Endu, //!<
- csimInputChannel_EnduLinking,//!<
- csimInputChannel_Membrane, //!< inject current directly to membrand potential
- };
- class layer; // forward declaration
- class Connection; //! forward declaration
- class connection; //! forward declaration --> loeschen geht noch nicht??
- class AbstractNormalize; //! forward declaration
- class learning; // forward declaration for learning pointer in class connection
- class veclearning; // forward declaration for learning pointer in class connection
- class input;
- //! structure for transfering connection parameters to learning object
- typedef struct {
- int Dmax;
- int maximumDelay;
- float MaxWeight;
- layer *TargetLayer, *SourceLayer;
- short** delays_length;
- short*** delays;
- int M;
- int **post;
- int **I_pre, **D_pre;
- int **m_pre;
- float **WeightPointer;
- float **WeightDerivativePointer;
- int maxN_pre;
- int *N_pre;
- pfloat **s_pre, **sd_pre;
- } ConnectionInfo;
- //! structure for transfering connection parameters to learning object
- typedef struct {
- int Dmax;
- int maximumDelay;
- float MaxWeight;
- layer *TargetLayer, *SourceLayer;
- vector<float>* PSynWeights;
- vector<T_NNeurons>* PSynSourceNr;
- vector<T_NNeurons>* PSynTargetNr;
- vector<T_Delays>* PSynDelays;
- vector<vector<T_NSynapses> >* PPreSynNr;
- vector<vector<vector<T_NSynapses> > >* Pdelays;
- } VecConnectionInfo;
- /////////////////////////////////////////
- class ParameterSet
- {
- public:
- // virtual destructor needed to make class polymorphic and use dynamic_cast
- virtual ~ParameterSet(){}
- };
- template<class T1, class T2>
- class TwoParameters: public ParameterSet
- {
- public:
- TwoParameters(T1 Val1, T2 Val2): first(Val1), second(Val2) {}
- T1 first;
- T2 second;
- };
- class Changable
- {
- public:
- virtual void changeParameter(ParameterSet* Paras)=0;
- };
- /////////////////////////////////
- class SimpleTextProgressBar
- {
- float Status; // 0<=status<=Final
- float StepSize;
- int Final;
- public:
- SimpleTextProgressBar(int MaxSteps=10);
- int Next(int StepNr);
- int Reset(int MaxSteps);
- };
- //////////////////////
- // forward declaration
- class AnyOptionWrapper;
- //StandardOptions
- class CSimStandardOptions
- {
- private:
- AnyOptionWrapper *myAnyWrap;
- public:
- CSimStandardOptions(AnyOptionWrapper* _opt);
- int NTrials;
- int NSteps;
- int TestNSteps;
- string DataDirectory;
- bool LoadWeights;
- bool SimFinishButton;
- float InputStrength;
- bool SaveInitialWeights;
- };
- /////////////////
- /*********IDLrpc******************/
- /* class IDLrpc */
- /* { */
- /* public: */
- /* IDLrpc(); */
- /* ~IDLrpc(); */
- /* }; */
- ////////////////////
- #endif /*_H_LIBCSIM */
|