ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_Powell.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Rapid Optimization Library (ROL) Package
4
//
5
// Copyright 2014 NTESS and the ROL contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
14
15
#ifndef USE_HESSVEC
16
#define USE_HESSVEC 1
17
#endif
18
19
#ifndef ROL_POWELL_HPP
20
#define ROL_POWELL_HPP
21
22
#include "
ROL_ScaledStdVector.hpp
"
23
#include "
ROL_TestProblem.hpp
"
24
25
namespace
ROL
{
26
namespace
ZOO {
27
30
template
<
class
Real>
31
class
Objective_Powell
:
public
Objective
<Real> {
32
33
public
:
34
Objective_Powell
() {}
35
36
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
37
ROL::Ptr<const std::vector<Real> > xp
38
=
dynamic_cast<
const
PrimalScaledStdVector<Real>
&
>
(x).getVector();
39
40
Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
41
Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
42
43
return
f1*f1+f2*f2;
44
}
45
46
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
47
ROL::Ptr<std::vector<Real> > gp
48
=
dynamic_cast<
DualScaledStdVector<Real>
&
>
(g).getVector();
49
ROL::Ptr<const std::vector<Real> > xp
50
=
dynamic_cast<
const
PrimalScaledStdVector<Real>
&
>
(x).getVector();
51
52
Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
53
Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
54
55
Real f11 = 1.e4*(*xp)[1];
56
Real f12 = 1.e4*(*xp)[0];
57
Real f21 = -std::exp(-(*xp)[0]);
58
Real f22 = -std::exp(-(*xp)[1]);
59
60
(*gp)[0] = 2.0*(f11*f1 + f21*f2);
61
(*gp)[1] = 2.0*(f12*f1 + f22*f2);
62
}
63
#if USE_HESSVEC
64
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
65
ROL::Ptr<std::vector<Real> > hvp
66
=
dynamic_cast<
DualScaledStdVector<Real>
&
>
(hv).getVector();
67
ROL::Ptr<const std::vector<Real> > vp
68
=
dynamic_cast<
const
PrimalScaledStdVector<Real>
&
>
(v).getVector();
69
ROL::Ptr<const std::vector<Real> > xp
70
=
dynamic_cast<
const
PrimalScaledStdVector<Real>
&
>
(x).getVector();
71
72
Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
73
Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
74
75
Real f11 = 1.e4*(*xp)[1];
76
Real f12 = 1.e4*(*xp)[0];
77
Real f21 = -std::exp(-(*xp)[0]);
78
Real f22 = -std::exp(-(*xp)[1]);
79
80
Real f111 = 0.0;
81
Real f112 = 1.e4;
82
Real f121 = 1.e4;
83
Real f122 = 0.0;
84
Real f211 = std::exp(-(*xp)[0]);
85
Real f212 = 0.0;
86
Real f221 = 0.0;
87
Real f222 = std::exp(-(*xp)[1]);
88
89
Real h11 = 2.0*(f111*f1 + f11*f11) + 2.0*(f211*f2 + f21*f21);
90
Real h12 = 2.0*(f112*f1 + f11*f12) + 2.0*(f212*f2 + f21*f22);
91
Real h21 = 2.0*(f121*f1 + f12*f11) + 2.0*(f221*f2 + f22*f21);
92
Real h22 = 2.0*(f122*f1 + f12*f12) + 2.0*(f222*f2 + f22*f22);
93
94
(*hvp)[0] = h11*(*vp)[0] + h12*(*vp)[1];
95
(*hvp)[1] = h21*(*vp)[0] + h22*(*vp)[1];
96
}
97
#endif
98
void
invHessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
99
ROL::Ptr<std::vector<Real> > hvp
100
=
dynamic_cast<
PrimalScaledStdVector<Real>
&
>
(hv).getVector();
101
ROL::Ptr<const std::vector<Real> > vp
102
=
dynamic_cast<
const
DualScaledStdVector<Real>
&
>
(v).getVector();
103
ROL::Ptr<const std::vector<Real> > xp
104
=
dynamic_cast<
const
PrimalScaledStdVector<Real>
&
>
(x).getVector();
105
106
Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
107
Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
108
109
Real f11 = 1.e4*(*xp)[1];
110
Real f12 = 1.e4*(*xp)[0];
111
Real f21 = -std::exp(-(*xp)[0]);
112
Real f22 = -std::exp(-(*xp)[1]);
113
114
Real f111 = 0.0;
115
Real f112 = 1.e4;
116
Real f121 = 1.e4;
117
Real f122 = 0.0;
118
Real f211 = std::exp(-(*xp)[0]);
119
Real f212 = 0.0;
120
Real f221 = 0.0;
121
Real f222 = std::exp(-(*xp)[1]);
122
123
Real h11 = 2.0*(f111*f1 + f11*f11) + 2.0*(f211*f2 + f21*f21);
124
Real h12 = 2.0*(f112*f1 + f11*f12) + 2.0*(f212*f2 + f21*f22);
125
Real h21 = 2.0*(f121*f1 + f21*f11) + 2.0*(f221*f2 + f22*f21);
126
Real h22 = 2.0*(f122*f1 + f12*f12) + 2.0*(f222*f2 + f22*f22);
127
128
(*hvp)[0] = (1.0/(h11*h22-h12*h21))*( h22*(*vp)[0] - h21*(*vp)[1]);
129
(*hvp)[1] = (1.0/(h11*h22-h12*h21))*(-h12*(*vp)[0] + h11*(*vp)[1]);
130
}
131
};
132
133
template
<
class
Real>
134
class
getPowell
:
public
TestProblem
<Real> {
135
private
:
136
ROL::Ptr<std::vector<Real> >
scale_
;
137
138
public
:
139
getPowell
(
void
) {
140
// Get problem scaling
141
scale_
= ROL::makePtr<std::vector<Real>>(2,0.0);
142
(*scale_)[0] = 1.e10; (*scale_)[1] = 1.e-2;
143
}
144
145
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
146
// Instantiate Objective Function
147
return
ROL::makePtr<Objective_Powell<Real>>();
148
}
149
150
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
151
// Problem dimension
152
int
n = 2;
153
// Get Initial Guess
154
ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,0.0);
155
(*x0p)[0] = 0.0; (*x0p)[1] = 1.0;
156
return
ROL::makePtr<PrimalScaledStdVector<Real>>(x0p,
scale_
);
157
}
158
159
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
160
// Problem dimension
161
int
n = 2;
162
// Get Solution: (*xp)[0] = 1.0981770261368074e-05;
163
ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
164
(*xp)[0] = 1.098e-05; (*xp)[1] = 9.106;
165
return
ROL::makePtr<PrimalScaledStdVector<Real>>(xp,
scale_
);
166
}
167
};
168
169
}
// End ZOO Namespace
170
}
// End ROL Namespace
171
172
#endif
ROL_ScaledStdVector.hpp
ROL_TestProblem.hpp
Contains definitions of test objective functions.
ROL::DualScaledStdVector
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
Definition
ROL_ScaledStdVector.hpp:102
ROL::PrimalScaledStdVector
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
Definition
ROL_ScaledStdVector.hpp:34
ROL::ROL::Objective::hessVec
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition
ROL_ObjectiveDef.hpp:61
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
ROL::TestProblem::TestProblem
TestProblem(void)
Definition
ROL_TestProblem.hpp:28
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::ZOO::Objective_Powell::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_Powell.hpp:36
ROL::ZOO::Objective_Powell::invHessVec
void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_Powell.hpp:98
ROL::ZOO::Objective_Powell::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_Powell.hpp:46
ROL::ZOO::Objective_Powell::Objective_Powell
Objective_Powell()
Definition
ROL_Powell.hpp:34
ROL::ZOO::getPowell::getPowell
getPowell(void)
Definition
ROL_Powell.hpp:139
ROL::ZOO::getPowell::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_Powell.hpp:145
ROL::ZOO::getPowell::scale_
ROL::Ptr< std::vector< Real > > scale_
Definition
ROL_Powell.hpp:136
ROL::ZOO::getPowell::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_Powell.hpp:159
ROL::ZOO::getPowell::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_Powell.hpp:150
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0