QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
simplex.hpp
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) 2006 Ferdinando Ametrano
5 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file simplex.hpp
22 \brief Simplex optimization method
23*/
24
25/* The implementation of the algorithm was inspired by
26 * "Numerical Recipes in C", 2nd edition, Press, Teukolsky, Vetterling, Flannery
27 * Chapter 10
28 */
29
30#ifndef quantlib_optimization_simplex_hpp
31#define quantlib_optimization_simplex_hpp
32
34#include <vector>
35
36namespace QuantLib {
37
38 //! Multi-dimensional simplex class
39 /*! This method is rather raw and requires quite a lot of
40 computing resources, but it has the advantage that it does not
41 need any evaluation of the cost function's gradient, and that
42 it is quite easily implemented. First, we choose N+1
43 starting points, given here by a starting point \f$
44 \mathbf{P}_{0} \f$ and N points such that
45 \f[
46 \mathbf{P}_{\mathbf{i}}=\mathbf{P}_{0}+\lambda \mathbf{e}_{\mathbf{i}},
47 \f]
48 where \f$ \lambda \f$ is the problem's characteristic length scale). These
49 points will form a geometrical form called simplex.
50 The principle of the downhill simplex method is, at each
51 iteration, to move the worst point (highest cost function value)
52 through the opposite face to a better point. When the simplex
53 seems to be constrained in a valley, it will be contracted
54 downhill, keeping the best point unchanged.
55
56 \ingroup optimizers
57 */
58 class Simplex : public OptimizationMethod {
59 public:
60 /*! Constructor taking as input the characteristic length */
62 EndCriteria::Type minimize(Problem& P, const EndCriteria& endCriteria) override;
63 Real lambda() const { return lambda_; }
64
65 private:
67 Size iHighest,
68 Real& factor) const;
70 mutable std::vector<Array> vertices_;
71 mutable Array values_, sum_;
72 };
73
74}
75
76#endif
1-D array used in linear algebra.
Definition: array.hpp:52
Criteria to end optimization process:
Definition: endcriteria.hpp:40
Abstract class for constrained optimization method.
Definition: method.hpp:36
Constrained optimization problem.
Definition: problem.hpp:42
Multi-dimensional simplex class.
Definition: simplex.hpp:58
Real lambda() const
Definition: simplex.hpp:63
std::vector< Array > vertices_
Definition: simplex.hpp:70
Real extrapolate(Problem &P, Size iHighest, Real &factor) const
Definition: simplex.cpp:58
Simplex(Real lambda)
Definition: simplex.hpp:61
EndCriteria::Type minimize(Problem &P, const EndCriteria &endCriteria) override
minimize the optimization problem P
Definition: simplex.cpp:96
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Abstract optimization problem class.