GPLIB++
LMSCanceller.cpp
Go to the documentation of this file.
1 #include "LMSCanceller.h"
2 #include "FatalException.h"
3 #include <iostream>
4 #include <iterator>
5 using namespace std;
6 
7 namespace gplib
8  {
9 
10  LMSCanceller::LMSCanceller(const int inputsize) :
11  LSSOFilter(inputsize), mu(1)
12  {
13  }
14 
15  LMSCanceller::LMSCanceller(const int inputsize, const double Mymu) :
16  LSSOFilter(inputsize), mu(Mymu)
17  {
18  }
19 
21  {
22  }
23 
24  void LMSCanceller::AdaptFilter(const gplib::rvec &Input,
25  const gplib::rvec &Desired)
26  {
27  if (Input.size() != GetInputLength() || Input.size() != GetWeights().size()
28  || Desired.size() != GetOutputLength())
29  throw FatalException("Input or Desired do not have expected size !");
30 
31  SetEpsilon(Desired - GetFilterOutput()); //Calculate the last prediction error
32  double step = ublas::prec_inner_prod(Input, Input); //the power of the input data
33  const double delta = 0.0001; // We introduce delta to improve stability for small values
34  step = mu / (step + delta); //here see Haykin, p 323
35  SetWeights() += 2.0 * step * GetEpsilon()(0) * Input; //update Filter based on prediction error
36  }
37  }
const gplib::rvec & GetEpsilon() const
Return the last estimation error.
const gplib::rvec & GetWeights()
Return the current set of weights.
Definition: LSSOFilter.h:41
void SetEpsilon(const gplib::rvec &MyEps)
Possibility for derived classes to set estimation error.
unsigned int GetInputLength()
Access function for derived classes for the inputlength.
virtual void AdaptFilter(const gplib::rvec &Input, const gplib::rvec &Desired)
Adapt the filter weights given the Input and Desired vectors.
const gplib::rvec & GetFilterOutput() const
Access to the last calculated output (not sure if needed)
gplib::rvec & SetWeights()
Definition: LSSOFilter.h:26
unsigned int GetOutputLength()
Access function for derived classes for the outputlength.
Base class for least squares filter with a single output value.
Definition: LSSOFilter.h:20
LMSCanceller(const int inputsize)
The basic exception class for all errors that arise in gplib.