Changeset 1725


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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/data/knni_matrix.data

    r420 r1725  
    66
    77.8624 .286482 .83248  .72846  .28468  .2347 .23234  .98973  .29874  .32894   .1234
    8 .8624 .286482 .83248  .72846  .28468  .2347 .23234  .98973  .29874  .32894   .1234
     8.8624 .286482 .83248  .72846  NaN .2347 .23234  .98973  .29874  .32894   .1234
    99.2342 .23878  .97437  .76236  .32764  .3474 .43276  .34555  .29948  .34598   .1234
    1010.2347 .56783  .78435  .35763  .23468  .7384 .23578  .345533 .235948 .32458   .1234
  • 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
  • trunk/yat/utility/WeNNI.h

    r1487 r1725  
    1010  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    1111  Copyright (C) 2008 Peter Johansson
     12  Copyright (C) 2009 Jari Häkkinen
    1213
    1314  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3637namespace utility {
    3738
    38   ///
    39   /// @brief Weighted Nearest Neighbour Imputation
    40   ///
    41   /// WeNNI is a continuous weights generalization of the (binary
    42   /// weights) kNNI algorithm presented by Troyanskaya et al. A
    43   /// reference to this paper is found in the NNI document referred to
    44   /// in the NNI class documentation. The NNI document also describes
    45   /// WeNNI in depth.
    46   ///
    47   /// @see NNI and kNNI
    48   ///
     39  /**
     40     \brief Weighted Nearest Neighbour Imputation
     41
     42     WeNNI is a continuous weights generalization of the (binary
     43     weights) kNNI algorithm presented by Troyanskaya et al. A
     44     reference to this paper is found in the NNI document referred to
     45     in the NNI class documentation. The NNI document also describes
     46     WeNNI in depth.
     47
     48     \note Missing values should be represented with a zero
     49     weight. WeNNI will treat the corresponding data values as zero,
     50     i.e., this implies that NaNs and Infs with zero weight will not
     51     have any impact on calculations.a
     52
     53     \see NNI and kNNI
     54  */
    4955  class WeNNI : public NNI
    5056  {
Note: See TracChangeset for help on using the changeset viewer.