Ignore:
Timestamp:
Jan 15, 2009, 5:57:36 PM (12 years ago)
Author:
Jari Häkkinen
Message:

Addresses #464. Weight zero will kill NaNs? and Infs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/WeNNI.cc

    r1554 r1725  
    66  Copyright (C) 2006 Jari Häkkinen
    77  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Jari Häkkinen
    89
    910  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    4546
    4647
    47 
    4848  // \hat{x_{ij}}=\frac{ \sum_{k=1,N} \frac{w_{kj}*x_{kj}}{d_{ki}} }
    4949  //                   { \sum_{k=1,N} \frac{w_{kj}       }{d_{ki}} }
     
    6666          // Avoid division with zero (perfect match vectors)
    6767          double d=(distance[*k].second ? distance[*k].second : small_number);
    68           new_value+=(weight_(distance[*k].first,j) *
    69                       data_(distance[*k].first,j)/d);
    70           norm+=weight_(distance[*k].first,j)/d;
     68          double w=weight_(distance[*k].first,j)/d;
     69          if (w) {
     70            new_value += w*data_(distance[*k].first,j);
     71            norm      += w;
     72          }
    7173        }
    7274        // No impute if no contributions from neighbours.
    73         if (norm){
     75        if (norm) {
    7476          imputed_data_raw_(i,j) = new_value/norm;
    75           imputed_data_(i,j)=
    76             weight_(i,j)*data_(i,j) + (1-weight_(i,j))* imputed_data_raw_(i,j);
     77          double w=weight_(i,j);
     78          if (w)
     79            imputed_data_(i,j) = w*data_(i,j) + (1-w)*imputed_data_raw_(i,j);
     80          else
     81            imputed_data_(i,j) = imputed_data_raw_(i,j);
    7782        }
    7883        else
Note: See TracChangeset for help on using the changeset viewer.