GeneralLinearCombiner.cpp

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

Generated on Fri Jul 4 15:30:20 2008 for GPLIB++ by  doxygen 1.5.5