Commit ab01c2d7d08eb9b32cca2ed00c498be132d7e0b5

Authored by David Mayerich
1 parent 0d840342

Edits to update STIM libraries. Still has a bug (determinants require OpenCV)

CMakeLists.txt
1 1 #Specify the version being used aswell as the language
2   -cmake_minimum_required(VERSION 2.8)
  2 +cmake_minimum_required(VERSION 3.16)
3 3  
4 4 #Name your project here
5 5 project(ga-gpu)
... ... @@ -32,8 +32,8 @@ SET( CUDA_NVCC_FLAGS "--gpu-architecture=compute_50 --gpu-code=sm_50,compute_50"
32 32  
33 33 #find packages-----------------------------------
34 34 #find OpenCV
35   -find_package(OpenCV REQUIRED)
36   -add_definitions(-DUSING_OPENCV)
  35 +#find_package(OpenCV REQUIRED)
  36 +#add_definitions(-DUSING_OPENCV)
37 37  
38 38 #find the pthreads package
39 39 find_package(Threads)
... ...
FindSTIM.cmake
... ... @@ -3,20 +3,14 @@
3 3  
4 4 include(FindPackageHandleStandardArgs)
5 5  
6   -set(STIM_INCLUDE_DIR $ENV{STIMLIB_PATH})
  6 +set(STIM_ROOT $ENV{STIM_ROOT})
7 7  
8   -find_package_handle_standard_args(STIM DEFAULT_MSG STIM_INCLUDE_DIR)
  8 +IF(NOT STIM_ROOT)
  9 + MESSAGE("ERROR: STIM_ROOT environment variable must be set!")
  10 +ENDIF(NOT STIM_ROOT)
9 11  
10   -if(STIM_FOUND)
11   - set(STIM_INCLUDE_DIRS ${STIM_INCLUDE_DIR})
12   -elseif(STIM_FOUND)
13   - #if the STIM library isn't found, download it
14   - #file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/stimlib) #remove the stimlib directory if it exists
15   - #set(STIM_GIT "https://git.stim.ee.uh.edu/codebase/stimlib.git")
16   - #execute_process(COMMAND git clone --depth 1 ${STIM_GIT} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
17   - #set(STIM_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/stimlib" CACHE TYPE PATH)
18   - message("STIM library not found. Set the STIMLIB_PATH environment variable to the STIMLIB location.")
19   - message("STIMLIB can be found here: https://git.stim.ee.uh.edu/codebase/stimlib")
20   -endif(STIM_FOUND)
  12 + FIND_PATH(STIM_INCLUDE_DIRS DOC "Path to STIM include directory."
  13 + NAMES stim/image/image.h
  14 + PATHS ${STIM_ROOT})
21 15  
22   -find_package_handle_standard_args(STIM DEFAULT_MSG STIM_INCLUDE_DIR)
  16 +find_package_handle_standard_args(STIM DEFAULT_MSG STIM_INCLUDE_DIRS)
... ...
src/ga_gpu.h
... ... @@ -4,7 +4,7 @@
4 4 #include <iostream>
5 5 #include <thread>
6 6 #include <complex>
7   -#include <cv.h>
  7 +//#include <cv.h>
8 8 #include <stdio.h>
9 9 #include <stdlib.h>
10 10 #include <iostream>
... ...
src/main.cpp
... ... @@ -153,6 +153,7 @@ void gpuComputeEignS( size_t g, size_t fea){
153 153 std::cout<<std::endl;
154 154 }
155 155  
  156 + ///DETERMINANT CURRENTLY REQUIRES OPENCV
156 157 cv::Mat newSw = cv::Mat((int)r, (int)r, CV_32FC1, nSw); //within scatter of gnome g in the population
157 158 cv::Mat newSb = cv::Mat((int)r, (int)r, CV_32FC1, nSb); //within scatter of gnome g in the population
158 159  
... ... @@ -167,20 +168,6 @@ void gpuComputeEignS( size_t g, size_t fea){
167 168 std::cout << ga.P[ga.f * g + i] << ", ";
168 169 std::cout << std::endl;
169 170 }
170   -// if(!isfinite(gnom.S[g])){
171   -// std::cout<<"-----------------------------------------------"<<std::endl;
172   -// std::cout<<"Displaying intermediate values of gnome for which score is non finite"<<std::endl;
173   -// std::cout<<"population "<<std::endl;
174   -// for(int i = 0; i < ga.f; i++){
175   -// std::cout<<"\t"<<ga.P[g * ga.f + i];
176   -// }
177   -// std::cout<<std::endl;
178   -// std::cout<<"Sb determinant is "<<cv::determinant(newSb)<<"\t Sw determinant is "<<cv::determinant(newSb)<<std::endl;
179   -// std::cout<<"fisher ratio is "<<fisherRatio<<std::endl;
180   -// std::cout<<"Score["<<g<<"]: "<< gnom.S[g]<<std::endl;
181   -// std::cout<<"------------------------------------------------"<<std::endl;
182   -//
183   -// }
184 171  
185 172  
186 173 if(IPIV!= NULL) std::free(IPIV);
... ... @@ -223,8 +210,6 @@ void fitnessFunction( float* sb, float* sw, float* lda, float* M, float* cM, siz
223 210 }
224 211  
225 212 // ----------------------- Linear discriminant Analysis --------------------------------------
226   - //timer.start();
227   - //structure is created to pass variable to thread function as it accepts only 3 arguments
228 213 gnom.S = ga.S;
229 214 gnom.Sw = sw;
230 215 gnom.Sb = sb;
... ... @@ -234,26 +219,13 @@ void fitnessFunction( float* sb, float* sw, float* lda, float* M, float* cM, siz
234 219 for (size_t i = 0; i<ga.p; i++){
235 220 //calling function for eigencomputation
236 221 gpuComputeEignS(i, f);
237   - //std::cout<<"Score["<<i<<"]: "<< ga.S[i]<<std::endl;
238 222 }
239 223  
240   - //std::vector<std::thread> threads;
241   - //for (size_t g = 0; g<ga.p; g++){
242   - // //creating thread to do eigen computation
243   - // threads.push_back(std::thread(gpuComputeEignS, g, f));
244   - //}
245   - //
246   - //// loop again to join the threads
247   - //for (auto& t : threads)
248   - // t.join();
249   -
250 224 const auto elapsed1 = timer.time_elapsed();
251 225 if(gen > ga.gnrtn - 2){
252 226 std::cout << "gpu_eigen time "<<std::chrono::duration_cast<std::chrono::microseconds>(elapsed1).count() << "us" << std::endl;
253 227 profilefile<< "gpu_eigen time "<<std::chrono::duration_cast<std::chrono::microseconds>(elapsed1).count() << "us" << std::endl;
254 228 }
255   - //ga.S = gnom.score;
256   - //size_t bestGnomeIdx = ga.sortSIndx()[0];
257 229  
258 230 }//end of fitness function
259 231  
... ... @@ -276,7 +248,6 @@ void advertisement() {
276 248 std::cout << "=========================================================================" << std::endl;
277 249 std::cout << "Thank you for using the GA-GPU features selection for spectroscopic image!" << std::endl;
278 250 std::cout << "=========================================================================" << std::endl << std::endl;
279   -// std::cout << args.str();
280 251 }
281 252  
282 253 int main(int argc, char* argv[]){
... ... @@ -335,8 +306,7 @@ int main(int argc, char* argv[]){
335 306 E.close(); //close the hyperspectral file
336 307 time_t t_end = time(NULL);
337 308 std::cout<<"Total time: "<<t_end - t_start<<" s"<<std::endl;
338   - //display_PixelfeatureNclass(ga.F, ga.T , B , 1); //Print one value from feature matrix to debug feature loading
339   - //std::cout << "pixel target is " << ga.T[0] << " " << ga.T[1] << " " << ga.T[tP - 2] << " " << ga.T[tP - 1]<<std::endl;
  309 +
340 310 ///--------------------------Genetic algorith configurations with defult paramets and from argument values---------------------
341 311 ga.f = args["features"].as_int(0); //number of features to be selected by user default value is 10
342 312 ga.p = args["population"].as_int(0); //population size to be selected by user default value is 1000
... ... @@ -415,11 +385,6 @@ int main(int argc, char* argv[]){
415 385 HANDLE_ERROR(cudaGetDeviceProperties(&props, 0));
416 386 ga.gpuInitializationfrommain(M, cM, nP, tP, nC);
417 387  
418   -//feture selection for class selected by user with user arguments (make it binary class data by making chosen class label as 1 and al other class labels 0 from multiclass data )
419   -//to select feature for all classes in joint class data using binary class system need to write a script with loop covering all classes
420   - //if(binaryClass){
421   - // binaryclassifier(binClassOne);
422   - //}
423 388  
424 389 //============================= GA evolution by generations ====================================================
425 390 std::vector<unsigned int> bestgnome; //holds best gnome after each generation evaluation
... ... @@ -468,9 +433,6 @@ int main(int argc, char* argv[]){
468 433 std::ofstream csv(outfile.c_str(), std::ios::out); //open outfstream for outfile
469 434 size_t ldaindx = bestG_Indx * (nC-1) * ga.f ; //Compute LDA basis index of best gnome
470 435  
471   - //if(binaryClass){ //this option is for binary class feature selection from joint classes but not fully implemented
472   - // csv<<binClassOne<<std::endl;
473   - //}
474 436  
475 437 //fitness values of best gnome is
476 438 csv<<"best gnome's fitness value is "<<best_S[ga.gnrtn-1]<<std::endl; //output fitness value of best gnome in last generation
... ...