testlp.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include "WienerInterpolator.h"
00003 #include <boost/numeric/ublas/vector.hpp>
00004 #include <boost/numeric/ublas/vector_proxy.hpp>
00005 #include <algorithm>
00006 #include <iterator>
00007 #include "UniformRNG.h"
00008 #include <itpp/itbase.h>
00009 #include <itpp/srccode/lpcfunc.h>
00010 #include <fstream>
00011 #include <numeric>
00012 #include <nr.h>
00013 #include <nrutil.h>
00014 #include <gsl/gsl_math.h>
00015 
00016 namespace ublas = boost::numeric::ublas;
00017 int main()
00018 {
00019         UniformRNG Random;
00020         
00021         const int datasize = Random.GetNumber(1000);
00022         const int filterlength = std::min(datasize/(Random.GetNumber(10)+1)+1,datasize);
00023         const int inputlength = std::min(datasize,filterlength*(Random.GetNumber(10)+1));
00024         //const int datasize =4;
00025         //const int filterlength = 2;
00026         //const int inputlength = 4;
00027         float *nrdata;
00028         float *d;
00029         nrdata = vector(1,inputlength);
00030         d = vector(1,filterlength);
00031         float xms;
00032         ublas::vector<float> Data(datasize);
00033         itpp::vec ItppData(inputlength);
00034         itpp::vec ItppCoeff(filterlength);
00035         itpp::vec StabCoeff(filterlength);
00036         
00037         for (int i = 0; i < datasize; ++i)
00038         {
00039                 Data(i) = sin(static_cast<double>(i)/1.2)+ (0.5 - Random.GetNumber())*0.1;
00040                 
00041         }
00042         WienerInterpolator Wiener(filterlength);
00043         ublas::vector<float> Input(inputlength);
00044         ublas::vector<double> Prediction(datasize);
00045         for (int i = 0; i < inputlength; ++i)
00046         {
00047                 Input(i) = Data(i);
00048                 ItppData(i) = Data(i);
00049                 Prediction(i) = Data(i);
00050                 nrdata[i+1] = Data(i);
00051         }
00052         Wiener.AdaptFilter(Input,Input);
00053         memcof(&(Input[0])-1,inputlength,filterlength,&xms,d);
00054         
00055         const double tolerance = 1e-3;
00056         std::cout << "Datasize: " << datasize << " Filterlength: " << filterlength << " Inputsize: " << inputlength<< std::endl; 
00057         for (int i = 0; i < filterlength; ++i)
00058         {
00059                 if ( gsl_fcmp(Wiener.GetWeights()(i),d[i+1],tolerance) != 0)
00060                 {
00061                         std::cout << "Index: " << i << " Own: " <<  Wiener.GetWeights()(i) << " NR: " << d[i+1] << std::endl;
00062                 }
00063         }
00064         
00065         /*ItppCoeff = itpp::schurrc(ItppData,filterlength);
00066         polystab(ItppCoeff,StabCoeff);
00067         std::ofstream outfile("out");
00068         for (int i = inputlength - filterlength; i < datasize - filterlength; ++i)
00069         {
00070                 //vector_range<vector<double> > vr(Data, range(i,i+filterlength));
00071                 //Prediction(i+filterlength) = inner_prod(Wiener.GetWeights(),vr);
00072                 Prediction(i+filterlength) = 0.0;
00073                 for (int j = 0; j < filterlength; ++j)
00074                 {
00075                         //Prediction(i+filterlength) += ItppCoeff(filterlength-j-1) * Prediction(i+j);
00076                         Prediction(i+filterlength) += d[filterlength-j] * Prediction(i+j);
00077                 }
00078         }
00079          std::cout << "Own: " << std::endl;
00080         for (int i = 0; i < datasize; ++i)
00081            outfile << i << " " << Data(i) << " " << Prediction(i) <<  std::endl;
00082          copy(Wiener.GetWeights().rbegin(),Wiener.GetWeights().rend(),std::ostream_iterator<double>(std::cout," "));
00083          std::cout << std::endl;
00084         
00085         std::cout << "NR: " << std::endl;
00086          for (int i = 0; i < filterlength; ++i)
00087                 std::cout << d[i+1] << " ";
00088          std::cout << std::endl;
00089          
00090          std::cout << "Itpp: " << std::endl;
00091          for (int i = 0; i < filterlength; ++i)
00092                 std::cout << ItppCoeff(i) << " ";
00093           std::cout << std::endl;
00094           
00095           /*for (int i = 0; i < filterlength; ++i)
00096                 std::cout << StabCoeff(i) << " ";
00097           std::cout << std::endl;*/
00098 }

Generated on Mon Sep 15 12:54:34 2008 for GPLIB++ by  doxygen 1.5.5