44 #ifndef ROL_COMPOSITE_OBJECTIVE_H 45 #define ROL_COMPOSITE_OBJECTIVE_H 60 const std::vector<Teuchos::RCP<Objective<Real> > >
obj_vec_;
61 const Teuchos::RCP<StdObjective<Real> >
std_obj_;
71 int size = obj_vec_.size();
72 vec_grad_.clear(); vec_grad_.resize(size,Teuchos::null);
73 vec_hess_.clear(); vec_hess_.resize(size,Teuchos::null);
74 for (
int i = 0; i < size; ++i) {
75 vec_grad_[i] = x.
dual().clone();
76 vec_hess_[i] = x.
dual().clone();
78 isInitialized_ =
true;
84 if (!isValueComputed_) {
85 int size = obj_vec_.size();
86 for (
int i = 0; i < size; ++i) {
87 (*obj_value_)[i] = obj_vec_[i]->value(x,tol);
89 isValueComputed_ =
true;
95 if (!isGradientComputed_) {
96 std_obj_->gradient(*(obj_grad_vec_),*(obj_value_vec_),tol);
97 int size = obj_vec_.size();
98 for (
int i = 0; i < size; ++i) {
99 obj_vec_[i]->gradient(*(vec_grad_[i]),x,tol);
101 isGradientComputed_ =
true;
107 int size = obj_vec_.size();
108 for (
int i = 0; i < size; ++i) {
109 (*obj_gv_)[i] = vec_grad_[i]->dot(v.
dual());
110 obj_vec_[i]->hessVec(*(vec_hess_[i]),v,x,tol);
112 std_obj_->hessVec(*(obj_hess_vec_),*(obj_gv_vec_),*(obj_value_vec_),tol);
118 : obj_vec_(obj_vec), std_obj_(std_obj), isInitialized_(false),
119 isValueComputed_(false), isGradientComputed_(false) {
120 obj_value_ = Teuchos::rcp(
new std::vector<Real>(obj_vec_.size(),0));
122 obj_grad_ = Teuchos::rcp(
new std::vector<Real>(obj_vec_.size(),0));
124 obj_gv_ = Teuchos::rcp(
new std::vector<Real>(obj_vec_.size(),0));
126 obj_hess_ = Teuchos::rcp(
new std::vector<Real>(obj_vec_.size(),0));
131 int size = obj_vec_.size();
132 for (
int i = 0; i < size; ++i) {
133 obj_vec_[i]->update(x,flag,iter);
135 isValueComputed_ =
false;
141 return std_obj_->value(*obj_value_vec_,tol);
147 int size = obj_vec_.size();
148 for (
int i = 0; i < size; ++i) {
149 g.
axpy((*obj_grad_)[i],*(vec_grad_[i]));
156 int size = obj_vec_.size();
157 for (
int i = 0; i < size; ++i) {
158 hv.
axpy((*obj_grad_)[i],*(vec_hess_[i]));
159 hv.
axpy((*obj_hess_)[i],*(vec_grad_[i]));
167 const int size = obj_vec_.size();
168 for (
int i = 0; i < size; ++i) {
169 obj_vec_[i]->setParameter(param);
171 std_obj_->setParameter(param);
172 isValueComputed_ =
false;
173 isGradientComputed_ =
false;
Provides the interface to evaluate objective functions.
void computeValue(const Vector< Real > &x, Real &tol)
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Teuchos::RCP< std::vector< Real > > obj_gv_
void computeGradient(const Vector< Real > &x, Real &tol)
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
CompositeObjective(const std::vector< Teuchos::RCP< Objective< Real > > > &obj_vec, const Teuchos::RCP< StdObjective< Real > > &std_obj)
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
void initialize(const Vector< Real > &x)
const Teuchos::RCP< StdObjective< Real > > std_obj_
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Real value(const Vector< Real > &x, Real &tol)
Compute value.
std::vector< Teuchos::RCP< Vector< Real > > > vec_hess_
Teuchos::RCP< StdVector< Real > > obj_hess_vec_
const std::vector< Teuchos::RCP< Objective< Real > > > obj_vec_
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Teuchos::RCP< StdVector< Real > > obj_gv_vec_
virtual void setParameter(const std::vector< Real > ¶m)
Teuchos::RCP< StdVector< Real > > obj_grad_vec_
Teuchos::RCP< std::vector< Real > > obj_hess_
Teuchos::RCP< std::vector< Real > > obj_grad_
void computeHessVec(const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Teuchos::RCP< StdVector< Real > > obj_value_vec_
Teuchos::RCP< std::vector< Real > > obj_value_
Provides the interface to evaluate composite objective functions.
std::vector< Teuchos::RCP< Vector< Real > > > vec_grad_
void setParameter(const std::vector< Real > ¶m)