Changeset 656 for trunk/c++_tools


Ignore:
Timestamp:
Sep 22, 2006, 12:07:54 PM (17 years ago)
Author:
Peter
Message:

fixes #145 cleaning up interface of DataLook2D. Those function were introduced only to avoid dynamic_casts in SubsetGenerator? and in the end dynamic_cast was necessary anyway, so these functions are just contaminating the interface.

Location:
trunk/c++_tools/classifier
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/classifier/DataLookup2D.h

    r648 r656  
    7979
    8080    ///
     81    /// @return number of rows
     82    ///
     83    inline size_t rows(void) const { return row_index_.size(); }
     84
     85    ///
    8186    /// @return Data based on selected features.
    8287    ///
     
    99104    ///
    100105    virtual const DataLookup2D*
    101     training_data(const std::vector<size_t>& features,
    102                   const std::vector<size_t>& samples) const=0;
    103 
    104     ///
    105     /// @return number of rows
    106     ///
    107     inline size_t rows(void) const { return row_index_.size(); }
    108 
    109     ///
    110     /// @return sub-Lookup of the DataLookup2D
    111     ///
    112     /// @Note Returns a dynamically allocated DataLookup2D, which has
    113     /// to be deleted by the caller to avoid memory leaks.
    114     ///
    115     virtual const DataLookup2D*
    116106    validation_data(const std::vector<size_t>& train,
    117                     const std::vector<size_t>& val) const=0;
    118 
    119     ///
    120     /// @return sub-Lookup of the DataLookup2D
    121     ///
    122     /// @Note Returns a dynamically allocated DataLookup2D, which has
    123     /// to be deleted by the caller to avoid memory leaks.
    124     ///
    125     virtual const DataLookup2D*
    126     validation_data(const std::vector<size_t>& features,
    127                     const std::vector<size_t>& train,
    128107                    const std::vector<size_t>& val) const=0;
    129108
  • trunk/c++_tools/classifier/KernelLookup.h

    r654 r656  
    221221
    222222    ///
    223     /// @todo remove
    224     /// @note This function will probably be removed
     223    /// Each element in returned KernelLookup is calculated using only
     224    /// selected features (defined by @a index). Each element
     225    /// corresponds to the same pair of samples as in the original
     226    /// KernelLookup.
    225227    ///
    226228    /// @Note Returns a dynamically allocated KernelLookup, which has
    227229    /// to be deleted by the caller to avoid memory leaks.
    228230    ///
    229     const KernelLookup* selected(const std::vector<size_t>&) const;
     231    const KernelLookup* selected(const std::vector<size_t>& index) const;
    230232   
    231233    ///
     
    233235    ///
    234236    inline bool weighted(void) const { return kernel_->weighted(); }
    235 
    236     ///
    237     /// Each column in returned MatrixLook corresponds to the column
    238     /// in KernelLookup. If no weights were used in construction of
    239     /// Kernel, each element in returned MatrixLookup is set to unity.
    240     ///
    241     /// @Note Returns a dynamically allocated MatrixLookup2D, which has
    242     /// to be deleted by the caller to avoid memory leaks.
    243     ///
    244     // Peter remove this
    245     //inline const MatrixLookup* weights(void) const
    246     //{ return new MatrixLookup(kernel_->weights(),column_index_, false); }
    247 
    248237
    249238  private:
  • trunk/c++_tools/classifier/MatrixLookup.cc

    r640 r656  
    155155
    156156  const MatrixLookup*
    157   MatrixLookup::training_data(const std::vector<size_t>& features,
    158                               const std::vector<size_t>& samples) const
    159   {
    160     return new MatrixLookup(*this, features, samples);
    161   }
    162 
    163 
    164 
    165   const MatrixLookup*
    166157  MatrixLookup::validation_data(const std::vector<size_t>& train,
    167158                                const std::vector<size_t>& val) const
    168159  {
    169160    return new MatrixLookup(*this,val, false);
    170   }
    171 
    172 
    173 
    174   const MatrixLookup*
    175   MatrixLookup::validation_data(const std::vector<size_t>& features,
    176                                 const std::vector<size_t>& train,
    177                                 const std::vector<size_t>& val) const
    178   {
    179     return new MatrixLookup(*this,features, val);
    180161  }
    181162
  • trunk/c++_tools/classifier/MatrixLookup.h

    r648 r656  
    6969    /// Constructor creating a lookup into a sub-matrix of @a matrix.
    7070    ///
    71     /// If @a row_vectors is true the new MatrixLookup will be consist
     71    /// If @a row_vectors is true the new MatrixLookup will consist
    7272    /// of the row vectors defined by @a index. This means that the
    7373    /// created MatrixLookup will fullfill:
     
    120120    /// underlying matrix to avoid multiple lookups.
    121121    ///
    122     /// If @a row_vectors is true the new MatrixLookup will be consist
     122    /// If @a row_vectors is true the new MatrixLookup will consist
    123123    /// of the row vectors defined by @a index. This means that the
    124124    /// created MatrixLookup will fullfill:
    125125    /// \f$ MatrixLookup(i,j)=ml(i,index[j])\f$
    126126    ///
    127     /// If @a row_vectors is false the new MatrixLookup will be consist
     127    /// If @a row_vectors is false the new MatrixLookup will consist
    128128    /// of the rolumn vectors defined by @a index. This means that the
    129129    /// created MatrixLookup will fullfill:
     
    156156
    157157    ///
    158     /// Destructor. If MatrixLookup is owner of underlying matrix, the
    159     /// matrix is destroyed.
     158    /// Destructor.
    160159    ///
    161160    virtual ~MatrixLookup();
    162161
    163     ///
    164     /// @todo doc
    165     ///   
     162    /**
     163       the new MatrixLookup will consist of the rolumn vectors
     164       defined by @a index. This means that the returned MatrixLookup
     165       will fullfill: \f$ returned(i,j) = original(index[i],j) \f$
     166
     167       @note If underlying matrix goes out of scope or is deleted, the
     168       returned pointer becomes invalid and the result of further use is
     169       undefined.
     170   
     171    */
    166172    const MatrixLookup* selected(const std::vector<size_t>&) const;
    167173
     
    177183    /// returned pointer becomes invalid and the result of further use is
    178184    /// undefined.
     185    ///
     186    /// @Note Returns a dynamically allocated DataLookup2D, which has
     187    /// to be deleted by the caller to avoid memory leaks.
    179188    ///
    180189    const MatrixLookup* training_data(const std::vector<size_t>& index) const;
     
    192201    /// undefined.
    193202    ///
     203    /**
    194204    const MatrixLookup* training_data(const std::vector<size_t>& features,
    195205                                      const std::vector<size_t>& samples) const;
    196    
     206    */
    197207    ///
    198208    /// The created MatrixLookup corresponds to all rows and the
     
    221231    /// undefined.
    222232    ///
     233    /**
    223234    const MatrixLookup* validation_data(const std::vector<size_t>& features,
    224235                                        const std::vector<size_t>& train,
    225236                                        const std::vector<size_t>& val) const;
     237    */
    226238    ///
    227239    /// @return false
  • trunk/c++_tools/classifier/MatrixLookupWeighted.cc

    r640 r656  
    225225
    226226  const MatrixLookupWeighted*
    227   MatrixLookupWeighted::training_data(const std::vector<size_t>& features,
    228                                       const std::vector<size_t>& samples) const
    229   {
    230     return new MatrixLookupWeighted(*this,features, samples);
    231   }
    232 
    233 
    234 
    235   const MatrixLookupWeighted*
    236227  MatrixLookupWeighted::validation_data(const std::vector<size_t>& train,
    237228                                        const std::vector<size_t>& val) const
    238229  {
    239230    return new MatrixLookupWeighted(*this,val, false);
    240   }
    241 
    242 
    243 
    244   const MatrixLookupWeighted*
    245   MatrixLookupWeighted::validation_data(const std::vector<size_t>& features,
    246                                         const std::vector<size_t>& training,
    247                                         const std::vector<size_t>& val) const
    248   {
    249     return new MatrixLookupWeighted(*this,features, val);
    250231  }
    251232
  • trunk/c++_tools/classifier/MatrixLookupWeighted.h

    r648 r656  
    213213   
    214214    ///
    215     /// The created MatrixLookupWeighted corresponds to rows defined
    216     /// by @a features and columns defined by @a samples in the
    217     /// original MatrixLookupWeighted. The created
    218     /// MatrixLookupWeighted will fullfill:
    219     /// \f$ novel_ml(i,j)=original(features[i],samples[j]) \f$.
    220     ///
    221     /// @return pointer to sub-Lookup of the MatrixLookupWeighted
    222     ///
    223     /// @note If underlying matrix goes out of scope or is deleted, the
    224     /// returned pointer becomes invalid and the result of further use is
    225     /// undefined.
    226     ///
    227     const MatrixLookupWeighted*
    228     training_data(const std::vector<size_t>& features,
    229                   const std::vector<size_t>& samples) const;
    230    
    231     ///
    232215    /// The created MatrixLookupWeighted corresponds to all rows and the
    233216    /// columns defined by @a index in the original MatrixLookupWeighted. The
     
    243226    const MatrixLookupWeighted* validation_data(const std::vector<size_t>&,
    244227                                        const std::vector<size_t>&) const;
    245 
    246     ///
    247     /// The created MatrixLookupWeighted corresponds to rows defined
    248     /// by @a features and columns defined by @a val in the original
    249     /// MatrixLookupWeighted. The created MatrixLookupWeighted will
    250     /// fullfill: \f$ novel_ml(i,j)=original(features[i],val[j]) \f$.
    251     ///
    252     /// @return pointer to sub-Lookup of the MatrixLookupWeighted
    253     ///
    254     /// @note If underlying matrix goes out of scope or is deleted, the
    255     /// returned pointer becomes invalid and the result of further use is
    256     /// undefined.
    257     ///
    258     const MatrixLookupWeighted*
    259     validation_data(const std::vector<size_t>& features,
    260                     const std::vector<size_t>& training,
    261                     const std::vector<size_t>& val) const;
    262228
    263229    ///
  • trunk/c++_tools/classifier/SubsetGenerator.cc

    r640 r656  
    8787       
    8888        // Dynamically allocated. Must be deleted in destructor.
    89         training_data_.push_back(ml->training_data(features_.back(),
    90                                                     training_index()));
    91         validation_data_.push_back(ml->validation_data(features_.back(),
    92                                                         training_index(),
    93                                                         validation_index()));
     89        training_data_.push_back(new MatrixLookup(*ml,features_.back(),
     90                                                  training_index()));
     91        validation_data_.push_back(new MatrixLookup(*ml,features_.back(),
     92                                                    validation_index()));     
    9493      }
    9594    }
     
    113112         
    114113          // Dynamically allocated. Must be deleted in destructor.
    115           training_data_.push_back(ml->training_data(features_.back(),
    116                                                      training_index()));
    117           validation_data_.push_back(ml->validation_data(features_.back(),
    118                                                          training_index(),
    119                                                          validation_index()));
    120          
     114          training_data_.push_back(new MatrixLookupWeighted(*ml,
     115                                                            features_.back(),
     116                                                            training_index()
     117                                                            ));
     118          validation_data_.push_back(new MatrixLookupWeighted(*ml,
     119                                                              features_.back(),
     120                                                              validation_index()
     121                                                              ));     
    121122        }
    122123      }
Note: See TracChangeset for help on using the changeset viewer.