00001 #include "GeneralLinearCombiner.h" 00002 #include <algorithm> 00003 #include "GeneralNeuron.h" 00004 00005 namespace gplib 00006 { 00007 GeneralLinearCombiner::GeneralLinearCombiner(bool wantcached) : 00008 wchanged(true), bchanged(true), cachedoutput(wantcached) 00009 { 00010 } 00011 GeneralLinearCombiner::~GeneralLinearCombiner() 00012 { 00013 } 00014 00015 double GeneralLinearCombiner::CalcOutput() 00016 { 00017 //if we do not want cached output or the weights or the bias has changed 00018 if (!cachedoutput || wchanged || bchanged) 00019 { 00020 // we calculate the output from bias, weights and input values 00021 Output = Bias; 00022 const size_t size = Weights.size(); 00023 for (unsigned int i = 0; i < size; ++i) 00024 Output += (Input.at(i)->GetOutput()) * Weights.at(i); 00025 // the next call will return the stored results, unless the weights or the bias have changed 00026 wchanged = false; 00027 bchanged = false; 00028 } 00029 return Output; 00030 } 00031 00032 void GeneralLinearCombiner::SetInput(const tinvector &LocalInput) 00033 { 00034 const int size = LocalInput.size(); 00035 // initialize the weights 00036 Weights.assign(size, 0); 00037 // we reassigned the input, so we have to recalculate the output in any case 00038 wchanged = true; 00039 bchanged = true; 00040 // initialize the Bias 00041 Bias = 0.0; 00042 // if we had some input before, clear it 00043 if (!Input.empty()) 00044 Input.clear(); 00045 //copy the parameter values to the local property 00046 copy(LocalInput.begin(), LocalInput.end(), back_inserter(Input)); 00047 } 00048 }
1.5.8