1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007, 2008 Mark Joshi
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
20
21#ifndef quantlib_basis_incomplete_ordered_hpp
22#define quantlib_basis_incomplete_ordered_hpp
23
24#include <ql/math/matrix.hpp>
25#include <valarray>
26
27namespace QuantLib {
28
29 class BasisIncompleteOrdered {
30 public:
31 BasisIncompleteOrdered(Size euclideanDimension);
32 //! return value indicates if the vector was linearly independent
33 bool addVector(const Array& newVector);
34 Size basisSize() const;
35 Size euclideanDimension() const;
36 Matrix getBasisAsRowsInMatrix() const;
37 private:
38 std::vector<Array> currentBasis_;
39 Size euclideanDimension_;
40 Array newVector_;
41 };
42
43/*! Given a collection of vectors, w_i, find a collection of vectors x_i such that
44x_i is orthogonal to w_j for i != j, and <x_i, w_i> = <w_i, w_i>
45
46This is done by performing GramSchmidt on the other vectors and then projecting onto
47the orthogonal space.
48
49This class is tested in
50
51 MatricesTest::testOrthogonalProjection();
52*/
53
54 class OrthogonalProjections
55 {
56 public:
57 OrthogonalProjections(const Matrix& originalVectors,
58 Real multiplierCutOff,
59 Real tolerance );
60
61 const std::valarray<bool>& validVectors() const;
62 const std::vector<Real>& GetVector(Size index) const;
63
64 Size numberValidVectors() const;
65
66
67 private:
68
69 //! inputs
70 Matrix originalVectors_;
71 Real multiplierCutoff_;
72 Size numberVectors_;
73 Size numberValidVectors_;
74 Size dimension_;
75
76 //!outputs
77 std::valarray<bool> validVectors_;
78 std::vector<std::vector<Real> > projectedVectors_;
79
80 //!workspace
81 Matrix orthoNormalizedVectors_;
82
83
84 };
85
86}
87
88#endif
89

source code of quantlib/ql/math/matrixutilities/basisincompleteordered.hpp