Changeset 228


Ignore:
Timestamp:
Feb 1, 2005, 3:06:51 PM (18 years ago)
Author:
Peter
Message:

moved estimation from constructor, added function telling which rows were not imputed (due too many missing values).

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/NNI.cc

    r177 r228  
    5656  // number, and neighbours are disqualified if their element (column)
    5757  // weight is zero
    58   vector<u_int> NNI::nearest_neighbours(const u_int column,
    59                                         const vector<pair<u_int,double> >& d) const
     58  vector<u_int>
     59  NNI::nearest_neighbours(const u_int column,
     60                          const vector<pair<u_int,double> >& d) const
    6061  {
    6162    vector<u_int> index;
  • trunk/src/NNI.h

    r178 r228  
    7272
    7373    ///
     74    /// Function doing the imputation. @return number of rows not imputed
     75    ///
     76    virtual size_t estimate(void)=0;
     77
     78    ///
    7479    /// @return A const reference to the modified data.
    7580    ///
    7681    const gslapi::matrix& imputed_data(void) const { return imputed_data_; }
    7782
     83    ///
     84    /// @return indices of rows in data matrix not imputed
     85    ///
     86    inline vector<size_t> not_imputed(void) const { return not_imputed_; }
     87
    7888  protected:
    7989    vector<pair<u_int,double> > calculate_distances(const u_int) const;
    80     virtual void estimate(void)=0;
    8190    vector<u_int> nearest_neighbours(const u_int,
    8291                                     const vector<pair<u_int,double> >&) const;
     
    8594    gslapi::matrix imputed_data_;
    8695    u_int neighbours_;
     96    vector<u_int> not_imputed_;
    8797    const gslapi::matrix& weight_;
    8898  };
  • trunk/src/WeNNI.cc

    r177 r228  
    1717    : NNI(matrix,flag,neighbours)
    1818  {
    19     estimate();
     19    //estimate();
    2020  }
    2121
     
    2626  // where N is defined in the paper cited in the NNI class definition
    2727  // documentation.
    28   void WeNNI::estimate(void)
     28  u_int WeNNI::estimate(void)
    2929  {
    3030    using namespace std;
     
    4848        // No impute if no contributions from neighbours.
    4949        if (norm)
    50           imputed_data_(i,j)=weight_(i,j)*data_(i,j)+(1-weight_(i,j))*new_value/norm;
     50          imputed_data_(i,j)=
     51            weight_(i,j)*data_(i,j) + (1-weight_(i,j)) * new_value/norm;
     52        else
     53          not_imputed_.push_back(i);
    5154      }
    5255    }
     56    return not_imputed_.size();
    5357  }
    5458
  • trunk/src/WeNNI.h

    r178 r228  
    2727  {
    2828  public:
     29    ///
     30    /// Constructor
     31    ///
     32    WeNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
     33          const u_int neighbours);
     34
     35    ///
    2936    /// Perform WeNNI on data in \a matrix with continuous uncertainty
    3037    /// weights in \a weight using \a neighbours for the new impute
    3138    /// value.
    3239    ///
    33     /// @note The algorithm is initiated within the constructor and
    34     /// the result is fetched with the NNI::imputed_data method.
    35     WeNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
    36          const u_int neighbours);
     40    u_int estimate(void);
    3741
    3842  private:
    39     void estimate(void);
     43
    4044
    4145  };
  • trunk/src/kNNI.cc

    r177 r228  
    2323          break;
    2424        }
    25     estimate();
     25    //estimate();
    2626  }
    2727
     
    3232  // where N is defined in the paper cited in the NNI class definition
    3333  // documentation.
    34   void kNNI::estimate(void)
     34  u_int kNNI::estimate(void)
    3535  {
    3636    using namespace std;
     
    4545          double new_value=0.0;
    4646          double norm=0.0;
    47           for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++) {
     47          for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++){
    4848            // Jari, a small number needed here, use something standardized.
    4949            // Avoid division with zero (perfect match vectors)
     
    5555          if (norm)
    5656            imputed_data_(mv_rows_[i],j)=new_value/norm;
     57          else
     58            not_imputed_.push_back(i);
    5759        }
    5860    }
     61    return not_imputed_.size();
    5962  }
    6063
  • trunk/src/kNNI.h

    r178 r228  
    2525  {
    2626  public:
     27    ///
     28    /// Constructor
     29    ///
     30    kNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
     31         const u_int neighbours);
     32
     33    ///
    2734    /// Perform kNNI on data in \a matrix with binary uncertainty
    2835    /// weights in \a weight using \a neighbours for the new impute
    2936    /// value.
    3037    ///
    31     /// @note The algorithm is initiated within the constructor and
    32     /// the result is fetched with the NNI::imputed_data method.
    33     kNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
    34          const u_int neighbours);
     38    size_t estimate(void);
    3539
    3640  private:
    37     void estimate(void);
    38 
    3941    vector<u_int> mv_rows_; // index to rows that have values to estimate
    4042  };
Note: See TracChangeset for help on using the changeset viewer.