ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_SumOfSquares.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_SUMOFSQUARES_HPP
20
#define ROL_SUMOFSQUARES_HPP
21
22
#include "
ROL_StdVector.hpp
"
23
#include "
ROL_TestProblem.hpp
"
24
25
namespace
ROL
{
26
namespace
ZOO {
27
30
template
<
class
Real>
31
class
Objective_SumOfSquares
:
public
Objective
<Real> {
32
public
:
33
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
34
return
x.
dot
(x);
35
}
36
37
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
38
g.
set
(x);
39
g.
scale
(2.0);
40
}
41
42
#if USE_HESSVEC
43
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
44
hv.
set
(v);
45
hv.
scale
(2.0);
46
}
47
#endif
48
49
void
invHessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
50
hv.
set
(v);
51
hv.
scale
(0.5);
52
}
53
};
54
55
template
<
class
Real>
56
class
getSumOfSquares
:
public
TestProblem
<Real> {
57
public
:
58
getSumOfSquares
(
void
) {}
59
60
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
61
// Instantiate Objective Function
62
return
ROL::makePtr<Objective_SumOfSquares<Real>>();
63
}
64
65
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
66
// Problem dimension
67
int
n = 100;
68
// Get Initial Guess
69
ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,1.0);
70
return
ROL::makePtr<StdVector<Real>>(x0p);
71
}
72
73
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
74
// Problem dimension
75
int
n = 100;
76
// Get Solution
77
ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
78
return
ROL::makePtr<StdVector<Real>>(xp);
79
}
80
};
81
82
}
// End ZOO Namespace
83
}
// End ROL Namespace
84
85
#endif
ROL_StdVector.hpp
ROL_TestProblem.hpp
Contains definitions of test objective functions.
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::Vector::set
virtual void set(const Vector &x)
Set where .
Definition
ROL_Vector.hpp:176
ROL::Vector::scale
virtual void scale(const Real alpha)=0
Compute where .
ROL::Vector::dot
virtual Real dot(const Vector &x) const =0
Compute where .
ROL::ZOO::Objective_SumOfSquares
Sum of squares function.
Definition
ROL_SumOfSquares.hpp:31
ROL::ZOO::Objective_SumOfSquares::invHessVec
void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_SumOfSquares.hpp:49
ROL::ZOO::Objective_SumOfSquares::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_SumOfSquares.hpp:37
ROL::ZOO::Objective_SumOfSquares::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_SumOfSquares.hpp:33
ROL::ZOO::getSumOfSquares::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_SumOfSquares.hpp:60
ROL::ZOO::getSumOfSquares::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_SumOfSquares.hpp:65
ROL::ZOO::getSumOfSquares::getSumOfSquares
getSumOfSquares(void)
Definition
ROL_SumOfSquares.hpp:58
ROL::ZOO::getSumOfSquares::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_SumOfSquares.hpp:73
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0