Changeset 174


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

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

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/WeNNI.cc

    r172 r174  
    3737        double norm=0.0;
    3838        for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++) {
    39           new_value+=1.0*data_(distance[*k].first,j)/(distance[*k].second);
    40           norm+=1.0/(distance[*k].second);
     39          // Jari, a small number needed here, use something standardized.
     40          // Avoid division with zero (perfect match vectors)
     41          double d=(distance[*k].second ? distance[*k].second : 1e-10);
     42          new_value+=1.0*data_(distance[*k].first,j)/d;
     43          norm+=1.0/d;
    4144        }
    4245        // No impute if no contributions from neighbours.
  • 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.