test-featureNPC.C
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 #include "Util/Timer.H"
00051 #include "VFAT/NPclassify.H"
00052
00053 #include <fstream>
00054 #include <iostream>
00055
00056
00057 char* configFile;
00058
00059 readConfig configIn(25);
00060 readConfig polySet(25);
00061
00062 int itemNumber;
00063
00064 int main(int argc, char* argv[])
00065 {
00066
00067 std::cerr << "STARTING\n";
00068 std::cerr << "Opening config file" << argv[1] << "\n";
00069 std::ifstream inFile(argv[1],std::ios::in);
00070 std::vector<double> dataIn(7,0.0F);
00071 std::vector< std::vector<double> > vectorIn(1000,dataIn);
00072 int column = 0;
00073 int row = 0;
00074 int family = 0;
00075 bool comment = false;
00076
00077 std::string in;
00078 std::cerr << "Parsing config file" << argv[1] << "\n";
00079 while (inFile >> in)
00080 {
00081
00082 if(!in.compare("#"))
00083 {
00084 if(!comment)
00085 {
00086 comment = true;
00087 }
00088 else
00089 {
00090 comment = false;
00091 }
00092 }
00093 if((!comment) && in.compare("#"))
00094 {
00095 if(column == 1)
00096 {
00097
00098
00099
00100 }
00101 if(column == 3)
00102 {
00103 vectorIn[row][family] = atof(in.c_str());
00104
00105
00106 }
00107 column++;
00108 if(column == 5)
00109 {
00110 column = 0;
00111 row++;
00112 }
00113 if(!in.compare("%"))
00114 {
00115 row = 0;
00116 column = 0;
00117 family++;
00118 std::cerr << "New Family " << family << "\n";
00119 }
00120 }
00121 }
00122
00123
00124 Timer tim;
00125 tim.reset();
00126 uint64 t0 = tim.get();
00127
00128
00129 if(argc > 2)
00130 itemNumber = atoi(argv[2]);
00131 else
00132 itemNumber = -666;
00133
00134
00135 configIn.openFile("NPclassify.conf");
00136 polySet.openFile("polySet.conf");
00137
00138 NPclassify NP(configIn,polySet,true);
00139 if(argc > 3)
00140 {
00141 NP.inputCommandLineSettings(atof(argv[3]),atof(argv[4]),atof(argv[5]),
00142 atof(argv[6]),atoi(argv[7]),atoi(argv[8]),
00143 atof(argv[9]),atof(argv[10]),atof(argv[11]));
00144 }
00145
00146
00147
00148 std::vector<double> feature(2,0);
00149 std::vector<long> roots;
00150 std::vector<long> parents;
00151 std::vector<double> density;
00152
00153 NP.addSpace(vectorIn,(row-1));
00154 NP.classifySpaceNew();
00155 uint64 t1 = tim.get();
00156 t0 = t1 - t0;
00157
00158 roots = NP.getStems();
00159 parents = NP.getParents();
00160 density = NP.getDensity();
00161
00162 std::vector<std::vector<long> > theReturn = NP.getChildren();
00163 for(int i = 0; i < NP.getStemNumber(); i++)
00164 {
00165 if(NP.getClassSize(i) > NP.getMinClassSize())
00166 {
00167 LINFO("CLASS %d size %ld",i,NP.getClassSize(i));
00168 }
00169 }
00170
00171
00172 NP.metaClassify(itemNumber);
00173
00174 std::ofstream outfile("feature_trian.dat",std::ios::out);
00175 std::ofstream matfile("feature_trian_mat.dat",std::ios::out);
00176 for(int i = 0; i < NP.getStemNumber(); i++)
00177 {
00178 for(int j = 0; j < NP.getClassSize(i); j++)
00179 {
00180 long item = NP.getClass(i,j);
00181 outfile << item << "\t" << i << "\t" << j << "\t"
00182 << NP.getFeature(item,0) << "\t"
00183 << NP.getFeature(item,1) << "\n";
00184 matfile << item << "\t" << i << "\n";
00185 }
00186 }
00187
00188
00189 }