| 1 |
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
|
| 3 |
/* |
| 4 |
Copyright (C) 2003 Neil Firth |
| 5 |
|
| 6 |
This file is part of QuantLib, a free-software/open-source library |
| 7 |
for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 |
|
| 9 |
QuantLib is free software: you can redistribute it and/or modify it |
| 10 |
under the terms of the QuantLib license. You should have received a |
| 11 |
copy of the license along with this program; if not, please email |
| 12 |
<quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 |
<http://quantlib.org/license.shtml>. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 |
FOR A PARTICULAR PURPOSE. See the license for more details. |
| 18 |
|
| 19 |
Adapted from the TNT project |
| 20 |
http://math.nist.gov/tnt/download.html |
| 21 |
|
| 22 |
This software was developed at the National Institute of Standards |
| 23 |
and Technology (NIST) by employees of the Federal Government in the |
| 24 |
course of their official duties. Pursuant to title 17 Section 105 |
| 25 |
of the United States Code this software is not subject to copyright |
| 26 |
protection and is in the public domain. NIST assumes no responsibility |
| 27 |
whatsoever for its use by other parties, and makes no guarantees, |
| 28 |
expressed or implied, about its quality, reliability, or any other |
| 29 |
characteristic. |
| 30 |
|
| 31 |
We would appreciate acknowledgement if the software is incorporated in |
| 32 |
redistributable libraries or applications. |
| 33 |
|
| 34 |
*/ |
| 35 |
|
| 36 |
/*! \file svd.hpp |
| 37 |
\brief singular value decomposition |
| 38 |
*/ |
| 39 |
|
| 40 |
#ifndef math_svd_hpp |
| 41 |
#define math_svd_hpp |
| 42 |
|
| 43 |
#include "math/RectMatrix.hpp" |
| 44 |
|
| 45 |
namespace oopse { |
| 46 |
|
| 47 |
//! Singular value decomposition |
| 48 |
/*! Refer to Golub and Van Loan: Matrix computation, |
| 49 |
The Johns Hopkins University Press |
| 50 |
|
| 51 |
\test the correctness of the returned values is tested by |
| 52 |
checking their properties. |
| 53 |
*/ |
| 54 |
class SVD { |
| 55 |
public: |
| 56 |
// constructor |
| 57 |
SVD(const RectMatrix&); |
| 58 |
// results |
| 59 |
const RectMatrix& U() const; |
| 60 |
const RectMatrix& V() const; |
| 61 |
const Vector& singularValues() const; |
| 62 |
RectMatrix S() const; |
| 63 |
Real norm2(); |
| 64 |
Real cond(); |
| 65 |
Integer rank(); |
| 66 |
// utilities |
| 67 |
Vector solveFor(const Vector&) const; |
| 68 |
private: |
| 69 |
RectMatrix U_, V_; |
| 70 |
Vector s_; |
| 71 |
int m_, n_; |
| 72 |
bool transpose_; |
| 73 |
}; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
#endif |
| 78 |
|