static double fuzzy(double *x, double *y, int nx, int ny, int nc) { double dist, smax, smin; int count, j; count = 0; smax = smin = 0; for (j = 0; j < nc; j++) { if (both_FINITE(*x, *y)) { if (*x > *y) { smax += *x; smin += *y; } else { smax += *y; smin += *x; } count++; } x += nx; y += ny; } if (count == 0) return NA_REAL; if (!R_FINITE(smin)) return NA_REAL; dist = smin / smax; if (ISNAN(dist)) return 0; return 1-dist; }
static double R_dist_binary(double *x, int nr, int nc, int i1, int i2) { int total, count, dist; int j; total = 0; count = 0; dist = 0; for(j = 0 ; j < nc ; j++) { if(both_non_NA(x[i1], x[i2])) { if(!both_FINITE(x[i1], x[i2])) { warning(_("treating non-finite values as NA")); } else { if(x[i1] || x[i2]) { count++; if( ! (x[i1] && x[i2]) ) dist++; } total++; } } i1 += nr; i2 += nr; } if(total == 0) return NA_REAL; if(count == 0) return 0; return (double) dist / count; }
double dist_binary(t_index i1, t_index i2) const { int total, count, dist; int j; total = 0; count = 0; dist = 0; double * p1 = x+i1*nc; double * p2 = x+i2*nc; for(j = 0 ; j < nc ; ++j) { if(both_non_NA(*p1, *p2)) { if(!both_FINITE(*p1, *p2)) { // warning(_("treating non-finite values as NA")); } else { #if HAVE_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #endif if(*p1 || *p2) { ++count; if( ! (*p1 && *p2) ) { ++dist; } } #if HAVE_DIAGNOSTIC #pragma GCC diagnostic pop #endif ++total; } } ++p1; ++p2; } if(total == 0) return NA_REAL; if(count == 0) return 0; return static_cast<double>(dist) / static_cast<double>(count); }