00001 #include <iostream>
00002 #include <itpp/base/fastica.h>
00003 #include <itpp/base/mat.h>
00004 #include <string>
00005 #include <fstream>
00006 #include <vector>
00007 #include <iterator>
00008 using namespace std;
00009
00010 void WriteToFile(const itpp::Vec<double> &in,const itpp::Vec<double> &out,const string &base)
00011 {
00012
00013 ofstream ints((base+".in").c_str());
00014 ofstream outts((base+".out").c_str());
00015
00016 const int size = in.length();
00017 for (int i = 0; i < size; ++i)
00018 {
00019 ints << in(i) << endl;
00020 outts << out(i) << endl;
00021 }
00022 }
00023
00024
00025 int main()
00026 {
00027 const int nchannels = 2;
00028
00029
00030 string name1, name2;
00031 cout << "Infile 1: ";
00032 cin >> name1;
00033 cout << "Infile 2: ";
00034 cin >> name2;
00035 ifstream file1(name1.c_str());
00036 ifstream file2(name2.c_str());
00037 vector<double> in1((istream_iterator<double>(file1)), istream_iterator<double>());
00038 vector<double> in2((istream_iterator<double>(file2)), istream_iterator<double>());
00039 const size_t tslength = min(in1.size(),in2.size());
00040 cout << tslength <<endl;
00041 itpp::mat Input(nchannels,tslength);
00042 for (size_t i = 0; i < tslength; ++i)
00043 {
00044 Input(0,i) = in1.at(i);
00045 Input(1,i) = in2.at(i);
00046 }
00047
00048 itpp::Fast_ICA fastica(Input);
00049 fastica.set_nrof_independent_components(nchannels);
00050
00051
00052 fastica.separate();
00053 itpp::mat Output = fastica.get_independent_components();
00054 WriteToFile(Input.get_row(0),Output.get_row(0),"1");
00055 WriteToFile(Input.get_row(1),Output.get_row(1),"2");
00056 cout << "Mix Mat: " << endl << fastica.get_mixing_matrix() << endl;
00057 cout << "Whit Mat: " << endl << fastica.get_whitening_matrix() << endl;
00058
00059 }