QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
projection.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 François du Vignaud
5 Copyright (C) 2007 Giorgio Facchinetti
6 Copyright (C) 2013 Peter Caspers
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
23#include <utility>
24
25namespace QuantLib {
26
27 Projection::Projection(const Array& parameterValues, std::vector<bool> fixParameters)
28 : fixedParameters_(parameterValues), actualParameters_(parameterValues),
29 fixParameters_(std::move(fixParameters)) {
30
31 if (fixParameters_.empty())
33 std::vector<bool>(actualParameters_.size(), false);
34
36 "fixedParameters_.size()!=parametersFreedoms_.size()");
37 for (auto&& fixParameter : fixParameters_)
38 if (!fixParameter)
40 QL_REQUIRE(numberOfFreeParameters_ > 0, "numberOfFreeParameters==0");
41 }
42
43 void Projection::mapFreeParameters(const Array &parameterValues) const {
44
45 QL_REQUIRE(parameterValues.size() == numberOfFreeParameters_,
46 "parameterValues.size()!=numberOfFreeParameters");
47 Size i = 0;
48 for (Size j = 0; j < actualParameters_.size(); j++)
49 if (!fixParameters_[j])
50 actualParameters_[j] = parameterValues[i++];
51
52 }
53
54 Array Projection::project(const Array &parameters) const {
55
56 QL_REQUIRE(parameters.size() == fixParameters_.size(),
57 "parameters.size()!=parametersFreedoms_.size()");
58 Array projectedParameters(numberOfFreeParameters_);
59 Size i = 0;
60 for (Size j = 0; j < fixParameters_.size(); j++)
61 if (!fixParameters_[j])
62 projectedParameters[i++] = parameters[j];
63 return projectedParameters;
64
65 }
66
67 Array Projection::include(const Array &projectedParameters) const {
68
69 QL_REQUIRE(projectedParameters.size() == numberOfFreeParameters_,
70 "projectedParameters.size()!=numberOfFreeParameters");
72 Size i = 0;
73 for (Size j = 0; j < y.size(); j++)
74 if (!fixParameters_[j])
75 y[j] = projectedParameters[i++];
76 return y;
77
78 }
79}
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:495
const Array fixedParameters_
Definition: projection.hpp:50
virtual Array include(const Array &projectedParameters) const
returns whole set of parameters corresponding to the set
Definition: projection.cpp:67
std::vector< bool > fixParameters_
Definition: projection.hpp:52
Projection(const Array &parameterValues, std::vector< bool > fixParameters=std::vector< bool >())
Definition: projection.cpp:27
virtual Array project(const Array &parameters) const
returns the subset of free parameters corresponding
Definition: projection.cpp:54
void mapFreeParameters(const Array &parameterValues) const
Definition: projection.cpp:43
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.
Parameter projection.