// For a number of horizontal shifts, find the optimal shift alignData shapeAlign::getOptimalShift(gsl_matrix *A1, gsl_matrix *A2){ alignData results; // Container for holding optimal shift results results.score = -10000; // Initialize results.score to a large negative number results.shift = 0; double score; // Perform a bunch of shifts, keeping track of the optimal score for (int s = shiftMin; s <= shiftMax; s++){ // Initialize a matrix delta to contain the element-wise differences // in the overlapping region int delSize = A2->size2-abs(s); // Get the values that fall within the overlapping region as // submatrices gsl_matrix_view subA1v = (s <= 0 ? gsl_matrix_submatrix(A1,0,0,m,A1->size2+s) : gsl_matrix_submatrix(A1,0,s,m,A1->size2-s) ); gsl_matrix_view subA2v = ( s <= 0 ? gsl_matrix_submatrix(A2,0,abs(s),m,A2->size2+s) : gsl_matrix_submatrix(A2,0,0,m,A2->size2-s) ); gsl_matrix *S1 = gsl_matrix_alloc(m,delSize); gsl_matrix_memcpy(S1,&subA1v.matrix); gsl_matrix *S2 = gsl_matrix_alloc(m,delSize); gsl_matrix_memcpy(S2,&subA2v.matrix); for (size_t j = 0; j < delSize; j++){ for (size_t i = 0; i < m; i++){ if (window && (j <= winStart || j >= winEnd)) s <=0 ? gsl_matrix_set(S1,i,j,0) : gsl_matrix_set(S2,i,j,0); if (ignore && (j >= ignStart && j <= ignEnd)) s <=0 ? gsl_matrix_set(S1,i,j,0) : gsl_matrix_set(S2,i,j,0); } } score = cosineSim(S1,S2); if (score > results.score ){ results.score = score; results.shift = s; } gsl_matrix_free(S1); gsl_matrix_free(S2); } return results; }
int main() { d2v_ctx_t d2v_ctx; d2v_status_t ret; d2v_vector_t doc_vec; // for create threshhold d2v_vector_t pdvlVector; float score; int pdvlcount =0; pdvl_ctx_t pdvl; pdvl_status_t pdvlRet; pdvl_count_t getcount; int i, j; int cnt; //pdvl open pdvlRet = pdvl_open(&pdvl, "default.pdvl"); if(pdvlRet == PDVL_STATUS_FAIL){ printf("pdvl open error!\n"); return 0; } // for(cnt = 1; cnt <2; cnt++){ for(cnt = 1; cnt <24; cnt++){ char filePath[40]; char filename[25] = "../example/training/test"; char filetype[5] = ".txt"; sprintf(filePath, "%s%d%s", filename, cnt, filetype); printf("%s\n", filePath); // Open input text file: test.txt ret = d2v_open(&d2v_ctx,filePath); if( ret != D2V_STATUS_SUCCESS ){ printf("d2v open error!\n"); return 0; } // Convert the input to it's document vector representation: doc_vec d2v_get_document_vector(&d2v_ctx, &doc_vec); // traing for( i = 0; i < doc_vec.length; i++){ pdvl_update_count(&pdvl, doc_vec.element[i].id, doc_vec.element[i].count); } // traing한후 pdvl과 d2v와의 threshold를 저장하자 init(&pdvlVector, doc_vec.length); for(j = 0; j < doc_vec.length; j++){ getcount = pdvl_get_count(&pdvl, doc_vec.element[j].id); if(getcount == -1) pdvlcount = 0; else pdvlcount = getcount; pdvlVector.element[j].id = doc_vec.element[j].id; pdvlVector.element[j].count = pdvlcount; } score = cosineSim(doc_vec, pdvlVector); getThreshold(score); vector_free(&pdvlVector); ///////////////////////////////////////////////// // Cleanup d2v_free_vector(&doc_vec); d2v_close(&d2v_ctx); } pdvl_close(&pdvl); return 0; }