Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include <iostream>
00056 #include "liatools.h"
00057
00058 void nap(Matrix <double>& sv,Matrix <double>& NAP) {
00059 RealVector <double> in;
00060 in.setSize(sv.cols());
00061 RealVector <double> proj;
00062 proj.setSize(sv.cols());
00063 for (unsigned long i=0;i<in.size();i++)
00064 in[i]=sv(0,i);
00065 projectOnSubSpace(in,NAP,proj);
00066 if (debug) cout <<"* sv:"<<sv(0,50)<<" proj:"<<proj[50]<<endl;
00067 in-=proj;
00068 sv=(Matrix <double>)in;
00069 if (debug) cout <<"** sv:"<<sv(0,50)<<" proj:"<<proj[50]<<endl;
00070 }
00071
00072 void project(Matrix <double>& sv,Matrix <double>& NAP) {
00073 RealVector <double> in;
00074 in.setSize(sv.cols());
00075 RealVector <double> proj;
00076 proj.setSize(sv.cols());
00077 for (unsigned long i=0;i<in.size();i++)
00078 in[i]=sv(0,i);
00079 projectOnSubSpace(in,NAP,proj);
00080 sv=(Matrix <double>)proj;
00081 if (debug) cout <<"** sv:"<<sv(0,50)<<" proj:"<<proj[50]<<endl;
00082 }
00083
00084 int main(int argc, char* argv[]){
00085
00086 ConfigChecker cc;
00087 cc.addStringParam("config", false, true, "default config filename");
00088 try{
00089 CmdLine cmdLine(argc, argv);
00090 Config tmp;
00091 cmdLine.copyIntoConfig(tmp);
00092 Config config;
00093 if (tmp.existsParam("config")) config.load(tmp.getParam("config"));
00094 cmdLine.copyIntoConfig(config);
00095 cc.check(config);
00096 debug=config.getParam_debug();
00097 if (config.existsParam("verbose"))verbose=config.getParam("verbose").toBool();else verbose=false;
00098 if (verbose) verboseLevel=1;else verboseLevel=0;
00099 if (config.existsParam("verboseLevel"))verboseLevel=config.getParam("verboseLevel").toLong();
00100 if (verboseLevel>0) verbose=true;
00101
00102
00103 XList inputList(config.getParam("inputFilename"));
00104 String vPath=config.getParam("vectorFilesPath");
00105 String vExt=config.getParam("vectorFilesExt");
00106 String vOExt=config.getParam("napvectorFilesExt");
00107 Matrix <double> NAP;
00108 NAP.load(config.getParam("NAP"),config);
00109 if (verbose) cout << "NAP matrix dimensions: ("<<NAP.rows()<<","<<NAP.cols()<<")"<<endl;
00110 for (unsigned long r=0;r<inputList.getLineCount();r++) {
00111 String in=vPath+inputList.getLine(r).getElement(0)+vExt;
00112 String out=vPath+inputList.getLine(r).getElement(0)+vOExt;
00113 if (verbose) cout << "Processing ["<<in<<"] to ["<<out<<"]"<<endl;
00114 Matrix <double> sv;
00115 sv.load(in,config);
00116 if (verboseLevel > 1) cout << "Vector dimensions: ("<<sv.rows()<<","<<sv.cols()<<")"<<endl;
00117 if (config.existsParam("project")) project(sv,NAP);
00118 nap(sv,NAP);
00119 sv.save(out,config);
00120 }
00121 return 0;
00122 }
00123 catch(alize::Exception & e){ cout <<"TrainTarget "<< e.toString() << endl << cc.getParamList()<<endl;}
00124 }