double pearson ( const mclv* a , const mclv* b , dim n ) { double suma = mclvSum(a) ; double sumb = mclvSum(b) ; double sumasq = mclvPowSum(a, 2.0) ; double sumbsq = mclvPowSum(b, 2.0) ; double nom = sqrt( (n*sumasq - suma*suma) * (n*sumbsq - sumb*sumb) ) ; double num = n * mclvIn(a, b) - suma * sumb ; return nom ? num / nom : 0.0 ; }
double get_score ( const mclv* c , const mclv* d , const mclv* c_start , const mclv* d_start , const mclv* c_end , const mclv* d_end ) { mclv* vecc = mclvClone(c) ; mclv* vecd = mclvClone(d) ; mclv* meet_c = mcldMeet(vecc, vecd, NULL) ; mclv* meet_d = mcldMeet(vecd, meet_c, NULL) ; mclv* cwid = mclvBinary(c_end, c_start, NULL, fltSubtract) ; mclv* dwid = mclvBinary(d_end, d_start, NULL, fltSubtract) ; mclv* rmin = mclvBinary(c_end, d_end, NULL, fltMin) ; mclv* lmax = mclvBinary(c_start, d_start, NULL, fltMax) ; mclv* delta = mclvBinary(rmin, lmax, NULL, fltSubtract) ; mclv* weightc, *weightd ; double ip, cd, csn, meanc, meand, mean, euclid, meet_fraction, score, sum_meet_c, sum_meet_d, reduction_c, reduction_d ; int nmeet = meet_c->n_ivps ; int nldif = vecc->n_ivps - nmeet ; int nrdif = vecd->n_ivps - nmeet ; mclvSelectGqBar(delta, 0.0) ; weightc= mclvBinary(delta, cwid, NULL, mydiv) ; weightd= mclvBinary(delta, dwid, NULL, mydiv) #if 0 ;if (c != d)mclvaDump ( cwid , stdout , 5 , "\n" , 0) ,mclvaDump ( dwid , stdout , 5 , "\n" , 0) #endif ; sum_meet_c = 0.01 + mclvSum(meet_c) ; sum_meet_d = 0.01 + mclvSum(meet_d) ; mclvBinary(meet_c, weightc, meet_c, fltMultiply) ; mclvBinary(meet_d, weightd, meet_d, fltMultiply) ; reduction_c = mclvSum(meet_c) / sum_meet_c ; reduction_d = mclvSum(meet_d) / sum_meet_d ; ip = mclvIn(meet_c, meet_d) ; cd = sqrt(mclvPowSum(meet_c, 2.0) * mclvPowSum(meet_d, 2.0)) ; csn = cd ? ip / cd : 0.0 ; meanc = meet_c->n_ivps ? mclvSum(meet_c) / meet_c->n_ivps : 0.0 ; meand = meet_d->n_ivps ? mclvSum(meet_d) / meet_d->n_ivps : 0.0 ; mean = MCX_MIN(meanc, meand) ; euclid = 0 ? 1.0 : ( mean ? sqrt(mclvPowSum(meet_c, 2.0) / mclvPowSum(vecc, 2.0)) : 0.0 ) ; meet_fraction = pow((meet_c->n_ivps * 1.0 / vecc->n_ivps), 1.0) ; score = mean * csn * euclid * meet_fraction * 1.0 ; mclvFree(&meet_c) ; mclvFree(&meet_d) ; fprintf ( stdout , "%10d%10d%10d%10d%10d%10g%10g%10g%10g%10g%10g%10g\n" , (int) c->vid , (int) d->vid , (int) nldif , (int) nrdif , (int) nmeet , score , mean , csn , euclid , meet_fraction , reduction_c , reduction_d ) ; return score ; }