Changeset 177


Ignore:
Timestamp:
Oct 1, 2004, 10:55:28 AM (18 years ago)
Author:
Jari Häkkinen
Message:

Added documentation and some implementation comments.

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/NNI.cc

    r173 r177  
    1313  using namespace std;
    1414
    15   NNI::NNI(gslapi::matrix& matrix,const gslapi::matrix& weight,
     15  // For a discussion and motivation for various algorithm
     16  // implementations here see the paper cited in the class definition
     17  // documentation.
     18  NNI::NNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
    1619           const u_int neighbours)
    1720    : data_(matrix), imputed_data_(matrix), neighbours_(neighbours),
     
    2124
    2225
    23 
    24 // d_{ij}^2=\frac {\sum_{1,N} w_{il} w_{jl} (x_{il}-x_{jl})^2 }
    25 //                {\sum_{l,N} w_{il} w_{jl} }
     26  // d_{ij}^2=\frac {\sum_{k=1,C} w_{ik} w_{jk} (x_{ik}-x_{jk})^2 }
     27  //                {\sum_{k=l,C} w_{ik} w_{jk} }
     28  // where C is the number of columns
    2629  vector<pair<u_int,double> > NNI::calculate_distances(const u_int row) const
    2730  {
     
    5053
    5154
     55  // Contributing nearest neighbours are added up to the user set
     56  // number, and neighbours are disqualified if their element (column)
     57  // weight is zero
    5258  vector<u_int> NNI::nearest_neighbours(const u_int column,
    5359                                        const vector<pair<u_int,double> >& d) const
  • trunk/src/NNI.h

    r172 r177  
    1616
    1717  ///
    18   /// A missing value estimator
     18  /// NNI is an abstract base class defining the interface for nearest
     19  /// neighbour imputation (NNI) algorithms.
     20  ///
     21  /// NNI algorithms implemented here is discussed in documents
     22  /// created in the WeNNI project. This document will be released for
     23  /// public access, and the necessary information for retrieving that
     24  /// document will be provided here.
     25  ///
     26  /// Short introduction to NNI is that one may want to improve
     27  /// (correct) uncertain data. Here, the data to be imputed is stored in a
     28  /// matrix where rows similar to each other are used to adjust
     29  /// uncertain data. The data matrix is accompanied by a weight
     30  /// (uncertainty) matrix defining what data is to be considered as
     31  /// 'certain' and what data is uncertain. The weight matrix can be
     32  /// binary with 1's indicating that the data does not need
     33  /// corrections, whereas a 0 means that the data should be replaced
     34  /// by an imputed value. Naturally, the weight matrix can also be
     35  /// continuos where values between 0 and 1 defines how certain a
     36  /// data element is.
     37  ///
     38  /// The imputation depends on how similarity of rows of data is
     39  /// defined and on the number of closest neighbours (here; rows) to
     40  /// use in the imputation can be set.
     41  ///
     42  /// Implementation issues
     43  ///
     44  /// The current implementation treats rows where all data are tagget
     45  /// are completely uncertatin, i.e. all weights are zero, by
     46  /// ignoring these lines in nearest neighbourhood
     47  /// calculations. Importantly, this type of data are not changed
     48  /// (imputed) either since there is no close neighbourhood defined
     49  /// for this data.
     50  ///
     51  /// Rows that is completely identical in an imputation algorithm
     52  /// sense will give problems since the distance between will usually
     53  /// become zero. This is solved by setting zero distance to a small
     54  /// number. Identical rows in this context are basically a
     55  /// comparison between elements with non-zero uncertainty weights
     56  /// only, and all these elemnts are equal. Zero weight elemenets are
     57  /// not used in the comparison since these are considered as
     58  /// non/sense values.
    1959  ///
    2060  class NNI
    2161  {
    2262  public:
    23     ///
    24     /// \a matrix is changed.
    25     ///
    26     NNI(gslapi::matrix& matrix,const gslapi::matrix& weight,
     63    /// Base constructor for the nearest neighbour imputation
     64    /// algorithms.
     65    NNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
    2766        const u_int neighbours);
    2867
    2968    virtual ~NNI(void) {};
    3069
     70    /// @return A const reference to the modified data.
    3171    const gslapi::matrix& imputed_data(void) const { return imputed_data_; }
    3272
     
    3777                                     const vector<pair<u_int,double> >&) const;
    3878
    39     gslapi::matrix& data_;
     79    const gslapi::matrix& data_;
    4080    gslapi::matrix imputed_data_;
    4181    u_int neighbours_;
  • trunk/src/WeNNI.cc

    r176 r177  
    1313
    1414
    15   WeNNI::WeNNI(gslapi::matrix& matrix,const gslapi::matrix& flag,
     15  WeNNI::WeNNI(const gslapi::matrix& matrix,const gslapi::matrix& flag,
    1616               const u_int neighbours)
    1717    : NNI(matrix,flag,neighbours)
     
    2222
    2323
    24 // \hat{x_{j}}=\frac{ \sum_{i,N} \frac{w_{ij}*x_i}{d_{ij}} }
    25 //                  { \sum_{i,N} \frac{w_{ij}    }{d_{ij}} }
     24  // \hat{x_{ij}}=\frac{ \sum_{k=1,N} \frac{w_{kj}*x_{kj}}{d_{ki}} }
     25  //                   { \sum_{k=1,N} \frac{w_{kj}       }{d_{ki}} }
     26  // where N is defined in the paper cited in the NNI class definition
     27  // documentation.
    2628  void WeNNI::estimate(void)
    2729  {
  • trunk/src/WeNNI.h

    r146 r177  
    1616
    1717  ///
    18   /// A missing value estimator
     18  /// WeNNI is a continous weights generalization of the (binary
     19  /// weights) kNNI algorithm presented by Troyanska et al. A
     20  /// reference to this paper is found in the NNI document referred to
     21  /// in the NNI class documentation. The NNI document also describes
     22  /// WeNNI in depth.
     23  ///
     24  /// @see NNI and kNNI
    1925  ///
    2026  class WeNNI : public NNI
    2127  {
    2228  public:
     29    /// Perform WeNNI on data in \a matrix with continious uncertainty
     30    /// weights in \a weight using \a neighbours for the new impute
     31    /// value.
    2332    ///
    24     /// \a matrix is changed.
    25     ///
    26     WeNNI(gslapi::matrix& matrix,const gslapi::matrix& weight,
     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,
    2736         const u_int neighbours);
    2837
  • trunk/src/kNNI.cc

    r174 r177  
    1313namespace cpptools {
    1414
    15   kNNI::kNNI(gslapi::matrix& matrix,const gslapi::matrix& flag,
     15  kNNI::kNNI(const gslapi::matrix& matrix,const gslapi::matrix& flag,
    1616             const u_int neighbours)
    1717    : NNI(matrix,flag,neighbours)
     
    2828
    2929
    30 // \hat{x_{j}}=\frac{ \sum_{1,k} \frac{x_i}{d_{ij}} }
    31 //                  { \sum_{1,k} \frac{1  }{d_{ij}} },
     30  // \hat{x_{ij}}=\frac{ \sum_{k=1,N} \frac{x_{kj}}{d_{ki}} }
     31  //                   { \sum_{k=1,N} \frac{1     }{d_{ki}} },
     32  // where N is defined in the paper cited in the NNI class definition
     33  // documentation.
    3234  void kNNI::estimate(void)
    3335  {
  • trunk/src/kNNI.h

    r146 r177  
    1313
    1414  ///
    15   /// A missing value estimator
     15  /// kNNI is the binary weight implementation of NNI. This follows
     16  /// the work done by Troyanska et al. cited in the NNI document
     17  /// referred to in the NNI class documentation.
     18  ///
     19  /// This is a special case of the WeNNI, but is maintained since it
     20  /// is faster than the more general WeNNI.
     21  ///
     22  /// @see NNI and WeNNI
    1623  ///
    1724  class kNNI : public NNI
    1825  {
    1926  public:
     27    /// Perform kNNI on data in \a matrix with binary uncertainty
     28    /// weights in \a weight using \a neighbours for the new impute
     29    /// value.
    2030    ///
    21     /// \a matrix is changed.
    22     ///
    23     kNNI(gslapi::matrix& matrix,const gslapi::matrix& weight,
     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,
    2434         const u_int neighbours);
    2535
Note: See TracChangeset for help on using the changeset viewer.