10 #ifndef ROL_COMPOSITE_OBJECTIVE_DEF_H
11 #define ROL_COMPOSITE_OBJECTIVE_DEF_H
15 template<
typename Real>
18 : obj_vec_(obj_vec), std_obj_(std_obj), isInitialized_(false),
19 isValueComputed_(false), isGradientComputed_(false) {
30 template<
typename Real>
32 int size = obj_vec_.size();
33 for (
int i = 0; i < size; ++i) {
34 obj_vec_[i]->update(x,type,iter);
36 isValueComputed_ =
false;
40 template<
typename Real>
42 int size = obj_vec_.size();
43 for (
int i = 0; i < size; ++i) {
44 obj_vec_[i]->update(x,flag,iter);
46 isValueComputed_ =
false;
47 isGradientComputed_ = (flag ?
false : isGradientComputed_);
50 template<
typename Real>
53 return std_obj_->value(*obj_value_vec_,tol);
56 template<
typename Real>
59 computeGradient(x,tol);
60 int size = obj_vec_.size();
61 for (
int i = 0; i < size; ++i) {
62 g.
axpy((*obj_grad_)[i],*(vec_grad_[i]));
66 template<
typename Real>
69 computeHessVec(v,x,tol);
70 int size = obj_vec_.size();
71 for (
int i = 0; i < size; ++i) {
72 hv.
axpy((*obj_grad_)[i],*(vec_hess_[i]));
73 hv.
axpy((*obj_hess_)[i],*(vec_grad_[i]));
77 template<
typename Real>
80 const int size = obj_vec_.size();
81 for (
int i = 0; i < size; ++i) {
82 obj_vec_[i]->setParameter(param);
84 std_obj_->setParameter(param);
85 isValueComputed_ =
false;
86 isGradientComputed_ =
false;
89 template<
typename Real>
92 int size = obj_vec_.size();
93 vec_grad_.clear(); vec_grad_.resize(size,nullPtr);
94 vec_hess_.clear(); vec_hess_.resize(size,nullPtr);
95 for (
int i = 0; i < size; ++i) {
99 isInitialized_ =
true;
103 template<
typename Real>
106 if (!isValueComputed_) {
107 int size = obj_vec_.size();
108 for (
int i = 0; i < size; ++i) {
109 (*obj_value_)[i] = obj_vec_[i]->value(x,tol);
111 isValueComputed_ =
true;
115 template<
typename Real>
118 if (!isGradientComputed_) {
119 std_obj_->gradient(*(obj_grad_vec_),*(obj_value_vec_),tol);
120 int size = obj_vec_.size();
121 for (
int i = 0; i < size; ++i) {
122 obj_vec_[i]->gradient(*(vec_grad_[i]),x,tol);
124 isGradientComputed_ =
true;
128 template<
typename Real>
130 computeGradient(x,tol);
131 int size = obj_vec_.size();
132 for (
int i = 0; i < size; ++i) {
134 (*obj_gv_)[i] = vec_grad_[i]->apply(v);
135 obj_vec_[i]->hessVec(*(vec_hess_[i]),v,x,tol);
137 std_obj_->hessVec(*(obj_hess_vec_),*(obj_gv_vec_),*(obj_value_vec_),tol);
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply Hessian approximation to vector.
Ptr< StdVector< Real > > obj_hess_vec_
void computeValue(const Vector< Real > &x, Real &tol)
const std::vector< Ptr< Objective< Real > > > obj_vec_
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
Ptr< std::vector< Real > > obj_gv_
void computeGradient(const Vector< Real > &x, Real &tol)
CompositeObjective(const std::vector< Ptr< Objective< Real >>> &obj_vec, const Ptr< StdObjective< Real >> &std_obj)
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
void initialize(const Vector< Real > &x)
Ptr< std::vector< Real > > obj_value_
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
Ptr< std::vector< Real > > obj_hess_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.
Ptr< StdVector< Real > > obj_value_vec_
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
Ptr< StdVector< Real > > obj_gv_vec_
virtual void setParameter(const std::vector< Real > ¶m)
Ptr< std::vector< Real > > obj_grad_
void computeHessVec(const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Ptr< StdVector< Real > > obj_grad_vec_
void setParameter(const std::vector< Real > ¶m) override