From be28a23d6126d2fc286caad7c3bdca44bf1aaea2 Mon Sep 17 00:00:00 2001 From: Sancar Adali Date: Tue, 5 Sep 2017 13:07:58 -0400 Subject: [PATCH] set of commits for valgrind fixes. test may be broken --- src/graphm/algorithm.cpp | 27 ++++++++++++- src/graphm/algorithm.h | 4 +- src/graphm/algorithm_path.cpp | 6 ++- src/graphm/algorithm_qcv.cpp | 73 ++++++++++++++++++----------------- 4 files changed, 68 insertions(+), 42 deletions(-) diff --git a/src/graphm/algorithm.cpp b/src/graphm/algorithm.cpp index 57d3fdc..0cbcaa1 100644 --- a/src/graphm/algorithm.cpp +++ b/src/graphm/algorithm.cpp @@ -22,12 +22,35 @@ algorithm::algorithm(std::string fconfig) : rpc(fconfig) { -gm_ldh=NULL;dalpha_ldh=0;bnosymm=false; + gm_ldh=NULL; + dalpha_ldh=0; + bnosymm=false; + df_norm=0; + N=0; + cdesc_matrix='A'; + cscore_matrix='A'; + bverbose=false; + sverbfile=std::string(""); + + N=0; + df_norm=0.0; + } algorithm::algorithm() : rpc() { -gm_ldh=NULL;dalpha_ldh=0;bnosymm=false;df_norm=0;N=0;cdesc_matrix='A';cscore_matrix='A'; + gm_ldh=NULL; + dalpha_ldh=0; + bnosymm=false; + df_norm=0; + N=0; + cdesc_matrix='A'; + cscore_matrix='A'; + bverbose=false; + sverbfile=std::string(""); + + N=0; + df_norm=0.0; } //common framework for graph matching algorithm diff --git a/src/graphm/algorithm.h b/src/graphm/algorithm.h index 933e7a6..34a1834 100644 --- a/src/graphm/algorithm.h +++ b/src/graphm/algorithm.h @@ -47,7 +47,7 @@ class match_result match_result() { gm_P=NULL; salgo = ""; - gm_P_exact=NULL; + gm_P_exact=NULL; inum_iteration=-1; dres = 0.0; dtime = 0.0; @@ -75,7 +75,7 @@ class algorithm : public rpc { public: algorithm(std::string ); - algorithm(); + algorithm() ; match_result gmatch(graph& g, graph& h,gsl_matrix* gm_P_i=NULL, gsl_matrix* gm_ldh=NULL,double dalpha_ldh=-1);//common stuff, virtual match_result match(graph& g, graph& h, gsl_matrix* gm_P_i=NULL, gsl_matrix* gm_ldh=NULL,double dalpha_ldh=-1)=0;//particular method implementation double graph_dist(graph &g,graph &h,gsl_matrix* gm_P,char cscore_matrix); diff --git a/src/graphm/algorithm_path.cpp b/src/graphm/algorithm_path.cpp index c192e8a..dd251d0 100644 --- a/src/graphm/algorithm_path.cpp +++ b/src/graphm/algorithm_path.cpp @@ -21,8 +21,10 @@ match_result algorithm_path::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matrix* _gm_ldh, double dalpha_ldh) { - bool bblast_match=(get_param_i("blast_match")==1); - bool bblast_match_end=(get_param_i("blast_match_proj")==1); + bool bblast_match=false; + bblast_match=(get_param_i("blast_match")==1); + bool bblast_match_end=false; + bblast_match_end=(get_param_i("blast_match_proj")==1); bool bbest_path_proj=(get_param_i("best_path_proj_sol")==1); bool bbest_path_blast_proj=(get_param_i("best_path_blast_proj_sol")==1); bool bbest_path_greedy=(get_param_i("best_path_greedy_sol")==1); diff --git a/src/graphm/algorithm_qcv.cpp b/src/graphm/algorithm_qcv.cpp index e6bdfde..627b209 100644 --- a/src/graphm/algorithm_qcv.cpp +++ b/src/graphm/algorithm_qcv.cpp @@ -23,7 +23,8 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr { if (bverbose) *gout<<"QCV matching"<data,N*N); gsl_matrix* gm_dP_2=gsl_matrix_alloc(N,N); //gsl_vector_view gvv_dP_2=gsl_vector_view_array(gm_dP_2->data,N*N); gsl_matrix_set_zero(gm_dP_2); - + if (gm_P_i==NULL) gsl_matrix_set_all(gm_P,1.0/N); else @@ -79,7 +80,7 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr gsl_matrix_memcpy(gm_P_prev,gm_P); //perm matrix transformation into vector gvv_P=gsl_vector_view_array(gm_P->data,N*N); - + //and in opposite direction for gradient gmv_C=gsl_matrix_view_vector(gv_C,N,N); C=&gmv_C.matrix; @@ -89,7 +90,7 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr gsl_matrix * gm_ddP_prev=gsl_matrix_alloc(N,N); gsl_vector_view gvv_ldh; if (dalpha_ldh>0) - { + { gvv_ldh=gsl_vector_view_array(gm_ldh->data,N*N); if (pdebug.ivalue) gsl_matrix_printout(gm_ldh,"gm_ldh",pdebug.strvalue); }; @@ -107,10 +108,10 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr dt1=clock(); //double r=(dt1-dt0)/CLOCKS_PER_SEC; if (pdebug.ivalue) gsl_matrix_printout(gv_C,"gv_C",pdebug.strvalue); - + //result save gsl_matrix_transpose(C); - if (pdebug.ivalue) gsl_matrix_printout(C,"C=gradient",pdebug.strvalue); + if (pdebug.ivalue) gsl_matrix_printout(C,"C=gradient",pdebug.strvalue); gsl_matrix_scale(C,2); update_C_hungarian(C); double dscale_factor =gsl_matrix_max_abs(C); @@ -118,8 +119,8 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr dscale_factor=dhung_max/dscale_factor; gsl_matrix_scale(C,dscale_factor); //gsl_matrix_transpose(C); - if (pdebug.ivalue) gsl_matrix_printout(C,"scale(C)",pdebug.strvalue); - + if (pdebug.ivalue) gsl_matrix_printout(C,"scale(C)",pdebug.strvalue); + //hungarian, before the true C matrix must be transposed gsl_matrix_transpose(C); dt1=clock(); @@ -130,15 +131,15 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr update_C_hungarian(C,1,true);//return to the original value gsl_matrix_scale(C,0.5); - if (pdebug.ivalue) gsl_matrix_printout(gm_P,"gm_P",pdebug.strvalue); - if (pdebug.ivalue) gsl_matrix_printout(gm_P_prev,"gm_P_prev",pdebug.strvalue); - + if (pdebug.ivalue) gsl_matrix_printout(gm_P,"gm_P",pdebug.strvalue); + if (pdebug.ivalue) gsl_matrix_printout(gm_P_prev,"gm_P_prev",pdebug.strvalue); + //line search gsl_matrix_memcpy(gm_dP,gm_P); gsl_matrix_sub(gm_dP,gm_P_prev); - - if (pdebug.ivalue) gsl_matrix_printout(gm_dP,"gm_dP",pdebug.strvalue); - + + if (pdebug.ivalue) gsl_matrix_printout(gm_dP,"gm_dP",pdebug.strvalue); + double a,b1,b2,bldh; gsl_matrix_transpose(gm_dP); gsl_matrix_transpose(gm_P_prev); @@ -164,7 +165,7 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr gsl_matrix_transpose(gm_P_prev); gsl_matrix_transpose(C); if ((alpha<1) and (alpha>0)) - { + { gsl_matrix_scale(gm_dP,(1-alpha)); gsl_matrix_sub(gm_P,gm_dP); }; @@ -176,16 +177,16 @@ match_result algorithm_qcv::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matr else { dfvalue=f_qcv(gm_Ag_d,gm_Ah_d,gm_P,gm_temp,true); - if (dfvalue>dfvalue_prev) + if (dfvalue>dfvalue_prev) {gsl_matrix_memcpy(gm_P,gm_P_prev); dfvalue=dfvalue_prev;}; }; - if (pdebug.ivalue) gsl_matrix_printout(gm_P,"gm_P_step_finish",pdebug.strvalue); //sparsity + if (pdebug.ivalue) gsl_matrix_printout(gm_P,"gm_P_step_finish",pdebug.strvalue); //sparsity long lsparse=0; for (long j=0;jdata[j]<1e-7); if (bverbose) *gout<<"#zeros="<