GPLIB++
GeneralLinearCombiner.cpp
Go to the documentation of this file.
2 #include <algorithm>
3 #include "GeneralNeuron.h"
4 
5 namespace gplib
6  {
8  wchanged(true), bchanged(true), cachedoutput(wantcached)
9  {
10  }
12  {
13  }
14 
16  {
17  //if we do not want cached output or the weights or the bias has changed
18  if (!cachedoutput || wchanged || bchanged)
19  {
20  // we calculate the output from bias, weights and input values
21  Output = Bias;
22  const size_t size = Weights.size();
23  for (unsigned int i = 0; i < size; ++i)
24  Output += (Input.at(i)->GetOutput()) * Weights.at(i);
25  // the next call will return the stored results, unless the weights or the bias have changed
26  wchanged = false;
27  bchanged = false;
28  }
29  return Output;
30  }
31 
33  {
34  const int size = LocalInput.size();
35  // initialize the weights
36  Weights.assign(size, 0);
37  // we reassigned the input, so we have to recalculate the output in any case
38  wchanged = true;
39  bchanged = true;
40  // initialize the Bias
41  Bias = 0.0;
42  // if we had some input before, clear it
43  if (!Input.empty())
44  Input.clear();
45  //copy the parameter values to the local property
46  copy(LocalInput.begin(), LocalInput.end(), back_inserter(Input));
47  }
48  }
GeneralLinearCombiner(bool wantcached=false)
virtual void SetInput(const tinvector &LocalInput)
connect the input channels to the neurons given in LocalInput
virtual double CalcOutput()
Calculate the output given the current configuration.
const int size
Definition: perftest.cpp:14
std::vector< boost::shared_ptr< GeneralNeuron > > tinvector