void SortedDistanceComparator::calcProperties(
  const SortedDistanceComparator::DistancesVec & dist1,
  const StridedIndexAdapter<size_t> & adapt1,
  const SortedDistanceComparator::DistancesVec & dist2,
  const StridedIndexAdapter<size_t> & adapt2,
  double & sqSum,
  double & max,
  unsigned int & runningComparedTotal) const
{
  const size_t maxIdx = ::std::min(adapt1.inv(dist1.size()), adapt2.inv(dist2.size()));

  double d1, d2, sum, delta;
  for(size_t i = 0; i < maxIdx; ++i)
  {
    d1 = dist1[adapt1(i)];
    d2 = dist2[adapt2(i)];

#if SORTED_DIST_COMP_DEBUG
    if(std::abs(d1 - d2) > 1e-5)
      std::cout << "Diff is: " << std::abs(d1 - d2) << std::endl;
#endif
    sum = d1 + d2;
    delta = sum > 0 ? std::abs(d1 - d2) / sum : 0;
    max   = std::max(max, delta);
    sqSum   += delta * delta;
  }
  runningComparedTotal += maxIdx;
}
Ejemplo n.º 2
0
void
SortedDistanceComparator::calcProperties(spl::math::RunningStats & stats,
    const SortedDistanceComparator::DistancesVec & dist1,
    const StridedIndexAdapter< size_t> & adapt1,
    const SortedDistanceComparator::DistancesVec & dist2,
    const StridedIndexAdapter< size_t> & adapt2) const
{
  const size_t maxIdx = std::min(adapt1.inv(dist1.size()),
      adapt2.inv(dist2.size()));

  double d1, d2, sum;
  for(size_t i = 0; i < maxIdx; ++i)
  {
    d1 = dist1[adapt1(i)];
    d2 = dist2[adapt2(i)];

#if SORTED_DIST_COMP_DEBUG
    if(std::abs(d1 - d2) > 1e-5)
    std::cout << "Diff is: " << std::abs(d1 - d2) << std::endl;
#endif
    sum = d1 + d2;
    if(sum > 0.0)
      stats.insert(2.0 * std::abs(d1 - d2) / sum);
  }
}