ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
ROL_SimulatedObjective.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
10
#ifndef ROL_SIMULATED_OBJECTIVE_H
11
#define ROL_SIMULATED_OBJECTIVE_H
12
13
#include "
ROL_SimulatedVector.hpp
"
14
#include "
ROL_Objective_SimOpt.hpp
"
15
16
namespace
ROL
{
17
18
template
<
class
Real>
19
class
SimulatedObjective
:
public
Objective
<Real> {
20
private
:
21
const
ROL::Ptr<SampleGenerator<Real> >
sampler_
;
22
const
ROL::Ptr<Objective_SimOpt<Real> >
pobj_
;
23
24
public
:
25
26
virtual
~SimulatedObjective
() {}
27
28
SimulatedObjective
(
const
ROL::Ptr<
SampleGenerator<Real>
> & sampler,
29
const
ROL::Ptr<
Objective_SimOpt<Real>
> & pobj)
30
:
sampler_
(sampler),
pobj_
(pobj) {}
31
32
void
update
(
const
Vector<Real>
&x,
bool
flag =
true
,
int
iter = -1 ) {
33
pobj_
->update(x,flag,iter);
34
}
35
void
update
(
const
Vector<Real>
&x,
UpdateType
type,
int
iter = -1 ) {
36
pobj_
->update(x,type,iter);
37
}
38
39
40
Real
value
(
const
Vector<Real>
&x,
41
Real &tol) {
42
const
Vector_SimOpt<Real>
&uz =
dynamic_cast<
const
Vector_SimOpt<Real>
&
>
(x);
43
ROL::Ptr<const Vector<Real> > uptr = uz.
get_1
();
44
ROL::Ptr<const Vector<Real> > zptr = uz.
get_2
();
45
const
SimulatedVector<Real>
&pu =
dynamic_cast<
const
SimulatedVector<Real>
&
>
(*uptr);
46
47
std::vector<Real> param;
48
Real weight(0);
49
Real val = 0;
50
Real tmpval = 0;
51
Real tmpsum = 0;
52
for
(
typename
std::vector<
SimulatedVector<Real>
>
::size_type
i=0; i<pu.
numVectors
(); ++i) {
53
param =
sampler_
->getMyPoint(
static_cast<
int
>
(i));
54
weight =
sampler_
->getMyWeight(
static_cast<
int
>
(i));
55
pobj_
->setParameter(param);
56
pobj_
->update(*(pu.
get
(i)), *zptr);
57
tmpval =
pobj_
->value(*(pu.
get
(i)), *zptr, tol);
58
tmpsum += tmpval*weight;
59
}
60
sampler_
->sumAll(&tmpsum, &val, 1);
61
return
val;
62
}
63
64
virtual
void
gradient
(
Vector<Real>
&g,
65
const
Vector<Real>
&x,
66
Real &tol) {
67
g.
zero
();
68
// split x
69
const
Vector_SimOpt<Real>
&xuz =
dynamic_cast<
const
Vector_SimOpt<Real>
&
>
(x);
70
ROL::Ptr<const Vector<Real> > xuptr = xuz.
get_1
();
71
ROL::Ptr<const Vector<Real> > xzptr = xuz.
get_2
();
72
const
SimulatedVector<Real>
&pxu =
dynamic_cast<
const
SimulatedVector<Real>
&
>
(*xuptr);
73
// split g
74
Vector_SimOpt<Real>
&guz =
dynamic_cast<
Vector_SimOpt<Real>
&
>
(g);
75
ROL::Ptr<Vector<Real> > guptr = guz.
get_1
();
76
ROL::Ptr<Vector<Real> > gzptr = guz.
get_2
();
77
SimulatedVector<Real>
&pgu =
dynamic_cast<
SimulatedVector<Real>
&
>
(*guptr);
78
79
std::vector<Real> param;
80
Real weight(0);
81
ROL::Ptr<Vector<Real> > tmp1 = gzptr->clone();
82
ROL::Ptr<Vector<Real> > tmp2 = gzptr->clone();
83
for
(
typename
std::vector<
SimulatedVector<Real>
>
::size_type
i=0; i<pgu.
numVectors
(); ++i) {
84
param =
sampler_
->getMyPoint(
static_cast<
int
>
(i));
85
weight =
sampler_
->getMyWeight(
static_cast<
int
>
(i));
86
pobj_
->setParameter(param);
87
Vector_SimOpt<Real>
xi(ROL::constPtrCast<
Vector<Real>
>(pxu.
get
(i)), ROL::constPtrCast<
Vector<Real>
>(xzptr));
88
Vector_SimOpt<Real>
gi(pgu.
get
(i), tmp1);
89
pobj_
->update(xi);
90
pobj_
->gradient(gi, xi, tol);
91
gi.
scale
(weight);
92
tmp2->plus(*tmp1);
93
}
94
sampler_
->sumAll(*tmp2, *gzptr);
95
96
}
97
98
99
virtual
void
hessVec
(
Vector<Real>
&hv,
100
const
Vector<Real>
&v,
101
const
Vector<Real>
&x,
102
Real &tol) {
103
hv.
zero
();
104
// split x
105
const
Vector_SimOpt<Real>
&xuz =
dynamic_cast<
const
Vector_SimOpt<Real>
&
>
(x);
106
ROL::Ptr<const Vector<Real> > xuptr = xuz.
get_1
();
107
ROL::Ptr<const Vector<Real> > xzptr = xuz.
get_2
();
108
const
SimulatedVector<Real>
&pxu =
dynamic_cast<
const
SimulatedVector<Real>
&
>
(*xuptr);
109
// split v
110
const
Vector_SimOpt<Real>
&vuz =
dynamic_cast<
const
Vector_SimOpt<Real>
&
>
(v);
111
ROL::Ptr<const Vector<Real> > vuptr = vuz.
get_1
();
112
ROL::Ptr<const Vector<Real> > vzptr = vuz.
get_2
();
113
const
SimulatedVector<Real>
&pvu =
dynamic_cast<
const
SimulatedVector<Real>
&
>
(*vuptr);
114
// split hv
115
Vector_SimOpt<Real>
&hvuz =
dynamic_cast<
Vector_SimOpt<Real>
&
>
(hv);
116
ROL::Ptr<Vector<Real> > hvuptr = hvuz.
get_1
();
117
ROL::Ptr<Vector<Real> > hvzptr = hvuz.
get_2
();
118
SimulatedVector<Real>
&phvu =
dynamic_cast<
SimulatedVector<Real>
&
>
(*hvuptr);
119
120
std::vector<Real> param;
121
Real weight(0);
122
ROL::Ptr<Vector<Real> > tmp1 = hvzptr->clone();
123
ROL::Ptr<Vector<Real> > tmp2 = hvzptr->clone();
124
for
(
typename
std::vector<
SimulatedVector<Real>
>
::size_type
i=0; i<phvu.
numVectors
(); ++i) {
125
param =
sampler_
->getMyPoint(
static_cast<
int
>
(i));
126
weight =
sampler_
->getMyWeight(
static_cast<
int
>
(i));
127
pobj_
->setParameter(param);
128
Vector_SimOpt<Real>
xi(ROL::constPtrCast<
Vector<Real>
>(pxu.
get
(i)), ROL::constPtrCast<
Vector<Real>
>(xzptr));
129
Vector_SimOpt<Real>
vi(ROL::constPtrCast<
Vector<Real>
>(pvu.
get
(i)), ROL::constPtrCast<
Vector<Real>
>(vzptr));
130
Vector_SimOpt<Real>
hvi(phvu.
get
(i), tmp1);
131
pobj_
->update(xi);
132
pobj_
->hessVec(hvi, vi, xi, tol);
133
hvi.
scale
(weight);
134
tmp2->plus(*tmp1);
135
}
136
sampler_
->sumAll(*tmp2, *hvzptr);
137
}
138
139
};
// class SimulatedObjective
140
141
}
// namespace ROL
142
143
#endif
ROL_Objective_SimOpt.hpp
ROL_SimulatedVector.hpp
ROL::Objective_SimOpt
Provides the interface to evaluate simulation-based objective functions.
Definition
ROL_Objective_SimOpt.hpp:25
ROL::size_type
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
ROL::SampleGenerator
Definition
ROL_SampleGenerator.hpp:20
ROL::SimulatedObjective::SimulatedObjective
SimulatedObjective(const ROL::Ptr< SampleGenerator< Real > > &sampler, const ROL::Ptr< Objective_SimOpt< Real > > &pobj)
Definition
ROL_SimulatedObjective.hpp:28
ROL::SimulatedObjective::update
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Definition
ROL_SimulatedObjective.hpp:35
ROL::SimulatedObjective::sampler_
const ROL::Ptr< SampleGenerator< Real > > sampler_
Definition
ROL_SimulatedObjective.hpp:21
ROL::SimulatedObjective::pobj_
const ROL::Ptr< Objective_SimOpt< Real > > pobj_
Definition
ROL_SimulatedObjective.hpp:22
ROL::SimulatedObjective::~SimulatedObjective
virtual ~SimulatedObjective()
Definition
ROL_SimulatedObjective.hpp:26
ROL::SimulatedObjective::update
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Definition
ROL_SimulatedObjective.hpp:32
ROL::SimulatedObjective::hessVec
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_SimulatedObjective.hpp:99
ROL::SimulatedObjective::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_SimulatedObjective.hpp:40
ROL::SimulatedObjective::gradient
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_SimulatedObjective.hpp:64
ROL::SimulatedVector
Defines the linear algebra of a vector space on a generic partitioned vector where the individual vec...
Definition
ROL_SimulatedVector.hpp:34
ROL::SimulatedVector::get
ROL::Ptr< const Vector< Real > > get(size_type i) const
Definition
ROL_SimulatedVector.hpp:231
ROL::SimulatedVector::numVectors
size_type numVectors() const
Definition
ROL_SimulatedVector.hpp:247
ROL::Vector_SimOpt
Defines the linear algebra or vector space interface for simulation-based optimization.
Definition
ROL_Vector_SimOpt.hpp:23
ROL::Vector_SimOpt::get_2
ROL::Ptr< const Vector< Real > > get_2() const
Definition
ROL_Vector_SimOpt.hpp:144
ROL::Vector_SimOpt::get_1
ROL::Ptr< const Vector< Real > > get_1() const
Definition
ROL_Vector_SimOpt.hpp:140
ROL::Vector_SimOpt::scale
void scale(const Real alpha)
Compute where .
Definition
ROL_Vector_SimOpt.hpp:45
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::zero
virtual void zero()
Set to zero vector.
Definition
ROL_Vector.hpp:134
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::UpdateType
UpdateType
Definition
ROL_UpdateType.hpp:18
Generated by
1.17.0