示例#1
0
int distance(sha1_hash *md1, sha1_hash *md2) {
  int i;
  int distance = 0;
  for(i = 0; i < SHA_DIGEST_LENGTH; i++) {
    distance += hamdist(md1[i], md2[i]);
  }
  return distance;
}
示例#2
0
Data brute_force_viterbi_decoder(Message data) {
  int min_dist = INT_MAX;
  int dist;
  Data best_fit;
  int i;
  for (i = 0; i < DATA_MAX; ++i) {
    dist = hamdist(memory_falt_encoder(i), data);
    if (dist < min_dist) {
      min_dist = dist;
      best_fit = i;
      if (min_dist == 0) break;
    }
  }
  return best_fit;
}
示例#3
0
void distfun(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], T classDummy)
{
    int     status;
    mwSize  numCoords,numPoints;
    char    metric[4];
    T       *x,*d,*arg,scalarArg;

    /*  get the metric */
    status = mxGetString(prhs[1],metric,4);

  /*  create a pointer to the input matrix y */
    x = (T*)mxGetData(prhs[0]);

  /*  get the dimensions of the matrix input y */
    numCoords = mxGetM(prhs[0]);
    numPoints = mxGetN(prhs[0]);

  /* get extra arg  */
    if (nrhs>2 && !mxIsEmpty(prhs[2])) {
        if (mxGetNumberOfElements(prhs[2]) == 1) {  /*scalar case */
            scalarArg = (T)mxGetScalar(prhs[2]);
        } else if (mxGetClassID(prhs[2]) == mxGetClassID(prhs[0])) {
            arg = (T*)mxGetData(prhs[2]);
        } else {
            mexErrMsgIdAndTxt("stats:pdistmex:MixedInputTypes",
                              "Additional input arguments must be the same class as X.");
        }
    }

    /* make sure that the distance matrix can be created, then create it.  doing
     * this in double remains exact except in the cases where we error out anyway. */
    double numDists = ((double)numPoints * (double)(numPoints-1)) / 2;
    if (numDists >= (double)MWSIZE_MAX) {
        mexErrMsgIdAndTxt("stats:pdistmex:OutputTooLarge",
                          "Distance matrix has more elements than the maximum allowed size in MATLAB.");
    }
    plhs[0] = mxCreateNumericMatrix(1, (mwSize)numDists, mxGetClassID(prhs[0]), mxREAL);
    
  /*  create a pointer to a copy of the output matrix */
    d = (T*)mxGetData(plhs[0]);

  /*  call the appropriate distance subroutine */
    if (strcmp(metric,"euc") == 0)
        eucdist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"seu") == 0)
        seudist(x,numPoints,numCoords,arg,d);
    else if(strcmp(metric,"cit") == 0)
        citdist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"min") == 0)
        mindist(x,numPoints,numCoords,scalarArg,d);
    else if(strcmp(metric,"cos") == 0)
        coscordist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"cor") == 0)
        coscordist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"spe") == 0)
        coscordist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"ham") == 0)
        hamdist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"jac") == 0)
        jacdist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"che") == 0)
        chedist(x,numPoints,numCoords,d);
    else if(strcmp(metric,"mah") == 0)
        mahdist(x,numPoints,numCoords,arg,d);
}
 unsigned hamdist(const ExpandedKMer &k,
                  unsigned tau = hammer::K) const {
   return hamdist(k.s_, tau);
 }