Changeset 1121 for trunk/yat/utility
- Timestamp:
- Feb 22, 2008, 4:29:56 PM (16 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 20 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/Alignment.cc
r1120 r1121 25 25 26 26 #include "Alignment.h" 27 #include " matrix.h"27 #include "Matrix.h" 28 28 #include "stl_utility.h" 29 29 … … 36 36 namespace utility { 37 37 38 double NeedlemanWunsch(const utility:: matrix& s,38 double NeedlemanWunsch(const utility::Matrix& s, 39 39 std::vector<std::pair<size_t, size_t> >& path, 40 40 const double gap) 41 41 { 42 utility:: matrix m(s.rows()+1,s.columns()+1);42 utility::Matrix m(s.rows()+1,s.columns()+1); 43 43 // Init upper and left border of matrix 44 44 for (size_t i=1; i<m.rows(); i++) … … 48 48 // choice(i,j) tells us how we came to s(i,j). 1 is diagonal, 2 49 49 // vertical, and 3 horizontal, 50 utility:: matrix choice(m.rows(),m.columns());50 utility::Matrix choice(m.rows(),m.columns()); 51 51 52 52 // Calculating NeedlemanWunsch matrix … … 90 90 double open_gap) 91 91 { 92 matrix m(first.size(), second.size());92 Matrix m(first.size(), second.size()); 93 93 for (size_t i=0; i<first.size(); ++i) 94 94 for (size_t j=0; j<second.size(); ++j) … … 98 98 99 99 100 double SmithWaterman(const utility:: matrix& s,100 double SmithWaterman(const utility::Matrix& s, 101 101 double gap, double open_gap) 102 102 { … … 104 104 105 105 // Calculating S-W matrix 106 matrix m(s.rows()+1,s.columns()+1);107 matrix array(m);106 Matrix m(s.rows()+1,s.columns()+1); 107 Matrix array(m); 108 108 for (size_t i=1; i<m.rows(); ++i) 109 109 for (size_t j=1; j<m.columns(); ++j){ -
trunk/yat/utility/Alignment.h
r1000 r1121 35 35 namespace utility { 36 36 37 class matrix;37 class Matrix; 38 38 39 39 /// … … 57 57 /// @return the global maximum alignment score. 58 58 /// 59 double NeedlemanWunsch(const utility:: matrix& s,59 double NeedlemanWunsch(const utility::Matrix& s, 60 60 std::vector<std::pair<size_t, size_t> >& path, 61 61 const double gap); … … 78 78 gap of length \f$l\f$ the total cost is \f$open_gap + l*gap\f$. 79 79 */ 80 double SmithWaterman(const utility:: matrix& s,80 double SmithWaterman(const utility::Matrix& s, 81 81 double gap, double open_gap); 82 82 -
trunk/yat/utility/Makefile.am
r1120 r1121 27 27 libutility_la_SOURCES = \ 28 28 Alignment.cc ColumnStream.cc CommandLine.cc FileUtil.cc Index.cc kNNI.cc \ 29 matrix.cc NNI.cc Option.cc OptionFile.cc OptionInFile.cc OptionOutFile.cc \29 Matrix.cc NNI.cc Option.cc OptionFile.cc OptionInFile.cc OptionOutFile.cc \ 30 30 OptionHelp.cc OptionSwitch.cc \ 31 31 PCA.cc stl_utility.cc SVD.cc TypeInfo.cc utility.cc Vector.cc \ … … 38 38 Container2DIterator.h \ 39 39 Exception.h FileUtil.h Index.h IteratorPolicy.h iterator_traits.h \ 40 kNNI.h matrix.h NNI.h \40 kNNI.h Matrix.h NNI.h \ 41 41 Option.h OptionArg.h OptionFile.h OptionInFile.h OptionOutFile.h \ 42 42 OptionHelp.h OptionSwitch.h \ -
trunk/yat/utility/Matrix.cc
r1120 r1121 25 25 */ 26 26 27 #include " yat/utility/matrix.h"28 #include " yat/utility/Vector.h"27 #include "Matrix.h" 28 #include "Vector.h" 29 29 #include "VectorBase.h" 30 30 #include "VectorConstView.h" … … 44 44 45 45 46 matrix::matrix(void)46 Matrix::Matrix(void) 47 47 : blas_result_(NULL), m_(NULL) 48 48 { … … 50 50 51 51 52 matrix::matrix(const size_t& r, const size_t& c, double init_value)52 Matrix::Matrix(const size_t& r, const size_t& c, double init_value) 53 53 : blas_result_(NULL), m_(gsl_matrix_alloc(r,c)) 54 54 { 55 55 if (!m_) 56 throw utility::GSL_error(" matrix::matrix failed to allocate memory");56 throw utility::GSL_error("Matrix::Matrix failed to allocate memory"); 57 57 all(init_value); 58 58 } 59 59 60 60 61 matrix::matrix(const matrix& o)61 Matrix::Matrix(const Matrix& o) 62 62 : blas_result_(NULL), m_(o.create_gsl_matrix_copy()) 63 63 { … … 66 66 67 67 // Constructor that gets data from istream 68 matrix::matrix(std::istream& is, char sep)68 Matrix::Matrix(std::istream& is, char sep) 69 69 throw (utility::IO_error,std::exception) 70 70 : blas_result_(NULL) … … 113 113 else if (v.size()!=nof_columns) { 114 114 std::ostringstream s; 115 s << " matrix::matrix(std::istream&, char) data file error: "115 s << "Matrix::Matrix(std::istream&, char) data file error: " 116 116 << "line " << nof_rows << " has " << v.size() 117 117 << " columns; expected " << nof_columns << " columns."; … … 126 126 m_ = gsl_matrix_alloc ( nof_rows, nof_columns ); 127 127 if (!m_) 128 throw utility::GSL_error(" matrix::matrix failed to allocate memory");128 throw utility::GSL_error("Matrix::Matrix failed to allocate memory"); 129 129 130 130 // if gsl error handler disabled, out of bounds index will not … … 136 136 137 137 138 matrix::~matrix(void)138 Matrix::~Matrix(void) 139 139 { 140 140 delete_allocated_memory(); … … 145 145 146 146 147 void matrix::all(const double value)147 void Matrix::all(const double value) 148 148 { 149 149 assert(m_); … … 152 152 153 153 154 matrix::iterator matrix::begin(void)154 Matrix::iterator Matrix::begin(void) 155 155 { 156 156 return iterator(&(*this)(0,0), 1); … … 158 158 159 159 160 matrix::const_iterator matrix::begin(void) const160 Matrix::const_iterator Matrix::begin(void) const 161 161 { 162 162 return const_iterator(&(*this)(0,0), 1); … … 164 164 165 165 166 matrix::column_iterator matrix::begin_column(size_t i)166 Matrix::column_iterator Matrix::begin_column(size_t i) 167 167 { 168 168 return iterator(&(*this)(0,i), this->columns()); … … 170 170 171 171 172 matrix::const_column_iterator matrix::begin_column(size_t i) const172 Matrix::const_column_iterator Matrix::begin_column(size_t i) const 173 173 { 174 174 return const_iterator(&(*this)(0,i), this->columns()); … … 176 176 177 177 178 matrix::row_iterator matrix::begin_row(size_t i)178 Matrix::row_iterator Matrix::begin_row(size_t i) 179 179 { 180 180 return iterator(&(*this)(i,0), 1); … … 182 182 183 183 184 matrix::const_row_iterator matrix::begin_row(size_t i) const184 Matrix::const_row_iterator Matrix::begin_row(size_t i) const 185 185 { 186 186 return const_iterator(&(*this)(i,0), 1); … … 188 188 189 189 190 VectorView matrix::column_view(size_t col)190 VectorView Matrix::column_view(size_t col) 191 191 { 192 192 VectorView res(*this, col, false); … … 195 195 196 196 197 const VectorConstView matrix::column_const_view(size_t col) const197 const VectorConstView Matrix::column_const_view(size_t col) const 198 198 { 199 199 return VectorConstView(*this, col, false); … … 201 201 202 202 203 size_t matrix::columns(void) const203 size_t Matrix::columns(void) const 204 204 { 205 205 return (m_ ? m_->size2 : 0); … … 207 207 208 208 209 gsl_matrix* matrix::create_gsl_matrix_copy(void) const209 gsl_matrix* Matrix::create_gsl_matrix_copy(void) const 210 210 { 211 211 gsl_matrix* m = gsl_matrix_alloc(rows(),columns()); 212 212 if (!m) 213 throw utility::GSL_error(" matrix::create_gsl_matrix_copy failed to allocate memory");213 throw utility::GSL_error("Matrix::create_gsl_matrix_copy failed to allocate memory"); 214 214 if (gsl_matrix_memcpy(m,m_)) 215 throw utility::GSL_error(" matrix::create_gsl_matrix_copy dimension mis-match");215 throw utility::GSL_error("Matrix::create_gsl_matrix_copy dimension mis-match"); 216 216 return m; 217 217 } 218 218 219 219 220 void matrix::delete_allocated_memory(void)220 void Matrix::delete_allocated_memory(void) 221 221 { 222 222 if (m_) … … 226 226 227 227 228 void matrix::div(const matrix& other)228 void Matrix::div(const Matrix& other) 229 229 { 230 230 assert(m_); … … 235 235 236 236 237 matrix::iterator matrix::end(void)237 Matrix::iterator Matrix::end(void) 238 238 { 239 239 return iterator(&(*this)(0,0)+rows()*columns(), 1); … … 241 241 242 242 243 matrix::const_iterator matrix::end(void) const243 Matrix::const_iterator Matrix::end(void) const 244 244 { 245 245 return const_iterator(&(*this)(0,0)+rows()*columns(), 1); … … 247 247 248 248 249 matrix::column_iterator matrix::end_column(size_t i)249 Matrix::column_iterator Matrix::end_column(size_t i) 250 250 { 251 251 return column_iterator(&(*this)(0,i)+rows()*columns(), this->columns()); … … 253 253 254 254 255 matrix::const_column_iterator matrix::end_column(size_t i) const255 Matrix::const_column_iterator Matrix::end_column(size_t i) const 256 256 { 257 257 return const_column_iterator(&(*this)(0,i)+rows()*columns(),this->columns()); … … 259 259 260 260 261 matrix::row_iterator matrix::end_row(size_t i)261 Matrix::row_iterator Matrix::end_row(size_t i) 262 262 { 263 263 return row_iterator(&(*this)(i,0)+columns(), 1); … … 265 265 266 266 267 matrix::const_row_iterator matrix::end_row(size_t i) const267 Matrix::const_row_iterator Matrix::end_row(size_t i) const 268 268 { 269 269 return const_row_iterator(&(*this)(i,0)+columns(), 1); … … 271 271 272 272 273 bool matrix::equal(const matrix& other, const double d) const273 bool Matrix::equal(const Matrix& other, const double d) const 274 274 { 275 275 if (this==&other) … … 287 287 288 288 289 const gsl_matrix* matrix::gsl_matrix_p(void) const289 const gsl_matrix* Matrix::gsl_matrix_p(void) const 290 290 { 291 291 return m_; … … 293 293 294 294 295 gsl_matrix* matrix::gsl_matrix_p(void)295 gsl_matrix* Matrix::gsl_matrix_p(void) 296 296 { 297 297 return m_; … … 299 299 300 300 301 void matrix::mul(const matrix& other)301 void Matrix::mul(const Matrix& other) 302 302 { 303 303 assert(m_); 304 304 int status=gsl_matrix_mul_elements(m_, other.gsl_matrix_p()); 305 305 if (status) 306 throw utility::GSL_error(std::string(" matrix::mul_elements",status));307 } 308 309 310 void matrix::resize(size_t r, size_t c, double init_value)306 throw utility::GSL_error(std::string("Matrix::mul_elements",status)); 307 } 308 309 310 void Matrix::resize(size_t r, size_t c, double init_value) 311 311 { 312 312 delete_allocated_memory(); … … 314 314 m_ = gsl_matrix_alloc(r,c); 315 315 if (!m_) 316 throw utility::GSL_error(" matrix::matrix failed to allocate memory");316 throw utility::GSL_error("Matrix::Matrix failed to allocate memory"); 317 317 all(init_value); 318 318 … … 326 326 327 327 328 size_t matrix::rows(void) const328 size_t Matrix::rows(void) const 329 329 { 330 330 return (m_ ? m_->size1 : 0); … … 332 332 333 333 334 const VectorConstView matrix::row_const_view(size_t col) const334 const VectorConstView Matrix::row_const_view(size_t col) const 335 335 { 336 336 return VectorConstView(*this, col, true); … … 338 338 339 339 340 VectorView matrix::row_view(size_t row)340 VectorView Matrix::row_view(size_t row) 341 341 { 342 342 VectorView res(*this, row, true); … … 345 345 346 346 347 void matrix::swap_columns(const size_t i, const size_t j)347 void Matrix::swap_columns(const size_t i, const size_t j) 348 348 { 349 349 assert(m_); 350 350 int status=gsl_matrix_swap_columns(m_, i, j); 351 351 if (status) 352 throw utility::GSL_error(std::string(" matrix::swap_columns",status));353 } 354 355 356 void matrix::swap_rowcol(const size_t i, const size_t j)352 throw utility::GSL_error(std::string("Matrix::swap_columns",status)); 353 } 354 355 356 void Matrix::swap_rowcol(const size_t i, const size_t j) 357 357 { 358 358 assert(m_); 359 359 int status=gsl_matrix_swap_rowcol(m_, i, j); 360 360 if (status) 361 throw utility::GSL_error(std::string(" matrix::swap_rowcol",status));362 } 363 364 365 void matrix::swap_rows(const size_t i, const size_t j)361 throw utility::GSL_error(std::string("Matrix::swap_rowcol",status)); 362 } 363 364 365 void Matrix::swap_rows(const size_t i, const size_t j) 366 366 { 367 367 assert(m_); 368 368 int status=gsl_matrix_swap_rows(m_, i, j); 369 369 if (status) 370 throw utility::GSL_error(std::string(" matrix::swap_rows",status));371 } 372 373 374 void matrix::transpose(void)370 throw utility::GSL_error(std::string("Matrix::swap_rows",status)); 371 } 372 373 374 void Matrix::transpose(void) 375 375 { 376 376 assert(m_); … … 380 380 gsl_matrix* transposed = gsl_matrix_alloc(columns(),rows()); 381 381 if (!transposed) 382 throw utility::GSL_error(" matrix::transpose failed to allocate memory");382 throw utility::GSL_error("Matrix::transpose failed to allocate memory"); 383 383 // next line never fails if allocation above succeeded. 384 384 gsl_matrix_transpose_memcpy(transposed,m_); … … 393 393 394 394 395 double& matrix::operator()(size_t row, size_t column)395 double& Matrix::operator()(size_t row, size_t column) 396 396 { 397 397 assert(m_); … … 400 400 double* d=gsl_matrix_ptr(m_, row, column); 401 401 if (!d) 402 throw utility::GSL_error(" matrix::operator()",GSL_EINVAL);402 throw utility::GSL_error("Matrix::operator()",GSL_EINVAL); 403 403 return *d; 404 404 } 405 405 406 406 407 const double& matrix::operator()(size_t row, size_t column) const407 const double& Matrix::operator()(size_t row, size_t column) const 408 408 { 409 409 assert(row<rows()); … … 411 411 const double* d=gsl_matrix_const_ptr(m_, row, column); 412 412 if (!d) 413 throw utility::GSL_error(" matrix::operator()",GSL_EINVAL);413 throw utility::GSL_error("Matrix::operator()",GSL_EINVAL); 414 414 return *d; 415 415 } 416 416 417 417 418 bool matrix::operator==(const matrix& other) const418 bool Matrix::operator==(const Matrix& other) const 419 419 { 420 420 return equal(other); … … 422 422 423 423 424 bool matrix::operator!=(const matrix& other) const424 bool Matrix::operator!=(const Matrix& other) const 425 425 { 426 426 return !equal(other); … … 428 428 429 429 430 const matrix& matrix::operator=( const matrix& other )430 const Matrix& Matrix::operator=( const Matrix& other ) 431 431 { 432 432 assert(other.m_); … … 435 435 resize(other.m_->size1,other.m_->size2); 436 436 if (gsl_matrix_memcpy(m_, other.gsl_matrix_p())) 437 throw utility::GSL_error(" matrix::create_gsl_matrix_copy dimension mis-match");437 throw utility::GSL_error("Matrix::create_gsl_matrix_copy dimension mis-match"); 438 438 } 439 439 return *this; … … 441 441 442 442 443 const matrix& matrix::operator+=(const matrix& other)443 const Matrix& Matrix::operator+=(const Matrix& other) 444 444 { 445 445 assert(m_); 446 446 int status=gsl_matrix_add(m_, other.m_); 447 447 if (status) 448 throw utility::GSL_error(std::string(" matrix::operator+=", status));449 return *this; 450 } 451 452 453 const matrix& matrix::operator+=(const double d)448 throw utility::GSL_error(std::string("Matrix::operator+=", status)); 449 return *this; 450 } 451 452 453 const Matrix& Matrix::operator+=(const double d) 454 454 { 455 455 assert(m_); … … 459 459 460 460 461 const matrix& matrix::operator-=(const matrix& other)461 const Matrix& Matrix::operator-=(const Matrix& other) 462 462 { 463 463 assert(m_); 464 464 int status=gsl_matrix_sub(m_, other.m_); 465 465 if (status) 466 throw utility::GSL_error(std::string(" matrix::operator-=", status));467 return *this; 468 } 469 470 471 const matrix& matrix::operator-=(const double d)466 throw utility::GSL_error(std::string("Matrix::operator-=", status)); 467 return *this; 468 } 469 470 471 const Matrix& Matrix::operator-=(const double d) 472 472 { 473 473 assert(m_); … … 477 477 478 478 479 const matrix& matrix::operator*=(const matrix& other)479 const Matrix& Matrix::operator*=(const Matrix& other) 480 480 { 481 481 assert(m_); … … 488 488 blas_result_ = gsl_matrix_alloc(rows(),other.columns()); 489 489 if (!blas_result_) 490 throw utility::GSL_error(" matrix::operator*= failed to allocate memory");490 throw utility::GSL_error("Matrix::operator*= failed to allocate memory"); 491 491 } 492 492 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, m_, other.m_, 0.0, blas_result_); … … 498 498 499 499 500 const matrix& matrix::operator*=(const double d)500 const Matrix& Matrix::operator*=(const double d) 501 501 { 502 502 assert(m_); … … 506 506 507 507 508 bool isnull(const matrix& other)508 bool isnull(const Matrix& other) 509 509 { 510 510 return gsl_matrix_isnull(other.gsl_matrix_p()); … … 512 512 513 513 514 double max(const matrix& other)514 double max(const Matrix& other) 515 515 { 516 516 return gsl_matrix_max(other.gsl_matrix_p()); … … 518 518 519 519 520 double min(const matrix& other)520 double min(const Matrix& other) 521 521 { 522 522 return gsl_matrix_min(other.gsl_matrix_p()); … … 524 524 525 525 526 void minmax_index(const matrix& other,526 void minmax_index(const Matrix& other, 527 527 std::pair<size_t,size_t>& min, std::pair<size_t,size_t>& max) 528 528 { … … 532 532 533 533 534 bool nan(const matrix& templat, matrix& flag)534 bool nan(const Matrix& templat, Matrix& flag) 535 535 { 536 536 size_t rows=templat.rows(); … … 551 551 552 552 553 void swap( matrix& a, matrix& b)553 void swap(Matrix& a, Matrix& b) 554 554 { 555 555 assert(a.gsl_matrix_p()); assert(b.gsl_matrix_p()); 556 556 int status=gsl_matrix_swap(a.gsl_matrix_p(), b.gsl_matrix_p()); 557 557 if (status) 558 throw utility::GSL_error(std::string("swap( matrix&,matrix&)",status));559 } 560 561 562 std::ostream& operator<<(std::ostream& s, const matrix& m)558 throw utility::GSL_error(std::string("swap(Matrix&,Matrix&)",status)); 559 } 560 561 562 std::ostream& operator<<(std::ostream& s, const Matrix& m) 563 563 { 564 564 s.setf(std::ios::dec); … … 576 576 577 577 578 Vector operator*(const matrix& m, const VectorBase& v)578 Vector operator*(const Matrix& m, const VectorBase& v) 579 579 { 580 580 utility::Vector res(m.rows()); … … 585 585 586 586 587 Vector operator*(const VectorBase& v, const matrix& m)587 Vector operator*(const VectorBase& v, const Matrix& m) 588 588 { 589 589 utility::Vector res(m.columns()); -
trunk/yat/utility/Matrix.h
r1120 r1121 62 62 /// superdiagonals. 63 63 /// 64 class matrix64 class Matrix 65 65 { 66 66 public: … … 95 95 structures. 96 96 */ 97 matrix(void);97 Matrix(void); 98 98 99 99 /** … … 103 103 \throw GSL_error if memory allocation fails. 104 104 */ 105 matrix(const size_t& r, const size_t& c, double init_value=0);105 Matrix(const size_t& r, const size_t& c, double init_value=0); 106 106 107 107 /** … … 111 111 fails. 112 112 */ 113 matrix(const matrix&);113 Matrix(const Matrix&); 114 114 115 115 /** … … 127 127 unexpected input is found in the input stream. 128 128 */ 129 explicit matrix(std::istream &, char sep='\0')129 explicit Matrix(std::istream &, char sep='\0') 130 130 throw(utility::IO_error, std::exception); 131 131 … … 133 133 \brief The destructor. 134 134 */ 135 ~ matrix(void);135 ~Matrix(void); 136 136 137 137 /// … … 206 206 \throw GSL_error if dimensions mis-match. 207 207 */ 208 void div(const matrix& b);208 void div(const Matrix& b); 209 209 210 210 /** … … 247 247 \see operator== and operator!= 248 248 */ 249 bool equal(const matrix&, const double precision=0) const;249 bool equal(const Matrix&, const double precision=0) const; 250 250 251 251 /// … … 260 260 261 261 /** 262 Multiply the elements of matrix \a b with the elements of the263 calling matrix ,\f$ a_{ij} = a_{ij} * b_{ij} \; \forall i,j264 \f$. The result is stored into the calling matrix.262 Multiply the elements of Matrix \a b with the elements of the 263 calling Matrix ,\f$ a_{ij} = a_{ij} * b_{ij} \; \forall i,j 264 \f$. The result is stored into the calling Matrix. 265 265 266 266 \throw GSL_error if dimensions mis-match. 267 267 */ 268 void mul(const matrix& b);269 270 /** 271 \brief Resize matrix268 void mul(const Matrix& b); 269 270 /** 271 \brief Resize Matrix 272 272 273 273 All elements are set to @a init_value. 274 274 275 275 \note underlying GSL matrix is destroyed and views into this 276 matrix becomes invalid.276 Matrix becomes invalid. 277 277 */ 278 278 void resize(size_t, size_t, double init_value=0); … … 303 303 \brief Swap row \a i and column \a j. 304 304 305 The matrix must be square.305 The Matrix must be square. 306 306 307 307 \throw GSL_error if either index is out of bounds, or if matrix … … 359 359 \see equal 360 360 */ 361 bool operator==(const matrix& other) const;361 bool operator==(const Matrix& other) const; 362 362 363 363 /** … … 372 372 \see equal 373 373 */ 374 bool operator!=(const matrix& other) const;374 bool operator!=(const Matrix& other) const; 375 375 376 376 /** 377 377 \brief The assignment operator. 378 378 379 \return A const reference to the resulting matrix.380 */ 381 const matrix& operator=(const matrix& other);379 \return A const reference to the resulting Matrix. 380 */ 381 const Matrix& operator=(const Matrix& other); 382 382 383 383 /** 384 384 \brief Add and assign operator. 385 385 386 Elementwise addition of the elements of matrix \a b to the left387 hand side matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; \forall i,j386 Elementwise addition of the elements of Matrix \a b to the left 387 hand side Matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; \forall i,j 388 388 \f$. 389 389 390 \return A const reference to the resulting matrix.390 \return A const reference to the resulting Matrix. 391 391 392 392 \throw GSL_error if dimensions mis-match. 393 393 */ 394 const matrix& operator+=(const matrix& b);394 const Matrix& operator+=(const Matrix& b); 395 395 396 396 /** 397 397 \brief Add and assign operator 398 398 399 Add the scalar value \a d to the left hand side matrix, \f$399 Add the scalar value \a d to the left hand side Matrix, \f$ 400 400 a_{ij} = a_{ij} + d \; \forall i,j \f$. 401 401 */ 402 const matrix& operator+=(const double d);402 const Matrix& operator+=(const double d); 403 403 404 404 /** 405 405 \brief Subtract and assign operator. 406 406 407 Elementwise subtraction of the elements of matrix \a b to the408 left hand side matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; \forall407 Elementwise subtraction of the elements of Matrix \a b to the 408 left hand side Matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; \forall 409 409 i,j \f$. 410 410 411 \return A const reference to the resulting matrix.411 \return A const reference to the resulting Matrix. 412 412 413 413 \throw GSL_error if dimensions mis-match. 414 414 */ 415 const matrix& operator-=(const matrix&);415 const Matrix& operator-=(const Matrix&); 416 416 417 417 /** 418 418 \brief Subtract and assign operator 419 419 420 Subtract the scalar value \a d to the left hand side matrix,420 Subtract the scalar value \a d to the left hand side Matrix, 421 421 \f$ a_{ij} = a_{ij} + d \; \forall i,j \f$. 422 422 */ 423 const matrix& operator-=(const double d);423 const Matrix& operator-=(const double d); 424 424 425 425 /** 426 426 \brief Multiply and assigment operator. 427 427 428 \return Const reference to the resulting matrix.428 \return Const reference to the resulting Matrix. 429 429 430 430 \throw GSL_error if memory allocation fails. 431 431 */ 432 const matrix& operator*=(const matrix&);432 const Matrix& operator*=(const Matrix&); 433 433 434 434 /** 435 435 \brief Multiply and assignment operator 436 436 437 Multiply the elements of the left hand side matrix with a437 Multiply the elements of the left hand side Matrix with a 438 438 scalar \a d, \f$ a_{ij} = d * a_{ij} \; \forall i,j \f$. 439 439 440 440 \throw GSL_error if memory allocation fails. 441 441 */ 442 const matrix& operator*=(double d);442 const Matrix& operator*=(double d); 443 443 444 444 private: … … 473 473 474 474 /** 475 \brief Check if all elements of the matrix are zero.476 477 \return True if all elements in the matrix is zero, false475 \brief Check if all elements of the Matrix are zero. 476 477 \return True if all elements in the Matrix is zero, false 478 478 othwerwise. 479 479 */ 480 bool isnull(const matrix&);481 482 /** 483 \brief Get the maximum value of the matrix.484 485 \return The maximum value of the matrix.486 */ 487 double max(const matrix&);488 489 /** 490 \brief Get the minimum value of the matrix.491 492 \return The minimum value of the matrix.493 */ 494 double min(const matrix&);495 496 /** 497 \brief Locate the maximum and minumum element in the matrix.480 bool isnull(const Matrix&); 481 482 /** 483 \brief Get the maximum value of the Matrix. 484 485 \return The maximum value of the Matrix. 486 */ 487 double max(const Matrix&); 488 489 /** 490 \brief Get the minimum value of the Matrix. 491 492 \return The minimum value of the Matrix. 493 */ 494 double min(const Matrix&); 495 496 /** 497 \brief Locate the maximum and minumum element in the Matrix. 498 498 499 499 \return The indecies to the element with the minimum and maximum 500 values of the matrix, respectively.500 values of the Matrix, respectively. 501 501 502 502 \note Lower index has precedence (searching in row-major order). 503 503 */ 504 void minmax_index(const matrix&,504 void minmax_index(const Matrix&, 505 505 std::pair<size_t,size_t>& min, 506 506 std::pair<size_t,size_t>& max); 507 507 508 508 /** 509 \brief Create a matrix \a flag indicating NaN's in another matrix509 \brief Create a Matrix \a flag indicating NaN's in another Matrix 510 510 \a templat. 511 511 512 The \a flag matrix is changed to contain 1's and 0's only. A 1513 means that the corresponding element in the \a templat matrix is512 The \a flag Matrix is changed to contain 1's and 0's only. A 1 513 means that the corresponding element in the \a templat Matrix is 514 514 valid and a zero means that the corresponding element is a NaN. 515 515 516 \note Space for matrix \a flag is reallocated to fit the size of517 matrix \a templat if sizes mismatch.518 519 \return True if the \a templat matrix contains at least one NaN.520 */ 521 bool nan(const matrix& templat, matrix& flag);516 \note Space for Matrix \a flag is reallocated to fit the size of 517 Matrix \a templat if sizes mismatch. 518 519 \return True if the \a templat Matrix contains at least one NaN. 520 */ 521 bool nan(const Matrix& templat, Matrix& flag); 522 522 523 523 /** … … 528 528 \throw GSL_error if either index is out of bounds. 529 529 */ 530 void swap( matrix&, matrix&);531 532 /** 533 \brief The output operator for the matrix class.534 */ 535 std::ostream& operator<< (std::ostream& s, const matrix&);536 537 /** 538 \brief vector matrix multiplication530 void swap(Matrix&, Matrix&); 531 532 /** 533 \brief The output operator for the Matrix class. 534 */ 535 std::ostream& operator<< (std::ostream& s, const Matrix&); 536 537 /** 538 \brief vector Matrix multiplication 539 539 */ 540 Vector operator*(const matrix&, const VectorBase&);541 542 /** 543 \brief matrix vector multiplication540 Vector operator*(const Matrix&, const VectorBase&); 541 542 /** 543 \brief Matrix vector multiplication 544 544 */ 545 Vector operator*(const VectorBase&, const matrix&);545 Vector operator*(const VectorBase&, const Matrix&); 546 546 547 547 }}} // of namespace utility, yat, and theplu -
trunk/yat/utility/NNI.cc
r1000 r1121 38 38 // implementations here see the paper cited in the class definition 39 39 // documentation. 40 NNI::NNI(const utility:: matrix& matrix,const utility::matrix& weight,40 NNI::NNI(const utility::Matrix& matrix,const utility::Matrix& weight, 41 41 const u_int neighbours) 42 42 : data_(matrix), imputed_data_(matrix), neighbours_(neighbours), … … 75 75 76 76 77 const utility:: matrix& NNI::imputed_data(void) const77 const utility::Matrix& NNI::imputed_data(void) const 78 78 { 79 79 return imputed_data_; -
trunk/yat/utility/NNI.h
r1000 r1121 27 27 */ 28 28 29 #include " matrix.h"29 #include "Matrix.h" 30 30 31 31 #include <iostream> … … 88 88 /// algorithms. 89 89 /// 90 NNI(const utility:: matrix& matrix,const utility::matrix& weight,90 NNI(const utility::Matrix& matrix,const utility::Matrix& weight, 91 91 const u_int neighbours); 92 92 … … 103 103 /// @return A const reference to the modified data. 104 104 /// 105 const utility:: matrix& imputed_data(void) const;105 const utility::Matrix& imputed_data(void) const; 106 106 107 107 /// … … 124 124 /// original data matrix 125 125 /// 126 const utility:: matrix& data_;126 const utility::Matrix& data_; 127 127 128 128 /// 129 129 /// data after imputation 130 130 /// 131 utility:: matrix imputed_data_;131 utility::Matrix imputed_data_; 132 132 133 133 /// … … 144 144 /// weight matrix 145 145 /// 146 const utility:: matrix& weight_;146 const utility::Matrix& weight_; 147 147 }; 148 148 -
trunk/yat/utility/PCA.cc
r1120 r1121 40 40 41 41 42 PCA::PCA(const utility:: matrix& A)42 PCA::PCA(const utility::Matrix& A) 43 43 : A_(A) 44 44 { … … 53 53 54 54 55 const utility:: matrix& PCA::eigenvectors(void) const55 const utility::Matrix& PCA::eigenvectors(void) const 56 56 { 57 57 return eigenvectors_; … … 62 62 { 63 63 // Row-center the data matrix 64 utility:: matrix A_center( A_.rows(), A_.columns() );64 utility::Matrix A_center( A_.rows(), A_.columns() ); 65 65 this->row_center( A_center ); 66 66 … … 68 68 std::auto_ptr<SVD> pSVD( new SVD( A_center ) ); 69 69 pSVD->decompose(); 70 utility:: matrix U(pSVD->U());71 utility:: matrix V(pSVD->V());70 utility::Matrix U(pSVD->U()); 71 utility::Matrix V(pSVD->V()); 72 72 73 73 // Read the eigenvectors and eigenvalues … … 141 141 142 142 143 utility:: matrix PCA::projection(const utility::matrix& samples ) const143 utility::Matrix PCA::projection(const utility::Matrix& samples ) const 144 144 { 145 145 const size_t Ncol = samples.columns(); 146 146 const size_t Nrow = samples.rows(); 147 utility:: matrix projs( Ncol, Ncol );147 utility::Matrix projs( Ncol, Ncol ); 148 148 149 149 utility::Vector temp(samples.rows()); … … 189 189 // that is, A_ = A_ - M, where M is a matrix 190 190 // with the meanvalues of each row 191 void PCA::row_center(utility:: matrix& A_center)191 void PCA::row_center(utility::Matrix& A_center) 192 192 { 193 193 meanvalues_ = Vector(A_.rows()); -
trunk/yat/utility/PCA.h
r1120 r1121 29 29 */ 30 30 31 #include " matrix.h"31 #include "Matrix.h" 32 32 #include "Vector.h" 33 33 … … 56 56 should have been performed and no products. 57 57 */ 58 explicit PCA(const utility:: matrix&);58 explicit PCA(const utility::Matrix&); 59 59 60 60 /** … … 81 81 eigenvectors. 82 82 */ 83 const utility:: matrix& eigenvectors(void) const;83 const utility::Matrix& eigenvectors(void) const; 84 84 85 85 /** … … 90 90 spanned by the eigenvectors. 91 91 */ 92 utility:: matrix projection( const utility::matrix& ) const;92 utility::Matrix projection( const utility::Matrix& ) const; 93 93 94 94 /** … … 116 116 with the meanvalues of each row 117 117 */ 118 void row_center( utility:: matrix& A_center );118 void row_center( utility::Matrix& A_center ); 119 119 120 utility:: matrix A_;120 utility::Matrix A_; 121 121 utility::Vector eigenvalues_; 122 utility:: matrix eigenvectors_;122 utility::Matrix eigenvectors_; 123 123 utility::Vector meanvalues_; 124 124 }; -
trunk/yat/utility/SVD.cc
r1120 r1121 36 36 37 37 38 SVD::SVD(const utility:: matrix& Ain)38 SVD::SVD(const utility::Matrix& Ain) 39 39 : U_(Ain), V_(Ain.columns(),Ain.columns()), s_(Ain.columns()) 40 40 { … … 88 88 { 89 89 utility::Vector w(U_.columns()); 90 utility:: matrix X(U_.columns(),U_.columns());90 utility::Matrix X(U_.columns(),U_.columns()); 91 91 return gsl_linalg_SV_decomp_mod(U_.gsl_matrix_p(), X.gsl_matrix_p(), 92 92 V_.gsl_matrix_p(), s_.gsl_vector_p(), … … 111 111 112 112 113 const utility:: matrix& SVD::U(void) const113 const utility::Matrix& SVD::U(void) const 114 114 { 115 115 return U_; … … 117 117 118 118 119 const utility:: matrix& SVD::V(void) const119 const utility::Matrix& SVD::V(void) const 120 120 { 121 121 return V_; -
trunk/yat/utility/SVD.h
r1120 r1121 29 29 */ 30 30 31 #include " matrix.h"31 #include "Matrix.h" 32 32 #include "Vector.h" 33 33 … … 80 80 object. 81 81 */ 82 SVD(const utility:: matrix& Ain);82 SVD(const utility::Matrix& Ain); 83 83 84 84 /** … … 124 124 is undefined. 125 125 */ 126 const utility:: matrix& U(void) const;126 const utility::Matrix& U(void) const; 127 127 128 128 /** … … 134 134 is undefined. 135 135 */ 136 const utility:: matrix& V(void) const;136 const utility::Matrix& V(void) const; 137 137 138 138 private: … … 158 158 int modified_golub_reinsch(void); 159 159 160 utility:: matrix U_, V_;160 utility::Matrix U_, V_; 161 161 utility::Vector s_; 162 162 }; -
trunk/yat/utility/Vector.cc
r1120 r1121 26 26 27 27 #include "Vector.h" 28 #include "matrix.h"29 28 #include "utility.h" 30 29 #include "yat/random/random.h" -
trunk/yat/utility/VectorBase.cc
r1120 r1121 26 26 27 27 #include "VectorBase.h" 28 #include " matrix.h"28 #include "Vector.h" 29 29 #include "utility.h" 30 30 #include "yat/random/random.h" -
trunk/yat/utility/VectorConstView.cc
r1029 r1121 26 26 27 27 #include "VectorConstView.h" 28 #include " matrix.h"28 #include "Matrix.h" 29 29 30 30 namespace theplu { … … 56 56 57 57 58 VectorConstView::VectorConstView(const matrix& m, size_t i, bool row)58 VectorConstView::VectorConstView(const Matrix& m, size_t i, bool row) 59 59 : VectorBase(), const_view_(NULL) 60 60 { -
trunk/yat/utility/VectorConstView.h
r1029 r1121 38 38 namespace utility { 39 39 40 class matrix;40 class Matrix; 41 41 42 42 /** … … 100 100 use is undefined. 101 101 */ 102 VectorConstView(const matrix& m, size_t i, bool row=true);102 VectorConstView(const Matrix& m, size_t i, bool row=true); 103 103 104 104 /** -
trunk/yat/utility/VectorMutable.cc
r1118 r1121 26 26 27 27 #include "VectorMutable.h" 28 #include "matrix.h"29 28 #include "utility.h" 30 29 #include "yat/random/random.h" -
trunk/yat/utility/VectorView.cc
r1118 r1121 27 27 #include "VectorView.h" 28 28 #include "VectorMutable.h" 29 #include " matrix.h"29 #include "Matrix.h" 30 30 #include "utility.h" 31 31 #include "yat/random/random.h" … … 77 77 78 78 79 VectorView::VectorView( matrix& m, size_t i, bool row)79 VectorView::VectorView(Matrix& m, size_t i, bool row) 80 80 : VectorMutable() 81 81 { -
trunk/yat/utility/VectorView.h
r1120 r1121 43 43 namespace utility { 44 44 45 class matrix;45 class Matrix; 46 46 class Vector; 47 47 … … 144 144 /// use is undefined. 145 145 /// 146 VectorView( matrix& m, size_t i, bool row=true);146 VectorView(Matrix& m, size_t i, bool row=true); 147 147 148 148 /** -
trunk/yat/utility/WeNNI.cc
r1000 r1121 25 25 26 26 #include "WeNNI.h" 27 #include " matrix.h"27 #include "Matrix.h" 28 28 #include "stl_utility.h" 29 29 … … 37 37 38 38 39 WeNNI::WeNNI(const utility:: matrix& matrix,const utility::matrix& flag,39 WeNNI::WeNNI(const utility::Matrix& matrix,const utility::Matrix& flag, 40 40 const u_int neighbours) 41 41 : NNI(matrix,flag,neighbours), imputed_data_raw_(matrix) -
trunk/yat/utility/WeNNI.h
r1000 r1121 29 29 30 30 #include "NNI.h" 31 #include " matrix.h"31 #include "Matrix.h" 32 32 33 33 #include <iostream> … … 54 54 /// Constructor 55 55 /// 56 WeNNI(const utility:: matrix& matrix,const utility::matrix& weight,56 WeNNI(const utility::Matrix& matrix,const utility::Matrix& weight, 57 57 const u_int neighbours); 58 58 … … 67 67 /// @return A const reference to imputed_data_raw. 68 68 /// 69 const utility:: matrix& imputed_data_raw(void) const69 const utility::Matrix& imputed_data_raw(void) const 70 70 { return imputed_data_raw_; } 71 71 … … 73 73 private: 74 74 75 utility:: matrix imputed_data_raw_;75 utility::Matrix imputed_data_raw_; 76 76 }; 77 77 -
trunk/yat/utility/kNNI.cc
r1000 r1121 36 36 namespace utility { 37 37 38 kNNI::kNNI(const utility:: matrix& matrix,const utility::matrix& flag,38 kNNI::kNNI(const utility::Matrix& matrix,const utility::Matrix& flag, 39 39 const u_int neighbours) 40 40 : NNI(matrix,flag,neighbours) -
trunk/yat/utility/kNNI.h
r1000 r1121 55 55 /// Constructor 56 56 /// 57 kNNI(const utility:: matrix& matrix,const utility::matrix& weight,57 kNNI(const utility::Matrix& matrix,const utility::Matrix& weight, 58 58 const u_int neighbours); 59 59
Note: See TracChangeset
for help on using the changeset viewer.