00001
00002
00003
00004
00034 #ifndef THETANEURON_HEADER
00035 #define THETANEURON_HEADER
00036
00037
00038 #include "stdafx.h"
00039 #include <fstream>
00040 #include <string>
00041 #include <iostream>
00042 #include <cmath>
00043 #include <ctime>
00044
00045 using namespace std;
00046
00047
00048 #define IO -0.001
00049 #define ALPHA 1
00050 #define OFFSET 0.0001
00051 #define TIMESTEP 0.001
00052 #define EPS 1e-10
00053 #define PI 3.14159265
00054 #define MAX_NUM_OUTPUT_SPIKES 5
00055
00056
00057 class thetaNeuron {
00058
00059
00060
00061
00062 public:
00063
00069 enum Method
00070 {
00071 Numerical,
00072 EventDriven
00073 };
00074
00096 thetaNeuron(int new_num_inputs = 3.0, double weight_ini = 1e6, double new_io = IO){
00097 srand((unsigned)time(0));
00098 weights=new double[new_num_inputs];
00099 for(int k=0;k<new_num_inputs;k++){
00100 if (weight_ini>100)
00101 weights[k] = (2.0*rand()/(RAND_MAX + 1.0))-1.0;
00102 else
00103 weights[k] = weight_ini;
00104 }
00105 num_inputs=new_num_inputs;
00106 io = new_io;
00107 if (io>=0) io=IO;
00108 beta=sqrt(fabs(ALPHA*io));
00109 positive_fixed_point=acos((1+ALPHA*io)/(1-ALPHA*io));
00110 phase=positive_fixed_point+OFFSET;
00111 verbose=1;
00112 method=Numerical;
00113 }
00114
00120 ~thetaNeuron(){
00121 delete [] weights;
00122 weights = NULL;
00123 }
00124
00125
00126
00127
00134 double getPhase(void) {return phase;}
00135
00142 Method getMethod(void) {return method;}
00143
00151 void setMethod(Method new_method) {method=new_method;}
00152
00160 void setVerbose(bool new_verbose) {verbose=new_verbose;}
00161
00169 double getWeight(int index) {
00170 if (index<num_inputs) {
00171 return weights[index];
00172 }
00173 else return -1;
00174 }
00175
00184 void setWeight(double new_weight, int index) {
00185 if (index<num_inputs) {
00186 weights[index]=new_weight;
00187 }
00188 }
00189
00196 double getIo(void) {return io;}
00197
00205 void setIo(double new_io) {
00206 if (new_io<0) {
00207 io=new_io;
00208 beta=sqrt(fabs(ALPHA*io));
00209 positive_fixed_point=acos((1+ALPHA*io)/(1-ALPHA*io));
00210 phase=positive_fixed_point+OFFSET;
00211 }
00212 }
00213
00220 void displayThetaNeuron(void);
00221
00231 int runThetaNeuron(double ti[], double ts[], int max_num_ts);
00232
00233
00234
00235
00236 private:
00237 double io;
00238 double beta;
00239 double positive_fixed_point;
00240 double phase;
00241 double *weights;
00242 int num_inputs;
00243 bool verbose;
00244 Method method;
00247
00248
00249 static double atanh(double x)
00250 {
00251 return ( 0.5 * log( ( 1.0 + x ) / ( 1.0 - x ) ) );
00252 }
00253
00254
00255
00256
00257
00258 void sortArray(double array[], int indices[], int size)
00259 {
00260 bool swap;
00261 double temp;
00262 int temp2;
00263 int n;
00264 for (n = 0; n < size; n++)
00265 {
00266 indices[n]=n;
00267 }
00268 do
00269 {
00270 swap = false;
00271 for (n = 0; n < (size - 1); n++)
00272 {
00273 if (array[n] > array[n + 1])
00274 {
00275 temp = array[n];
00276 array[n] = array[n + 1];
00277 array[n + 1] = temp;
00278 temp2 = indices[n];
00279 indices[n] = indices[n + 1];
00280 indices[n + 1] = temp2;
00281 swap = true;
00282 }
00283 }
00284 } while (swap);
00285 }
00286
00287
00288
00289 template <class ItemType>
00290 void showArray(ItemType array[], int size)
00291 {
00292 for (int j = 0; j < size; j++) {
00293 cout << array[j] << " ";
00294 }
00295 cout << endl;
00296 }
00297 };
00298
00299 #endif