Changeset 826
- Timestamp:
- Mar 19, 2007, 6:45:30 PM (17 years ago)
- Location:
- trunk/yat/classifier
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/DataLookup2D.h
r720 r826 36 36 /// 37 37 /// This is the abstract base class defining a common interface for 38 /// MatrixLookup and KernelLookup. The general idea o the Lookup38 /// MatrixLookup and KernelLookup. The general idea of the Lookup 39 39 /// classes is to: rather than copying the sub-matrix or sub-kernel, 40 40 /// to hold a pointer to the underlying matrix/kernel and a vector … … 44 44 /// This allow fast construction of sub-matrices/sub-kernels and at 45 45 /// 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. 46 53 /// 47 54 class DataLookup2D -
trunk/yat/classifier/KernelLookup.cc
r757 r826 135 135 136 136 137 const Kernel* KernelLookup::kernel(void) const138 {139 return kernel_;140 }141 142 143 137 const KernelLookup* 144 138 KernelLookup::selected(const std::vector<size_t>& inputs) const -
trunk/yat/classifier/KernelLookup.h
r720 r826 54 54 /// 55 55 /// 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. 60 61 /// 61 62 class KernelLookup : public DataLookup2D … … 69 70 /// Constructs a KernelLookup corresponding to the Kernel @a 70 71 /// 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. 74 73 /// 75 74 /// @note If underlying Kernel goes out of scope or is deleted, the … … 106 105 /// 107 106 /// 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. 110 111 /// 111 112 KernelLookup(const KernelLookup& kl); … … 123 124 /// undefined in case underlying Kernel is destroyed. 124 125 /// 126 /// If \a kl is owner of underlying data, constructed 127 /// KernelLookup will also be set as owner of underlying data. 128 /// 125 129 /// @note For training usage row index shall always be equal to 126 130 /// column index. … … 134 138 /// equally many rows as @a kernel. 135 139 /// 140 /// If \a kl is owner of underlying data, constructed 141 /// KernelLookup will also be set as owner of underlying data. 142 /// 136 143 /// @note If underlying kernel goes out of scope or is deleted, the 137 144 /// KernelLookup becomes invalid and the result of further use is … … 144 151 /// @brief Destructor 145 152 /// 146 /// Deletes underlying Kernel if KernelLookup owns it. 153 /// Deletes underlying Kernel if KernelLookup owns it and there is 154 /// no other owner. 147 155 /// 148 156 virtual ~KernelLookup(void); 149 157 150 158 /// 151 /// Each column in returned MatrixLookup corresponds to the column159 /// Each column in returned DataLookup corresponds to the column 152 160 /// in KernelLookup. 161 /// 162 /// \return data that KernelLookup is built upon. 153 163 /// 154 164 /// @Note Returns a dynamically allocated MatrixLookup, which has … … 156 166 /// 157 167 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; 158 176 159 177 /** … … 166 184 vector corresponding to \f$ i \f$ th row. 167 185 */ 168 double element(const DataLookup1D& vec, size_t i) const;169 170 /**171 Function to calculate a new Kernel element using the underlying172 KernelFunction. The value is calulated between @a vec and the173 data vector of the \f$ i \f$ th sample, in other words, the174 sample corresponding to the \f$ i \f$ th row or \f$ i \f$ th175 column. In case KernelLookup is a sub-Kernel and not symmetric,176 the kernel value is calculated between @a vec and the data177 vector corresponding to \f$ i \f$ th row.178 */179 186 double element(const DataLookupWeighted1D& vec, size_t i) const; 180 181 const Kernel* kernel(void) const;182 187 183 188 /** … … 193 198 194 199 /** 195 This function is useful when predicting on a independent data200 This function is useful when predicting on an independent data 196 201 set using a kernel-based classifier. In returned KernelLookup 197 202 column \f$ i \f$ corresponds to column \f$ i \f$ in @a … … 208 213 209 214 /** 210 This function is useful when predicting on a independent data215 This function is useful when predicting on an independent data 211 216 set using a kernel-based classifier. In returned KernelLookup 212 217 column \f$ i \f$ corresponds to column \f$ i \f$ in @a -
trunk/yat/classifier/MatrixLookup.cc
r781 r826 25 25 #include "yat/utility/matrix.h" 26 26 27 #ifndef NDEBUG28 27 #include <algorithm> 29 #endif30 31 28 #include <cassert> 32 29 #include <fstream> … … 39 36 : DataLookup2D(own), data_(&data) 40 37 { 38 row_index_.reserve(data_->rows()); 41 39 for(size_t i=0;i<(*data_).rows();i++) 42 40 row_index_.push_back(i); 41 column_index_.reserve(data_->columns()); 43 42 for(size_t i=0;i<(*data_).columns();i++) 44 43 column_index_.push_back(i); -
trunk/yat/classifier/MatrixLookup.h
r767 r826 49 49 /// to a row and a column in the Kernel, respectively. This design 50 50 /// 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. 52 54 /// 53 55 /// A MatrixLookup can be created directly from a matrix or from an … … 57 59 /// 58 60 /// 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. 60 66 /// 61 67 class MatrixLookup : public DataLookup2D … … 68 74 /// Constructor creating a lookup into the entire @a matrix. 69 75 /// @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. 70 81 /// 71 82 /// @note If @a matrix goes out of scope or is deleted, the … … 115 126 /// @brief Copy constructor. 116 127 /// 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 125 141 /// MatrixLookup @a ml. The MatrixLookup is created to look 126 142 /// directly into the underlying matrix to avoid multiple lookups. 127 143 /// 144 /// If \a ml is owner of underlying data, constructed 145 /// MatrixLookup will also be set as owner of underlying data. 146 /// 128 147 /// The @a row and @a column define what sub-matrix to look into, 129 148 /// in other words, the created MatrixLookup will fullfill the 130 /// following: \f$ MatrixLookup(i,j)=ml(row[i],column[j]) \f$. This149 /// following: MatrixLookup(i,j)=ml(row[i],column[j]). This 131 150 /// also means that number of rows in created MatrixLookup is 132 151 /// equal to size of vector @a row, and number of columns is equal 133 152 /// to size of vector @a column. 134 153 /// 154 /// If \a ml is owner of underlying data, constructed 155 /// MatrixLookup will also be set as owner of underlying data. 156 /// 135 157 /// @note If underlying matrix goes out of scope or is deleted, the 136 158 /// MatrixLookup becomes invalid and the result of further use is … … 148 170 /// of the row vectors defined by @a index. This means that the 149 171 /// created MatrixLookup will fullfill: 150 /// \f$ MatrixLookup(i,j)=ml(i,index[j])\f$172 /// MatrixLookup(i,j)=ml(i,index[j]) 151 173 /// 152 174 /// If @a row_vectors is false the new MatrixLookup will consist … … 154 176 /// created MatrixLookup will fullfill: 155 177 /// \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. 156 181 /// 157 182 /// @note If underlying matrix goes out of scope or is deleted, the … … 181 206 182 207 /// 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. 184 212 /// 185 213 virtual ~MatrixLookup(); … … 244 272 /// 245 273 /// 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 247 276 /// matrix, that matrix will be deleted here. 248 277 /// -
trunk/yat/classifier/MatrixLookupWeighted.cc
r781 r826 25 25 #include "yat/utility/matrix.h" 26 26 27 #ifndef NDEBUG28 27 #include <algorithm> 29 #endif30 31 28 #include <cassert> 32 29 #include <fstream> … … 315 312 for(size_t i=0, j=0; i<m.rows(); i++) 316 313 for (j=0; j<m.columns(); j++) { 317 s << m(i,j); 314 if (m.weight(i,j)) 315 s << m.data(i,j); 318 316 if (j<m.columns()-1) 319 317 s << s.fill(); -
trunk/yat/classifier/MatrixLookupWeighted.h
r767 r826 44 44 /// A MatrixLookupWeighted is very similar to a MatrixLookup, but 45 45 /// 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. 47 47 /// 48 48 /// A MatrixLookupWeighted can be created directly from a matrix or … … 52 52 /// 53 53 /// 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. 59 60 /// 60 61 class MatrixLookupWeighted : public DataLookup2D … … 65 66 66 67 /// 67 /// Constructor creating a lookup into the entire @a matrix. 68 /// Constructor creating a lookup into the entire \a matrix and \a 69 /// weights. 68 70 /// 69 71 /// @note If @a matrix or @a weights goes out of scope or is … … 79 81 /// Constructor creating a lookup into the entire @a matrix. A 80 82 /// 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 82 88 /// is deleted, the MatrixLookupWeighted becomes invalid and the 83 89 /// result of further use is undefined. … … 90 96 /// The @a row and @a column define what sub-matrix to look into, 91 97 /// in other words, the created MatrixLookupWeighted will fullfill 92 /// the following: \f$98 /// the following: 93 99 /// MatrixLookupWeighted(i,j)=matrix(row[i],column[j]) 94 /// weights(row[i],column[j]) \f$. This also means that number of100 /// weights(row[i],column[j]). This also means that number of 95 101 /// rows in created MatrixLookupWeighted is equal to size of 96 102 /// vector @a row, and number of columns is equal to size of … … 111 117 /// If @a row_vectors is true the new MatrixLookupWeighted will be 112 118 /// 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: 114 120 /// MatrixLookupWeighted(i,j)=matrix(i,index[j])*weights(i,index[j]) 115 /// \f$121 /// 116 122 /// 117 123 /// If @a row_vectors is false the new MatrixLookupWeighted will be consist 118 124 /// of the rolumn vectors defined by @a index. This means that the 119 125 /// created MatrixLookupWeighted will fullfill: 120 /// \f$ MatrixLookupWeighted(i,j)=matrix(index[i],j) \f$126 /// 121 127 /// 122 128 /// @note If @a matrix or @a weights goes out of scope or is … … 130 136 131 137 /// 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. 133 142 /// 134 143 /// @note If underlying matrix goes out of scope or is deleted, the … … 136 145 /// undefined. 137 146 /// 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); 148 148 149 149 /// … … 159 159 /// to size of vector @a column. 160 160 /// 161 /// If \a ml is owner of underlying data, constructed 162 /// MatrixLookup will also be set as owner of underlying data. 163 /// 161 164 /// @note If underlying matrix goes out of scope or is deleted, the 162 165 /// MatrixLookupWeighted becomes invalid and the result of further use is … … 182 185 /// \f$ MatrixLookupWeighted(i,j) = ml(index[i],j) \f$ 183 186 /// 187 /// If \a ml is owner of underlying data, constructed 188 /// MatrixLookup will also be set as owner of underlying data. 189 /// 184 190 /// @note If underlying matrix goes out of scope or is deleted, the 185 191 /// MatrixLookupWeighted becomes invalid and the result of further use is … … 210 216 211 217 /// 212 /// Destructor. If MatrixLookup is owner of underlying matrix, the213 /// matrix isdestroyed.218 /// Destructor. If MatrixLookup is owner (and the only owner) of 219 /// underlying matrix, the matrices are destroyed. 214 220 /// 215 221 virtual ~MatrixLookupWeighted(); … … 220 226 double data(size_t row, size_t column) const; 221 227 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 */ 225 240 const MatrixLookupWeighted* selected(const std::vector<size_t>& i) const; 226 241 … … 229 244 /// columns defined by @a index in the original MatrixLookupWeighted. The 230 245 /// created MatrixLookupWeighted will fullfill: 231 /// \f$ novel_ml(i,j)=original(i,index[j]) \f$.246 /// novel_ml(i,j)=original(i,index[j]). 232 247 /// 233 248 /// @return pointer to sub-Lookup of the MatrixLookupWeighted … … 244 259 /// columns defined by @a index in the original MatrixLookupWeighted. The 245 260 /// created MatrixLookupWeighted will fullfill: 246 /// \f$ novel_ml(i,j)=original(i,index[j]) \f$.261 /// novel_ml(i,j)=original(i,index[j]) 247 262 /// 248 263 /// @return pointer to sub-Lookup of the MatrixLookupWeighted … … 268 283 /// Access operator 269 284 /// 270 /// @return weight * data for element \f$ i j\f$285 /// @return weight * data for element (@a row, @a column) 271 286 /// 272 287 double operator()(const size_t row, const size_t column) const; … … 275 290 /// @brief assigment operator 276 291 /// 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. 280 296 /// 281 297 const MatrixLookupWeighted& operator=(const MatrixLookupWeighted&); … … 290 306 /// The output operator MatrixLookupWeighted 291 307 /// 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 /// 292 311 std::ostream& operator<< (std::ostream& s, const MatrixLookupWeighted&); 293 312
Note: See TracChangeset
for help on using the changeset viewer.