SpikeStream Library
0.2
|
00001 #ifndef CONNECTION_H 00002 #define CONNECTION_H 00003 00004 //SpikeStream includes 00005 #include "SpikeStreamException.h" 00006 00007 //Other includes 00008 #include <math.h> 00009 00010 00011 //Defines for compressing the weight 00012 #define DELAY_FACTOR 10 00013 #define DELAY_MAX 6553.5f 00014 #define WEIGHT_FACTOR 10000.0f 00015 #define WEIGHT_MAX 1.0f 00016 #define WEIGHT_MIN -1.0f 00017 00018 00019 namespace spikestream { 00020 00023 class Connection{ 00024 public: 00025 Connection(); 00026 Connection (unsigned fromNeuronID, unsigned toNeuronID, float delay, float weight); 00027 Connection (unsigned id, unsigned fromNeuronID, unsigned toNeuronID, float delay, float weight); 00028 Connection(const Connection& conn); 00029 Connection& operator=(const Connection& rhs); 00030 void print(); 00031 00032 unsigned getID() { return id; } 00033 float getDelay(); 00034 unsigned getFromNeuronID(){ return fromNeuronID; } 00035 unsigned getToNeuronID(){ return toNeuronID; } 00036 float getTempWeight(); 00037 float getWeight(); 00038 void setID(unsigned id) { this->id = id; } 00039 void setFromNeuronID(unsigned fromNeurID) { this->fromNeuronID = fromNeurID; } 00040 void setToNeuronID(unsigned toNeurID) { this->toNeuronID = toNeurID; } 00041 void setTempWeight(float newTempWeight); 00042 void setWeight(float newWeight); 00043 00044 00045 private: 00046 //======================= VARIABLES ======================== 00048 unsigned id; 00049 00051 unsigned int fromNeuronID; 00052 00054 unsigned int toNeuronID; 00055 00058 unsigned short delay; 00059 00062 short weight; 00063 00066 short tempWeight; 00067 00068 }; 00069 00070 00071 00072 /*--------------------------------------------------------*/ 00073 /*------- INLINE METHODS -------*/ 00074 /*--------------------------------------------------------*/ 00075 00077 inline float Connection::getDelay(){ 00078 return (float)delay / DELAY_FACTOR; 00079 } 00080 00081 00083 inline float Connection::getWeight(){ 00084 return (float)weight / WEIGHT_FACTOR; 00085 } 00086 00087 00089 inline float Connection::getTempWeight(){ 00090 return (float)tempWeight / WEIGHT_FACTOR; 00091 } 00092 00093 00095 inline void Connection::setTempWeight(float newTempWeight){ 00096 if(newTempWeight > WEIGHT_MAX || newTempWeight < WEIGHT_MIN) 00097 throw SpikeStreamException("Weight out of range: " + QString::number(newTempWeight)); 00098 this->tempWeight = (short) rint(newTempWeight * WEIGHT_FACTOR); 00099 } 00100 00101 00103 inline void Connection::setWeight(float newWeight){ 00104 if(newWeight > WEIGHT_MAX || newWeight < WEIGHT_MIN) 00105 throw SpikeStreamException("Weight out of range: " + QString::number(newWeight)); 00106 this->weight = (short) rint(newWeight * WEIGHT_FACTOR); 00107 } 00108 00109 } 00110 00111 #endif//CONNECTION_H 00112