Files
ia2005/backprop/synapse.cpp
2024-11-12 17:41:10 +01:00

52 lines
1.0 KiB
C++

#include "synapse.h"
Synapse::Synapse(const double w){
setWeight(w);
}
double Synapse::getWeight() const{
return weight;
}
void Synapse::setWeight(const double w){
weight =(double) w;
}
void Synapse::operator=(const double w){
setWeight(w);
}
Synapse& Synapse::operator =(const Synapse& s){
if(this!=&s){
setWeight(s.getWeight());
}
return *this;
}
void Synapse::setRandomWeight(){
//double range = SYNAPSE_WEIGHT_MAX - SYNAPSE_WEIGHT_MIN + 1;
double range = SYNAPSE_WEIGHT_MAX - SYNAPSE_WEIGHT_MIN; //lau
double res;
do{
//res = (double)(range * rand()/(RAND_MAX + 1.0)) + SYNAPSE_WEIGHT_MIN;
res=(double)(((rand()/2.0)/(RAND_MAX/2.0))*range)+SYNAPSE_WEIGHT_MIN;
}while(res > SYNAPSE_WEIGHT_MAX && res < SYNAPSE_WEIGHT_MIN);
setWeight(res);
}
ostream & operator<<(ostream & os,const Synapse & syn){
os << syn.getWeight();
return os;
}
istream& operator>>(istream & inp,Synapse & syn){
double tmp;
inp >> tmp;
syn.setWeight(tmp);
return inp;
}