00001 #ifndef MISC_TOOLS_H
00002 #define MISC_TOOLS_H
00003
00004
00005
00006
00007
00008 #define EPSILON 0.00001
00009 #define Pi 3.141592653589793
00010 #define NO_VAL HUGE_VAL-10
00011
00012
00013 #include <math.h>
00014 #include <string>
00015 #include <iostream>
00016 #include <fstream>
00017 #include <sstream>
00018 #include<map>
00019 #include<vector>
00020 #include<complex>
00021
00022 using namespace std;
00023
00024 const complex<double> Icplx(0,1);
00025
00026
00027
00028
00029 template<typename TYPE>
00030 inline std::string toString(TYPE typ, int nFormat=0)
00031 {
00032 ostringstream ost;
00033 if(nFormat) {ost.width(nFormat); ost.fill('0');}
00034 ost<<typ;
00035 return ost.str();
00036 }
00037
00038 template<typename TYPE>
00039 inline TYPE fromString(const std::string& stringuee)
00040 {
00041 TYPE typ;
00042 istringstream ist;
00043 ist.str(stringuee);
00044 ist>>typ;
00045 return typ;
00046 }
00047
00048
00049
00050
00051
00052 struct extCommand {
00053 int argc ;
00054 char** argv ;
00055 extCommand() : argc(0), argv(0) {}
00056
00057 ~extCommand() ;
00058
00059 void assign( const vector<string> & commands ) ;
00060 void assign( const string & total_command ) ;
00061
00062 extCommand( const vector<string> & commands ) ;
00063 extCommand( const string & total_command ) ;
00064 };
00065
00066
00067
00068 std::string my_pwd(void) ;
00069
00070
00071
00072
00073 inline double round0(double val)
00074 {
00075 if(fabs(val)<EPSILON) return(0.0);
00076 else return(val);
00077 }
00078
00079 inline double min(const double a,const double b)
00080 {
00081 return (a<b) ? a : b ;
00082 }
00083
00084 inline double max(const double a,const double b)
00085 {
00086 return (a>b) ? a : b;
00087 }
00088
00089 inline int sign(float val)
00090 {
00091 return (val<0) ? -1 : 1;
00092 }
00093
00094
00095
00096
00097 inline double norm(double a,double b)
00098 {
00099 return sqrt(a*a+b*b);
00100 }
00101
00102
00103
00104
00105
00106
00107 inline int arrangement(int n, int k)
00108 {
00109 if ((n<0)||(k<0))
00110 cerr<<"Error in function 'arrangement': used with negative values."<<endl;
00111 int res=1;
00112 for(int i=n;i>n-k;--i) res*=i;
00113 return res;
00114 }
00115
00116 inline int factorial(int n)
00117 {
00118 return arrangement(n,n);
00119 }
00120
00121 inline int combination(int n, int k)
00122 {
00123 return arrangement(n,k)/factorial(k);
00124 }
00125
00126
00127
00128 inline double Gaussian(double sigma,double x, double y)
00129 {
00130 double xy=-((x*x)+(y*y));
00131 return sigma?
00132 exp(xy/(2*pow(sigma,2))) / (2*M_PI*pow(sigma,2)) :
00133 xy? 0.0 : 1.0 ;
00134 }
00135
00136 inline double Gabor(double sigma,double T,double freq, double x, double y,double phi)
00137 {
00138 return sigma?
00139 exp(-((x*x)+(y*y))/(2*sigma*sigma)) * (sin(2*M_PI*freq*(x*cos(T)+y*sin(T))+phi)) :
00140 (x*x+y*y) ? 0.0 : sin(phi) ;
00141 }
00142
00143
00144
00145
00146
00147 template<typename TYPE>
00148 TYPE* vecSum(TYPE* v1,int l1,TYPE* v2, int l2)
00149 {
00150 bool longer1 = (l1>l2) ;
00151 int lmax= longer1? l1: l2;
00152 int lmin= longer1? l2: l1;
00153 TYPE* res=new TYPE[lmax];
00154 for(int l=0;l<lmin;++l)
00155 res[l]=v1[l]+v2[l];
00156 for(int l=lmin;l<lmax;++l)
00157 res[l]= longer1? v1[l]: v2[l];
00158 return res;
00159 }
00160
00161
00162
00163
00164 template<typename TYPE>
00165 TYPE* vecConvolve(TYPE* v1,int l1,TYPE* v2, int l2)
00166 {
00167 TYPE* res=new TYPE[l1+l2-1];
00168 for(int l=0;l<l1+l2-1;++l)
00169 {
00170 res[l]=0;
00171 int start=max(0,l-l2+1);
00172 int end=min(l+1,l1);
00173 for(int i=start;i<end;++i)
00174 res[l]+=(v1[i]*v2[l-i]);
00175 }
00176 return res;
00177 }
00178
00179
00180
00181 double instantFiringRate(double I, double tauRefr, double gLeak, double Ginh, double Einh=0, double Gexc=0, double Eexc=14/3);
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 #endif
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223