Changeset 174 for trunk/src/kNNI.cc


Ignore:
Timestamp:
Sep 29, 2004, 2:54:38 PM (17 years ago)
Author:
Jari Häkkinen
Message:

Added checks on perfect match rows, i.e. avoid zero (distance) division.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kNNI.cc

    r172 r174  
    4444          double norm=0.0;
    4545          for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++) {
    46             new_value+=data_(distance[*k].first,j)/(distance[*k].second);
    47             norm+=1.0/(distance[*k].second);
     46            // Jari, a small number needed here, use something standardized.
     47            // Avoid division with zero (perfect match vectors)
     48            double d=(distance[*k].second ? distance[*k].second : 1e-10);
     49            new_value+=data_(distance[*k].first,j)/d;
     50            norm+=1.0/d;
    4851          }
    4952          // No impute if no contributions from neighbours.
Note: See TracChangeset for help on using the changeset viewer.