Commit a801c828849778a53d2ca7891f5c3774ad39f489

Authored by David Mayerich
1 parent e9a7821b

Added code to save a matrix to a file for debugging

Showing 2 changed files with 21 additions and 2 deletions   Show diff stats
src/basic_functions.h
@@ -47,6 +47,24 @@ void mtxMultranspose(T* M3, T* M1, T* M2, size_t r1, size_t c1, size_t r2, size_ @@ -47,6 +47,24 @@ void mtxMultranspose(T* M3, T* M1, T* M2, size_t r1, size_t c1, size_t r2, size_
47 } 47 }
48 } 48 }
49 49
  50 +template<typename T>
  51 +void mtxOutputFile(std::string filename, T* M, size_t rows, size_t cols){
  52 + std::cout<<"Outputting "<<rows<<" x "<<cols<<" matrix to file: "<<filename<<std::endl;
  53 + ofstream outfile(filename.c_str()); //open a file for writing
  54 + //output the matrix
  55 + for(size_t r = 0; r < rows; r++){
  56 + for(size_t c = 0; c < cols; c++){
  57 + outfile<<M[r * cols + c];
  58 + if(c != cols-1)
  59 + outfile<<",";
  60 + }
  61 + if(r != rows - 1)
  62 + outfile<<std::endl;
  63 + }
  64 + outfile.close();
  65 + //outfile<<"This is a test."<<std::endl;
  66 +}
  67 +
50 //display within class scatter 68 //display within class scatter
51 template<typename T> 69 template<typename T>
52 void displayS(T* sw, size_t f){ 70 void displayS(T* sw, size_t f){
@@ -155,6 +155,7 @@ void gpuComputeEignS( size_t g, size_t fea){ @@ -155,6 +155,7 @@ void gpuComputeEignS( size_t g, size_t fea){
155 155
156 ///DETERMINANT CURRENTLY REQUIRES OPENCV 156 ///DETERMINANT CURRENTLY REQUIRES OPENCV
157 std::cout<<"ERROR: This code requires a fix to remove an OpenCV dependence."<<std::endl; 157 std::cout<<"ERROR: This code requires a fix to remove an OpenCV dependence."<<std::endl;
  158 + mtxOutputFile("newSw.csv", nSw, r, r);
158 exit(1); 159 exit(1);
159 //FIX BY REPLACING THE FOLLOWING THREE LINES OF CODE USING LAPACK 160 //FIX BY REPLACING THE FOLLOWING THREE LINES OF CODE USING LAPACK
160 //cv::Mat newSw = cv::Mat((int)r, (int)r, CV_32FC1, nSw); //within scatter of gnome g in the population 161 //cv::Mat newSw = cv::Mat((int)r, (int)r, CV_32FC1, nSw); //within scatter of gnome g in the population
@@ -255,7 +256,7 @@ int main(int argc, char* argv[]){ @@ -255,7 +256,7 @@ int main(int argc, char* argv[]){
255 args.add("generations", "number of generationsr", "50"); 256 args.add("generations", "number of generationsr", "50");
256 args.add("initial_guess", "initial guess of featues", ""); 257 args.add("initial_guess", "initial guess of featues", "");
257 args.add("debug", "display intermediate data for debugging"); 258 args.add("debug", "display intermediate data for debugging");
258 - args.add("binary", "Select features for binary classes", ""); 259 + args.add("binary", "Calculate features based on class1 vs. all other classes", "");
259 args.add("trim", "this gives wavenumber to use in trim option of siproc which trims all bands from envi file except gagpu selected bands"); 260 args.add("trim", "this gives wavenumber to use in trim option of siproc which trims all bands from envi file except gagpu selected bands");
260 261
261 args.parse(argc,argv); //parse the command line arguments 262 args.parse(argc,argv); //parse the command line arguments
@@ -263,7 +264,7 @@ int main(int argc, char* argv[]){ @@ -263,7 +264,7 @@ int main(int argc, char* argv[]){
263 //Print the help text if set 264 //Print the help text if set
264 if(args["help"].is_set()){ //display the help text if requested 265 if(args["help"].is_set()){ //display the help text if requested
265 advertisement(); 266 advertisement();
266 - std::cout<<std::endl<<"usage: ga-gpu input output --option [A B C ...]"<<std::endl; 267 + std::cout<<std::endl<<"usage: ga-gpu input_ENVI output.txt --classes class1.bmp class2.bmp ... --option [A B C ...]"<<std::endl;
267 std::cout<<std::endl<<std::endl; 268 std::cout<<std::endl<<std::endl;
268 std::cout<<args.str()<<std::endl; 269 std::cout<<args.str()<<std::endl;
269 exit(1); 270 exit(1);