3 #include <boost/progress.hpp>
9 showprogress(false), wanthistory(keephistory), shift(0),
10 Filter(TheFilter), weightsaveintervall(TheFilter.GetOutputLength())
25 if (WeightHistory.empty())
27 const size_t xsize = WeightHistory.size();
28 const size_t ysize = WeightHistory.front().size();
29 gplib::rmat temp(xsize, ysize);
30 for (
size_t i = 0; i < xsize; ++i)
31 for (
size_t j = 0; j < ysize; ++j)
32 temp(i, j) = WeightHistory.at(i)(j);
38 if (!InputChannels.empty() && Channel.
GetData().size()
39 != InputChannels.front()->GetData().size())
41 "Input channel has incompatible size to first channel");
42 InputChannels.push_back(&Channel);
49 "Trying to add more reference channels than permitted by Adaptive Filter class");
50 if (!RefChannels.empty() && Channel.
GetData().size()
51 != RefChannels.front()->GetData().size())
53 "Ref channel has incompatible size to first channel");
54 RefChannels.push_back(&Channel);
59 const int ninputchannels = InputChannels.size();
60 const int datalength = InputChannels.front()->GetData().size();
63 const int pointsperchannel = inputsize / ninputchannels;
65 gplib::rvec currentinput(inputsize), currdesired(outputsize), currout(
70 if (!EpsValues.empty())
76 for (
int i = 0; i < outputsize; ++i)
78 std::vector<double> temp;
79 EpsValues.push_back(temp);
80 OutChannels.push_back(boost::shared_ptr<TimeSeriesComponent>(
82 OutChannels.at(i)->GetData().reserve(
83 RefChannels.at(i)->GetData().size());
84 EpsValues.at(i).reserve(RefChannels.at(i)->GetData().size());
86 OutChannels.at(i)->GetData().insert(
87 OutChannels.at(i)->GetData().begin(), shift, 0.0);
88 EpsValues.at(i).insert(EpsValues.at(i).begin(), shift, 0.0);
90 const int maxindex = datalength - pointsperchannel - shift;
91 boost::progress_display *progressbar = NULL;
94 progressbar =
new boost::progress_display(maxindex);
96 for (
int i = 0; i < maxindex; ++i)
99 for (
int j = 0; j < ninputchannels; ++j)
101 copy(InputChannels.at(j)->GetData().begin() + i,
102 InputChannels.at(j)->GetData().begin() + pointsperchannel
103 + i, currentinput.begin() + j * pointsperchannel);
105 for (
int j = 0; j < outputsize; ++j)
106 currdesired(j) = RefChannels.at(j)->GetData().at(i + shift);
114 for (
int j = 0; j < outputsize; ++j)
116 OutChannels.at(j)->GetData().push_back(currout(j));
118 if (wanthistory && ((i - shift) % weightsaveintervall == 0))
122 for (
int j = 0; j < outputsize; ++j)
124 EpsValues.at(j).push_back(Filter.
GetEpsilon()(j));
127 for (
int i = 0; i < outputsize; ++i)
129 OutChannels.at(i)->GetData().insert(
130 OutChannels.at(i)->GetData().end(), pointsperchannel, 0.0);
131 EpsValues.at(i).insert(EpsValues.at(i).end(), pointsperchannel, 0.0);
const gplib::rvec & GetEpsilon() const
Return the last estimation error.
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
void AddReferenceChannel(TimeSeriesComponent &Channel)
Add a reference channel to the filter, some AdaptiveFilter objects require only one reference...
gplib::rmat GetWeightHistory()
Return a matrix with the values of the weights at iterations specified by weightsaveintervall.
virtual const gplib::rvec & GetWeightsAsVector()=0
We can always convert the weights to some sort of vector, the details have to be implemented in the d...
void AddInputChannel(TimeSeriesComponent &Channel)
Add an input channel to the filter.
ApplyFilter(AdaptiveFilter &TheFilter, bool keephistory=false)
The constructor takes the AdaptiveFilter object that determines how the filtering is done...
unsigned int GetInputLength()
Access function for derived classes for the inputlength.
A generic base class for all types of adaptive filters.
TimeSeriesComponent is the base storage class for all types of time series data.
virtual void CalcOutput(const gplib::rvec &Input, gplib::rvec &Output)=0
Calculate the filter output given Input.
virtual void AdaptFilter(const gplib::rvec &Input, const gplib::rvec &Desired)=0
Adapt the filter weights given the Input and Desired vectors.
void FilterData()
Filter the input channels with the current settings.
unsigned int GetOutputLength()
Access function for derived classes for the outputlength.
The basic exception class for all errors that arise in gplib.