00001 #include "LMSCanceller.h" 00002 #include "FatalException.h" 00003 #include <iostream> 00004 #include <iterator> 00005 using namespace std; 00006 00007 namespace gplib 00008 { 00009 00010 LMSCanceller::LMSCanceller(const int inputsize) : 00011 LSSOFilter(inputsize), mu(1) 00012 { 00013 } 00014 00015 LMSCanceller::LMSCanceller(const int inputsize, const double Mymu) : 00016 LSSOFilter(inputsize), mu(Mymu) 00017 { 00018 } 00019 00020 LMSCanceller::~LMSCanceller() 00021 { 00022 } 00023 00024 void LMSCanceller::AdaptFilter(const gplib::rvec &Input, 00025 const gplib::rvec &Desired) 00026 { 00027 if (Input.size() != GetInputLength() || Input.size() != GetWeights().size() 00028 || Desired.size() != GetOutputLength()) 00029 throw FatalException("Input or Desired do not have expected size !"); 00030 00031 SetEpsilon(Desired - GetFilterOutput()); //Calculate the last prediction error 00032 double step = ublas::prec_inner_prod(Input, Input); //the power of the input data 00033 const double delta = 0.0001; // We introduce delta to improve stability for small values 00034 step = mu / (step + delta); //here see Haykin, p 323 00035 SetWeights() += 2.0 * step * GetEpsilon()(0) * Input; //update Filter based on prediction error 00036 } 00037 }
1.5.8