GPLIB++
simplelp.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <algorithm>
4 #include <iterator>
5 #include "WienerInterpolator.h"
6 #include "UniformRNG.h"
7 #include <boost/numeric/ublas/vector.hpp>
8 #include <boost/numeric/ublas/vector_proxy.hpp>
9 
10 
11 using namespace boost::numeric::ublas;
12 using namespace gplib;
13 
14 int main()
15  {
16  std::string filename;
17  std::ifstream infile;
18  UniformRNG Random;
19  /*std::cout << "Infile name: ";
20  std::cin >> filename;
21  std::vector<double> read;
22  infile.open(filename.c_str());
23  std::copy(std::istream_iterator<double>(infile),std::istream_iterator<double>(),std::back_inserter(read));*/
24 
25  const int datasize = 500;
26  const int filterlength = 20;
27  const int inputlength = 100;
28  gplib::rvec Data(datasize);
29  for (int i = 0; i < datasize; ++i)
30  Data(i) = sin(static_cast<double> (i) / 0.9) + cos(
31  static_cast<double> (i) / 2.7) + (0.5 - Random.GetNumber()) * 0.1;
32  //copy(read.begin(),read.end(),Data.begin());
33  WienerInterpolator Wiener(filterlength);
34  gplib::rvec Input(inputlength);
35  gplib::rvec Prediction(datasize);
36  for (int i = 0; i < inputlength; ++i)
37  {
38  Input(i) = Data(i);
39  Prediction(i) = Data(i);
40  }
41  Wiener.AdaptFilter(Input, Input);
42 
43  for (int i = inputlength - filterlength; i < datasize - filterlength; ++i)
44  {
45  vector_range<vector<double> >
46  vr(Prediction, range(i, i + filterlength));
47  Prediction(i + filterlength) = inner_prod(Wiener.GetWeights(), vr);
48  }
49  std::ofstream outfile("out");
50  for (int i = 0; i < datasize; ++i)
51  outfile << i << " " << Data(i) << " " << Prediction(i) << std::endl;
52  //copy(Wiener.GetWeights().begin(),Wiener.GetWeights().end(),std::ostream_iterator<double>(std::cout,"\n"));
53  }
const gplib::rvec & GetWeights()
Return the current set of weights.
Definition: LSSOFilter.h:41
Generate uniformly distributed random numbers, this is basically a wrapper for the boost random numbe...
Definition: UniformRNG.h:19
int main()
Definition: simplelp.cpp:14
float GetNumber(const float low, const float high)
Return a random float between low and high.
Definition: UniformRNG.cpp:21
virtual void AdaptFilter(const gplib::rvec &Input, const gplib::rvec &Desired)
Calculate the prediction coefficients, the contents of Desired are ignored, this function has to be i...