Changeset 826 for trunk/yat/classifier


Ignore:
Timestamp:
Mar 19, 2007, 6:45:30 PM (14 years ago)
Author:
Peter
Message:

documentation and some minor fixes Fixes #135

Location:
trunk/yat/classifier
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/DataLookup2D.h

    r720 r826  
    3636  ///
    3737  /// This is the abstract base class defining a common interface for
    38   /// MatrixLookup and KernelLookup. The general idea o the Lookup
     38  /// MatrixLookup and KernelLookup. The general idea of the Lookup
    3939  /// classes is to: rather than copying the sub-matrix or sub-kernel,
    4040  /// to hold a pointer to the underlying matrix/kernel and a vector
     
    4444  /// This allow fast construction of sub-matrices/sub-kernels and at
    4545  /// almost no extra memory usage.
     46  ///
     47  /// There is a possibility to set DataLookup2D as owner of the
     48  /// underlying data. This implies that underlying data is deleted in
     49  /// destructor of DataLookup2D (actually in destructor of inherited
     50  /// class since underlying data is class specific), but only if
     51  /// there is no other owner of the underlying data. A reference
     52  /// counter is used to keep track of number of owners.
    4653  ///
    4754  class DataLookup2D
  • trunk/yat/classifier/KernelLookup.cc

    r757 r826  
    135135
    136136
    137   const Kernel* KernelLookup::kernel(void) const
    138   {
    139     return kernel_;
    140   }
    141 
    142 
    143137  const KernelLookup*
    144138  KernelLookup::selected(const std::vector<size_t>& inputs) const
  • trunk/yat/classifier/KernelLookup.h

    r720 r826  
    5454  ///
    5555  /// There is a possibility to set the KernelLookup as owner of the
    56   /// underlying Kernel. In that case the underlying Kernel will be
    57   /// destroyed in the destructor. Consequently, the underlying Kernel
    58   /// must have been dynamically allocated and no other KernelLookup
    59   /// can own the Kernel.
     56  /// underlying kernel. This implies that underlying kernel is deleted
     57  /// in destructor of MatrixLookup, but only if there is no other
     58  /// owner of the underlying kernel. A reference counter is used to
     59  /// keep track of number of owners. Ownership is copied in copy
     60  /// constructors and assignments.
    6061  ///
    6162  class KernelLookup : public DataLookup2D
     
    6970    /// Constructs a KernelLookup corresponding to the Kernel @a
    7071    /// kernel. By default @a owner is set to false, which means
    71     /// KernelLookup does not own the underlying Kernel. If
    72     /// KernelLookup owns the Kernel the Kernel will be deleted
    73     /// in the destructor.
     72    /// KernelLookup does not own the underlying Kernel.
    7473    ///
    7574    /// @note If underlying Kernel goes out of scope or is deleted, the
     
    106105    ///
    107106    /// A Lookup is created looking into the
    108     /// same underlying Kernel as @a kl is looking into. The newly
    109     /// created KernelLookup does not own the underlying Kernel.
     107    /// same underlying Kernel as @a kl is looking into.
     108    ///
     109    /// If \a kl is owner of underlying data, constructed
     110    /// KernelLookup will also be set as owner of underlying data.
    110111    ///
    111112    KernelLookup(const KernelLookup& kl);
     
    123124    /// undefined in case underlying Kernel is destroyed.
    124125    ///
     126    /// If \a kl is owner of underlying data, constructed
     127    /// KernelLookup will also be set as owner of underlying data.
     128    ///
    125129    /// @note For training usage row index shall always be equal to
    126130    /// column index.
     
    134138    /// equally many rows as @a kernel.
    135139    ///
     140    /// If \a kl is owner of underlying data, constructed
     141    /// KernelLookup will also be set as owner of underlying data.
     142    ///
    136143    /// @note If underlying kernel goes out of scope or is deleted, the
    137144    /// KernelLookup becomes invalid and the result of further use is
     
    144151    /// @brief Destructor
    145152    ///
    146     /// Deletes underlying Kernel if KernelLookup owns it.
     153    /// Deletes underlying Kernel if KernelLookup owns it and there is
     154    /// no other owner.
    147155    ///
    148156    virtual ~KernelLookup(void);
    149157
    150158    ///
    151     /// Each column in returned MatrixLookup corresponds to the column
     159    /// Each column in returned DataLookup corresponds to the column
    152160    /// in KernelLookup.
     161    ///
     162    /// \return data that KernelLookup is built upon.
    153163    ///
    154164    /// @Note Returns a dynamically allocated MatrixLookup, which has
     
    156166    ///
    157167    const DataLookup2D* data(void) const;
     168
     169    /**
     170       Function to calculate a new Kernel element using the underlying
     171       KernelFunction. The value is calculated between @a vec and the
     172       data vector of the \a i th sample, in other words, the
     173       sample corresponding to the \a i th row.
     174    */
     175    double element(const DataLookup1D& vec, size_t i) const;
    158176
    159177    /**
     
    166184       vector corresponding to \f$ i \f$ th row.
    167185    */
    168     double element(const DataLookup1D& vec, size_t i) const;
    169 
    170     /**
    171        Function to calculate a new Kernel element using the underlying
    172        KernelFunction. The value is calulated between @a vec and the
    173        data vector of the \f$ i \f$ th sample, in other words, the
    174        sample corresponding to the \f$ i \f$ th row or \f$ i \f$ th
    175        column. In case KernelLookup is a sub-Kernel and not symmetric,
    176        the kernel value is calculated between @a vec and the data
    177        vector corresponding to \f$ i \f$ th row.
    178     */
    179186    double element(const DataLookupWeighted1D& vec, size_t i) const;
    180 
    181     const Kernel* kernel(void) const;
    182187
    183188    /**
     
    193198   
    194199    /**
    195        This function is useful when predicting on a independent data
     200       This function is useful when predicting on an independent data
    196201       set using a kernel-based classifier. In returned KernelLookup
    197202       column \f$ i \f$ corresponds to column \f$ i \f$ in @a
     
    208213
    209214    /**
    210        This function is useful when predicting on a independent data
     215       This function is useful when predicting on an independent data
    211216       set using a kernel-based classifier. In returned KernelLookup
    212217       column \f$ i \f$ corresponds to column \f$ i \f$ in @a
  • trunk/yat/classifier/MatrixLookup.cc

    r781 r826  
    2525#include "yat/utility/matrix.h"
    2626
    27 #ifndef NDEBUG
    2827#include <algorithm>
    29 #endif
    30 
    3128#include <cassert>
    3229#include <fstream>
     
    3936    : DataLookup2D(own), data_(&data)
    4037  {
     38    row_index_.reserve(data_->rows());
    4139    for(size_t i=0;i<(*data_).rows();i++)
    4240      row_index_.push_back(i);
     41    column_index_.reserve(data_->columns());
    4342    for(size_t i=0;i<(*data_).columns();i++)
    4443      column_index_.push_back(i);
  • trunk/yat/classifier/MatrixLookup.h

    r767 r826  
    4949  /// to a row and a column in the Kernel, respectively. This design
    5050  /// allow for fast creation of sub-matrices, which is a common
    51   /// operation in most traning/validation procedures.
     51  /// operation in most traning/validation procedures. The views are
     52  /// const views in the sense that they cannot modify underlying
     53  /// matrix.
    5254  ///
    5355  /// A MatrixLookup can be created directly from a matrix or from an
     
    5759  ///
    5860  /// There is a possibility to set the MatrixLookup as owner of the
    59   /// underlying matrix.
     61  /// underlying matrix. This implies that underlying data is deleted
     62  /// in destructor of MatrixLookup, but only if there is no other
     63  /// owner of the underlying data. A reference counter is used to
     64  /// keep track of number of owners. Ownership is copied in copy
     65  /// constructors and assignments.
    6066  ///
    6167  class MatrixLookup : public DataLookup2D
     
    6874    /// Constructor creating a lookup into the entire @a matrix.
    6975    /// @param own if true MatrixLookup owns its underlying @a matrix
     76    ///
     77    /// @note If \a own is true and \a matrix is already owned by some
     78    /// other object, this will lead to \a matrix having multiple
     79    /// owners without the owners being aware of each
     80    /// other. Consequently multiple deletion will occur.
    7081    ///
    7182    /// @note If @a matrix goes out of scope or is deleted, the
     
    115126    /// @brief Copy constructor.
    116127    ///
    117     /// @note If underlying matrix goes out of scope or is deleted, the
    118     /// MatrixLookup becomes invalid and the result of further use is
    119     /// undefined.
    120     ///
    121     MatrixLookup(const MatrixLookup&);
    122 
    123     ///
    124     /// Creates a sub-MatrixLookup. The Lookup is independent of
     128    /// If \a other is owner of underlying data, constructed
     129    /// MatrixLookup will also be set as owner of underlying data.
     130    ///
     131    /// @note If underlying matrix goes out of scope or is deleted, the
     132    /// MatrixLookup becomes invalid and the result of further use is
     133    /// undefined.
     134    ///
     135    MatrixLookup(const MatrixLookup& other);
     136
     137    ///
     138    /// @brief Create a sub-MatrixLookup.
     139    ///
     140    /// The Lookup is independent of
    125141    /// MatrixLookup @a ml. The MatrixLookup is created to look
    126142    /// directly into the underlying matrix to avoid multiple lookups.
    127143    ///
     144    /// If \a ml is owner of underlying data, constructed
     145    /// MatrixLookup will also be set as owner of underlying data.
     146    ///
    128147    /// The @a row and @a column define what sub-matrix to look into,
    129148    /// in other words, the created MatrixLookup will fullfill the
    130     /// following: \f$ MatrixLookup(i,j)=ml(row[i],column[j]) \f$. This
     149    /// following: MatrixLookup(i,j)=ml(row[i],column[j]). This
    131150    /// also means that number of rows in created MatrixLookup is
    132151    /// equal to size of vector @a row, and number of columns is equal
    133152    /// to size of vector @a column.
    134153    ///
     154    /// If \a ml is owner of underlying data, constructed
     155    /// MatrixLookup will also be set as owner of underlying data.
     156    ///
    135157    /// @note If underlying matrix goes out of scope or is deleted, the
    136158    /// MatrixLookup becomes invalid and the result of further use is
     
    148170    /// of the row vectors defined by @a index. This means that the
    149171    /// created MatrixLookup will fullfill:
    150     /// \f$ MatrixLookup(i,j)=ml(i,index[j])\f$
     172    /// MatrixLookup(i,j)=ml(i,index[j])
    151173    ///
    152174    /// If @a row_vectors is false the new MatrixLookup will consist
     
    154176    /// created MatrixLookup will fullfill:
    155177    /// \f$ MatrixLookup(i,j) = ml(index[i],j) \f$
     178    ///
     179    /// If \a ml is owner of underlying data, constructed
     180    /// MatrixLookup will also be set as owner of underlying data.
    156181    ///
    157182    /// @note If underlying matrix goes out of scope or is deleted, the
     
    181206
    182207    ///
    183     /// Destructor.
     208    /// @brief Destructor.
     209    ///
     210    /// If ownership is set true and there is no other owner of
     211    /// underlying data, underlying data is deleted.
    184212    ///
    185213    virtual ~MatrixLookup();
     
    244272    ///
    245273    /// Does only change MatrixLookup not the underlying matrix
    246     /// object. However if the MatrixLookup is owner of its underlying
     274    /// object. However if the MatrixLookup is owner (and the only owner)
     275    /// of its underlying
    247276    /// matrix, that matrix will be deleted here.
    248277    ///
  • trunk/yat/classifier/MatrixLookupWeighted.cc

    r781 r826  
    2525#include "yat/utility/matrix.h"
    2626
    27 #ifndef NDEBUG
    2827#include <algorithm>
    29 #endif
    30 
    3128#include <cassert>
    3229#include <fstream>
     
    315312    for(size_t i=0, j=0; i<m.rows(); i++)
    316313      for (j=0; j<m.columns(); j++) {
    317         s << m(i,j);
     314        if (m.weight(i,j))
     315          s << m.data(i,j);
    318316        if (j<m.columns()-1)
    319317          s << s.fill();
  • trunk/yat/classifier/MatrixLookupWeighted.h

    r767 r826  
    4444  /// A MatrixLookupWeighted is very similar to a MatrixLookup, but
    4545  /// contains a pointer to a weight matrix as well meaning each data
    46   /// element is associated to weight.
     46  /// element is associated to a weight.
    4747  ///
    4848  /// A MatrixLookupWeighted can be created directly from a matrix or
     
    5252  ///
    5353  /// There is a possibility to set the MatrixLookupWeighted as owner
    54   /// of the underlying matrices (data and weight). In that case the
    55   /// underlying matrix will be destroyed in the
    56   /// destructor. Consequently, the underlying matricis must have been
    57   /// dynamically allocated and no other MatrixLookupWeighted can own
    58   /// the matrices.
     54  /// of the underlying matrices (data and weight).
     55  /// This implies that underlying data is deleted
     56  /// in destructor of MatrixLookupWeighted, but only if there is no other
     57  /// owner of the underlying data. A reference counter is used to
     58  /// keep track of number of owners. Ownership is copied in copy
     59  /// constructors and assignments.
    5960  ///
    6061  class MatrixLookupWeighted : public DataLookup2D
     
    6566
    6667    ///
    67     /// Constructor creating a lookup into the entire @a matrix.
     68    /// Constructor creating a lookup into the entire \a matrix and \a
     69    /// weights.
    6870    ///
    6971    /// @note If @a matrix or @a weights goes out of scope or is
     
    7981    /// Constructor creating a lookup into the entire @a matrix.  A
    8082    /// weight matrix is constructed with weights 1 for values and 0
    81     /// for nan's in @a matrix. @note If @a matrix goes out of scope or
     83    /// for nan's in @a matrix.
     84    ///
     85    /// \see  bool utility::nan(const matrix&, matrix&);
     86    ///
     87    /// @note If @a matrix goes out of scope or
    8288    /// is deleted, the MatrixLookupWeighted becomes invalid and the
    8389    /// result of further use is undefined.
     
    9096    /// The @a row and @a column define what sub-matrix to look into,
    9197    /// in other words, the created MatrixLookupWeighted will fullfill
    92     /// the following: \f$
     98    /// the following:
    9399    /// MatrixLookupWeighted(i,j)=matrix(row[i],column[j])
    94     /// weights(row[i],column[j])\f$. This also means that number of
     100    /// weights(row[i],column[j]). This also means that number of
    95101    /// rows in created MatrixLookupWeighted is equal to size of
    96102    /// vector @a row, and number of columns is equal to size of
     
    111117    /// If @a row_vectors is true the new MatrixLookupWeighted will be
    112118    /// consist of the row vectors defined by @a index. This means
    113     /// that the created MatrixLookupWeighted will fullfill: \f$
     119    /// that the created MatrixLookupWeighted will fullfill:
    114120    /// MatrixLookupWeighted(i,j)=matrix(i,index[j])*weights(i,index[j])
    115     /// \f$
     121    ///
    116122    ///
    117123    /// If @a row_vectors is false the new MatrixLookupWeighted will be consist
    118124    /// of the rolumn vectors defined by @a index. This means that the
    119125    /// created MatrixLookupWeighted will fullfill:
    120     /// \f$ MatrixLookupWeighted(i,j)=matrix(index[i],j) \f$
     126    ///
    121127    ///
    122128    /// @note If @a matrix or @a weights goes out of scope or is
     
    130136
    131137    ///
    132     /// @brief
     138    /// @brief Copy constructor.
     139    ///
     140    /// If \a other is owner of underlying data, constructed
     141    /// MatrixLookup will also be set as owner of underlying data.
    133142    ///
    134143    /// @note If underlying matrix goes out of scope or is deleted, the
     
    136145    /// undefined.
    137146    ///
    138     //MatrixLookupWeighted(const MatrixLookup&, const MatrixLookup);
    139 
    140     ///
    141     /// @brief Copy constructor.
    142     ///
    143     /// @note If underlying matrix goes out of scope or is deleted, the
    144     /// MatrixLookupWeighted becomes invalid and the result of further use is
    145     /// undefined.
    146     ///
    147     MatrixLookupWeighted(const MatrixLookupWeighted&);
     147    MatrixLookupWeighted(const MatrixLookupWeighted& other);
    148148
    149149    ///
     
    159159    /// to size of vector @a column.
    160160    ///
     161    /// If \a ml is owner of underlying data, constructed
     162    /// MatrixLookup will also be set as owner of underlying data.
     163    ///
    161164    /// @note If underlying matrix goes out of scope or is deleted, the
    162165    /// MatrixLookupWeighted becomes invalid and the result of further use is
     
    182185    /// \f$ MatrixLookupWeighted(i,j) = ml(index[i],j) \f$
    183186    ///
     187    /// If \a ml is owner of underlying data, constructed
     188    /// MatrixLookup will also be set as owner of underlying data.
     189    ///
    184190    /// @note If underlying matrix goes out of scope or is deleted, the
    185191    /// MatrixLookupWeighted becomes invalid and the result of further use is
     
    210216
    211217    ///
    212     /// Destructor. If MatrixLookup is owner of underlying matrix, the
    213     /// matrix is destroyed.
     218    /// Destructor. If MatrixLookup is owner (and the only owner) of
     219    /// underlying matrix, the matrices are destroyed.
    214220    ///
    215221    virtual ~MatrixLookupWeighted();
     
    220226    double data(size_t row, size_t column) const;
    221227
    222     ///
    223     /// @todo doc
    224     ///
     228    /**
     229       the new MatrixLookup will consist of the rolumn vectors
     230       defined by @a index. This means that the returned
     231       MatrixLookupWeighted
     232       will fullfill:
     233       returned(i,j) = original(index[i],j)
     234
     235       @note If underlying matrix goes out of scope or is deleted, the
     236       returned pointer becomes invalid and the result of further use is
     237       undefined.
     238   
     239    */
    225240    const MatrixLookupWeighted* selected(const std::vector<size_t>& i) const;
    226241
     
    229244    /// columns defined by @a index in the original MatrixLookupWeighted. The
    230245    /// created MatrixLookupWeighted will fullfill:
    231     /// \f$ novel_ml(i,j)=original(i,index[j]) \f$.
     246    /// novel_ml(i,j)=original(i,index[j]).
    232247    ///
    233248    /// @return pointer to sub-Lookup of the MatrixLookupWeighted
     
    244259    /// columns defined by @a index in the original MatrixLookupWeighted. The
    245260    /// created MatrixLookupWeighted will fullfill:
    246     /// \f$ novel_ml(i,j)=original(i,index[j]) \f$.
     261    /// novel_ml(i,j)=original(i,index[j])
    247262    ///
    248263    /// @return pointer to sub-Lookup of the MatrixLookupWeighted
     
    268283    /// Access operator
    269284    ///
    270     /// @return weight * data for element \f$ i j\f$
     285    /// @return weight * data for element (@a row, @a column)
    271286    ///
    272287    double operator()(const size_t row, const size_t column) const;
     
    275290    /// @brief assigment operator
    276291    ///
    277     /// Does only change MatrixLookupWeighted not the underlying matrix
    278     /// object. However if the MatrixLookupWeighted is owner of its underlying
    279     /// matrix, that matrix will be deleted here.
     292    /// Does only change MatrixLookupWeighted not the underlying
     293    /// matrix object. However if the MatrixLookupWeighted is owner
     294    /// (and the only owner) of its underlying data, those data will
     295    /// be deleted here.
    280296    ///
    281297    const MatrixLookupWeighted& operator=(const MatrixLookupWeighted&);
     
    290306  /// The output operator MatrixLookupWeighted
    291307  ///
     308  /// For eacd data element data(i,j) is printed except those being
     309  /// associated with a zero weight for which nothing is printed.
     310  ///
    292311  std::ostream& operator<< (std::ostream& s, const MatrixLookupWeighted&);
    293312
Note: See TracChangeset for help on using the changeset viewer.