void mexFunction( int nlhs, mxArray *plhs[] , int nrhs, const mxArray *prhs[] ) { bool * front; double * M; unsigned int row, col; const mwSize *dims; if(nrhs == 0 || nlhs > 1) { printf("\nsynopsis: front = paretofront(X)"); plhs[0] = mxCreateDoubleMatrix(0 , 0 , mxREAL); return; } M = mxGetPr(prhs[0]); dims = mxGetDimensions(prhs[0]); row = dims[0]; col = dims[1]; /* ----- output ----- */ plhs[0] = mxCreateLogicalMatrix (row , 1); front = (bool *) mxGetPr(plhs[0]); /* main call */ paretofront(front, M, row, col); }
int criteria_MOTS(float **distances, int *classes, int n_elt, int n_feat, int cur, int n_class) { double *data; float *classDist, curDist; int i, j, k = 0, *front, bestClass = -1; data = malloc(n_feat * n_elt * sizeof(double)); for (i = 0; i < n_elt; i++) for (j = 0; j < n_feat; j++) { if (i != cur) { data[k++] = (double)distances[i][j]; } else { data[k++] = FLT_MAX; } } classDist = calloc(n_class, sizeof(float)); front = calloc(n_elt, sizeof(int)); paretofront(front, data, n_elt, n_feat); for (i = 0; i < n_elt; i++) if (front[i] > 0) { for (j = 0, curDist = 0; j < n_feat; j++) if (i != cur) curDist += pow(distances[i][j], 2); classDist[classes[i]] += (1.0 / sqrt(curDist / n_feat)); } for (i = 0, curDist = -1; i < n_class; i++) if (classDist[i] > curDist) { curDist = classDist[i]; bestClass = i; } free(data); free(front); free(classDist); return bestClass; }
int criteria_NPMOTS(float **distances, int *classes, int n_elt, int n_feat, int cur, int n_class) { double curBest = DBL_MAX, *curClassDist, curDist, tmpDist; int i, j, k, l, curClass = -1, curClassSize, *front, n_fr; for (i = 0; i < n_class; i++) { curClassSize = 0; curClassDist = NULL; for (j = 0, k = 0; j < n_elt; j++) if (classes[j] == i && (j != cur)) { curClassDist = realloc(curClassDist, ((++curClassSize) * n_feat) * sizeof(double)); for (l = 0; l < n_feat; l++) curClassDist[k++] = (double)distances[j][l]; } if (curClassSize == 0) continue; front = calloc(curClassSize, sizeof(int)); paretofront(front, curClassDist, curClassSize, n_feat); for (curDist = 0, j = 0, n_fr = 0; j < curClassSize; j++) if (front[j] > 0) { for (tmpDist = 0, l = 0; l < n_feat; l++) tmpDist += pow(curClassDist[(j * n_feat) + l], 2); curDist += (tmpDist / n_feat); n_fr++; } curDist = sqrt(curDist / n_fr); if (curDist < curBest) { curBest = curDist; curClass = i; } free(front); free(curClassDist); } return curClass; }