00001 #ifndef INSTANTSYNAPSE_H 00002 #define INSTANTSYNAPSE_H 00003 00004 #include "cimg/misc_tools.h" 00005 #include "cimg/cimg_tools.h" 00006 00007 00008 // A 'quite' general tool to model instantaneous synaptic transmission, with its possible non linearities. 00009 //Its parameters are: 00010 // - Gmax, maximum output value (saturation) 00011 // - v0, threshold of the function. Transmission is 'compressed' for v<v0, and 'saturated' for v>v0 00012 // - lambda, slope of the function at point v0 (if power_exp = 1 ) 00013 // - eta, relative sizes of the 'saturation' zone and of the 'compression' zone 00014 00015 // - power_exp, an 'artificial' exponent to be able to generate power-law synaptic functions 00016 // Allows to implement transmissions of the type v->v^2 (but in a very complicated way !!!! :-) ) 00017 00018 //The most general formula it implements is, for an input value v : 00019 00020 // workPoint = ( v > v0 ) ? lambda/Gmax * pow ( v - v0 , power_exp ) : //workPoint > 0 00021 // - lambda/Gmax * pow ( v0 - v , power_exp ) ; //workPoint < 0 00022 00023 // output = (workPoint > 0 )? Gmax * ( eta + (1-eta)*workPoint/(1-eta+workPoint) ) : 00024 // Gmax * eta * eta/(eta-workPoint); 00025 00026 00027 class InstantSynapse 00028 { 00029 protected: 00030 double eta, Gmax, lambda, v0, zeroPoint, workPoint, power_exp; 00031 bool useZP; 00032 00033 inline void actualize(void) 00034 { 00035 if(useZP) v0=-Gmax/lambda*zeroPoint; 00036 else zeroPoint=-lambda/Gmax*v0; 00037 } 00038 double nonLinTransmission(double inputValue); //const; 00039 00040 00041 public: 00042 00043 bool isUsed; //to tell if the synapse has been initialized, or if it is just 'virtual' (to win some calcuation time). 00044 bool isLinear; //to tell if the synapse has been initialized non-linearly (to win some calcuation time). 00045 00046 InstantSynapse(bool uZP=false); 00047 ~InstantSynapse(){} 00048 00049 //************* Transmission functions: ******* 00050 00051 double transmission(double inputValue); //const; 00052 void addTransmission(const CImg<double>& input, CImg<double>& output); //const; 00053 void apply(CImg<double>& input); //const; 00054 CImg<double> transmission(const CImg<double>& input); //const; 00055 00056 //************* Initialization functions: ***** 00057 00058 //****** (1) Already coded functions: 00059 00060 //returns val_v^2 /(val_v + lam * (v-input)^power_exp ) if lam*(input-v) < 0 00061 // val_v + lam * (v-input)^power_exp if lam*(input-v) > 0 00062 InstantSynapse& rectification(double v, double lam=1.0, double val_v=0.0); 00063 00064 //A simple linear amplification of the input___Warning! Output can be negative... 00065 InstantSynapse& linearAmplification( double lam ); 00066 00067 //If you want to change the power exponent (default is 1, of course) 00068 InstantSynapse& set_power_exp(double val); 00069 00070 //just to represent the shape of the synapse's rectification function 00071 void draw_transmission( double xmin=-2.0, double xmax=2.0, const double* color = green ); 00072 00073 00074 //******** (2) Custom functions: 00075 00076 //Decide wether the synapse formalism should use a 'zeroPoint' or rather a 'v0' 00077 InstantSynapse& useZeroPoint(void); 00078 //direct setting of parameters: 00079 InstantSynapse& set_Gmax(double val); 00080 InstantSynapse& set_eta(double val); 00081 InstantSynapse& set_lambda(double val); 00082 InstantSynapse& set_v0(double val); 00083 InstantSynapse& set_zeroPoint(double val); 00084 //once all other synaptic parameters are fixed, calculates zeroPoint (or v0...) so as to have g as transmission output when inputValue=v 00085 double calculate_v0(double g, double v); //const; 00086 double calculate_zeroPoint(double g, double v); //const; 00087 00088 00089 //get_X functions (because of the ambiguity zeroPoint <-> v0) 00090 double get_zeroPoint(void); //const; 00091 double get_v0(void); //const; 00092 00093 }; 00094 #endif 00095 00096