- Timestamp:
- Mar 1, 2007, 10:52:48 PM (16 years ago)
- Location:
- trunk/yat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/MatrixLookupWeighted.cc
r720 r774 53 53 { 54 54 utility::matrix weights; 55 data_->nan(weights);55 utility::nan(*data_,weights); 56 56 weights_= new utility::matrix(weights); 57 57 ref_count_weights_=new u_int(1); … … 214 214 column_index_.push_back(i); 215 215 utility::matrix weights; 216 data_->nan(weights);216 utility::nan(*data_,weights); 217 217 weights_= new utility::matrix(weights); 218 218 ref_count_weights_=new u_int(1); -
trunk/yat/utility/matrix.cc
r773 r774 213 213 214 214 215 bool matrix::isnull(void) const216 {217 return gsl_matrix_isnull(m_);218 }219 220 221 215 bool matrix::isview(void) const 222 216 { 223 217 return view_; 224 }225 226 227 double matrix::max(void) const228 {229 return gsl_matrix_max(m_);230 }231 232 233 double matrix::min(void) const234 {235 return gsl_matrix_min(m_);236 }237 238 239 void matrix::minmax_index(std::pair<size_t,size_t>& min,240 std::pair<size_t,size_t>& max) const241 {242 gsl_matrix_minmax_index(m_, &min.first, &min.second, &max.first,243 &max.second);244 }245 246 247 bool matrix::nan(matrix &m) const248 {249 m=matrix(rows(),columns(),1.0);250 bool nan=false;251 for (size_t i=0; i<rows(); i++)252 for (size_t j=0; j<columns(); j++)253 if (std::isnan(operator()(i,j))) {254 m(i,j)=0;255 nan=true;256 }257 return nan;258 218 } 259 219 … … 302 262 if (status) 303 263 throw utility::GSL_error(std::string("matrix::set_row",status)); 304 }305 306 307 void matrix::swap(matrix& other)308 {309 int status=gsl_matrix_swap(m_, other.m_);310 if (status)311 throw utility::GSL_error(std::string("matrix::swap",status));312 264 } 313 265 … … 455 407 456 408 409 bool isnull(const matrix& m) 410 { 411 return gsl_matrix_isnull(m.gsl_matrix_p()); 412 } 413 414 415 double max(const matrix& m) 416 { 417 return gsl_matrix_max(m.gsl_matrix_p()); 418 } 419 420 421 double min(const matrix& m) 422 { 423 return gsl_matrix_min(m.gsl_matrix_p()); 424 } 425 426 427 void minmax_index(const matrix& m, 428 std::pair<size_t,size_t>& min, std::pair<size_t,size_t>& max) 429 { 430 gsl_matrix_minmax_index(m.gsl_matrix_p(), &min.first, &min.second, 431 &max.first, &max.second); 432 } 433 434 435 bool nan(const matrix& templat, matrix& flag) 436 { 437 size_t rows=templat.rows(); 438 size_t columns=templat.columns(); 439 if (rows!=flag.rows() && columns!=flag.columns()) 440 flag=matrix(rows,columns,1.0); 441 else 442 flag.set_all(1.0); 443 bool nan=false; 444 for (size_t i=0; i<rows; i++) 445 for (size_t j=0; j<columns; j++) 446 if (std::isnan(templat(i,j))) { 447 flag(i,j)=0; 448 nan=true; 449 } 450 return nan; 451 } 452 453 454 void swap(matrix& a, matrix& b) 455 { 456 int status=gsl_matrix_swap(a.gsl_matrix_p(), b.gsl_matrix_p()); 457 if (status) 458 throw utility::GSL_error(std::string("matrix::swap",status)); 459 } 460 461 457 462 std::ostream& operator<<(std::ostream& s, const matrix& m) 458 463 { -
trunk/yat/utility/matrix.h
r773 r774 177 177 178 178 /// 179 /// @return True if all elements in the matrix is zero, false180 /// othwerwise;181 ///182 bool isnull(void) const;183 184 ///185 179 /// @brief Check if the matrix object is a view (sub-matrix) to 186 180 /// another matrix. … … 189 183 /// 190 184 bool isview(void) const; 191 192 ///193 /// @return The maximum value of the matrix.194 ///195 double max(void) const;196 197 ///198 /// @return The minimum value of the matrix.199 ///200 double min(void) const;201 202 ///203 /// @return The indecies to the element with the minimum and204 /// maximum values of the matrix, respectively. The lowest index205 /// has precedence (searching in row-major order).206 ///207 void minmax_index(std::pair<size_t,size_t>& min,208 std::pair<size_t,size_t>& max) const;209 210 ///211 /// The argument is changed into a matrix containing 1's and 0's212 /// only. 1 means element in matrix is valid and a zero means213 /// element is a NaN.214 ///215 /// @return true if matrix contains at least one NaN.216 ///217 bool nan(matrix&) const;218 185 219 186 /** … … 266 233 */ 267 234 void set_row(const size_t row, const vector& vec); 268 269 /**270 \brief Exchange the elements of the this and \a other by copying.271 272 The two matrices must have the same size.273 274 \throw GSL_error if either index is out of bounds.275 */276 void swap(matrix& other);277 235 278 236 /** … … 453 411 }; 454 412 455 /// 456 /// The output operator for the matrix class. 457 /// 413 /** 414 \brief Check if all elements of the matrix are zero. 415 416 \return True if all elements in the matrix is zero, false othwerwise 417 */ 418 bool isnull(const matrix&); 419 420 /** 421 \brief Get the maximum value in the matrix. 422 423 \return The maximum value of the matrix. 424 */ 425 double max(const matrix&); 426 427 /** 428 \brief Get the minimum value in the matrix. 429 430 \return The minimum value of the matrix. 431 */ 432 double min(const matrix&); 433 434 /** 435 \brief Locate the maximum and minumum element in the matrix. 436 437 \return The indecies to the element with the minimum and maximum 438 values of the matrix, respectively. 439 440 \note The lowest index has precedence (searching in row-major 441 order). 442 */ 443 void minmax_index(const matrix&, 444 std::pair<size_t,size_t>& min, 445 std::pair<size_t,size_t>& max); 446 447 /** 448 \brief Create a matrix \a flag indicating NaN's in another matrix 449 \a templat. 450 451 The \a flag matrix is changed to contain 1's and 0's only. A 1 452 means that the corresponding element in the \a templat matrix is 453 valid and a zero means that the corresponding element is a NaN. 454 455 \note Space for matrix \a flag is reallocated to fit the size of 456 matrix \a templat if sizes mismatch. 457 458 \return True if the \a templat matrix contains at least one NaN. 459 */ 460 bool nan(const matrix& templat, matrix& flag); 461 462 /** 463 \brief Exchange all elements between the matrices by copying. 464 465 The two matrices must have the same size. 466 467 \throw GSL_error if either index is out of bounds. 468 */ 469 void swap(matrix&, matrix&); 470 471 /** 472 \brief The output operator for the matrix class. 473 */ 458 474 std::ostream& operator<< (std::ostream& s, const matrix&); 459 475
Note: See TracChangeset
for help on using the changeset viewer.