Esempio n. 1
0
float Permutation::calculateKendall(const Permutation & compare) const
{
  float score=0;
  vector<int> compareArray = compare.getArray();
  if (getLength() != compare.getLength()) {
    cerr << "1stperm: " << getLength() << " 2ndperm: " << compare.getLength() << endl;
    throw runtime_error("Length of permutations not equal");
  }
  if (getLength() == 0) {
    cerr << "Empty permutation" << endl;
    return 0;
  }
  for (size_t i=0; i<getLength(); i++) {
    for (size_t j=0; j<getLength(); j++) {
      if ((m_array[i] < m_array[j]) && (compareArray[i] > compareArray[j])) {
        score++;
      }
    }
  }
  score = (score / ((getLength()*getLength() - getLength()) /2  ) );
  //Adjusted Kendall's tau correlates better with human judgements
  score = sqrt (score);
  score = 1 - score;

  return score;
}
Esempio n. 2
0
float Permutation::calculateHamming(const Permutation & compare) const
{
  float score=0;
  vector<int> compareArray = compare.getArray();
  if (getLength() != compare.getLength()) {
    cerr << "1stperm: " << getLength() << " 2ndperm: " << compare.getLength() << endl;
    throw runtime_error("Length of permutations not equal");
  }
  if (getLength() == 0) {
    cerr << "Empty permutation" << endl;
    return 0;
  }
  for (size_t i=0; i<getLength(); i++) {
    if (m_array[i] != compareArray[i]) {
      score++;
    }

  }
  score = 1 - (score / getLength());
  return score;
}