44 #ifndef ROL_NONLINEARCG_H
45 #define ROL_NONLINEARCG_H
77 struct NonlinearCGState {
78 std::vector<ROL::Ptr<Vector<Real> > > grad;
79 std::vector<ROL::Ptr<Vector<Real> > > pstep;
89 ROL::Ptr<NonlinearCGState<Real> > state_;
91 ROL::Ptr<Vector<Real> > y_;
92 ROL::Ptr<Vector<Real> > yd_;
96 virtual ~NonlinearCG() {}
100 state_ = ROL::makePtr<NonlinearCGState<Real>>();
102 state_->grad.resize(1);
103 state_->pstep.resize(1);
105 std::invalid_argument,
106 ">>> ERROR (ROL_NonlinearCG.hpp): Invalid nonlinear CG type in constructor!");
107 state_->nlcg_type = type;
108 ROL_TEST_FOR_EXCEPTION((restart < 1),
109 std::invalid_argument,
110 ">>> ERROR (ROL_NonlinearCG.hpp): Non-positive restart integer in constructor!");
111 state_->restart = restart;
114 ROL::Ptr<NonlinearCGState<Real> >& get_state() {
return this->state_; }
117 virtual void run( Vector<Real> &s ,
const Vector<Real> &g,
const Vector<Real> &x, Objective<Real> &obj ) {
120 if ( state_->iter == 0 ) {
133 if ((state_->iter % state_->restart) != 0) {
134 Real beta(0),
zero(0);
135 switch(state_->nlcg_type) {
139 y_->axpy(-one, *(state_->grad[0]));
140 beta = - g.dot(*y_) / (state_->pstep[0]->dot(y_->dual()));
141 beta = std::max(beta,
zero);
146 beta = g.dot(g) / (state_->grad[0])->dot(*(state_->grad[0]));
152 obj.hessVec( *y_, *(state_->pstep[0]), x, htol );
153 beta = - g.dot(*y_) / (state_->pstep[0])->dot(y_->dual());
154 beta = std::max(beta,
zero);
160 y_->axpy(-one, *(state_->grad[0]));
161 beta = g.dot(*y_) / (state_->grad[0])->dot(*(state_->grad[0]));
162 beta = std::max(beta,
zero);
167 beta = g.dot(g) / (state_->pstep[0])->dot((state_->grad[0])->dual());
173 y_->axpy(-one, *(state_->grad[0]));
174 beta = g.dot(*y_) / (state_->pstep[0])->dot((state_->grad[0])->dual());
181 y_->axpy(-one, *(state_->grad[0]));
182 beta = - g.dot(g) / (state_->pstep[0])->dot(y_->dual());
187 Real eta_0(1e-2), two(2);
189 y_->axpy(-one, *(state_->grad[0]));
191 Real mult = two * ( y_->dot(*y_) / (state_->pstep[0])->dot(y_->dual()) );
192 yd_->axpy(-mult, (state_->pstep[0])->dual());
193 beta = - yd_->dot(g) / (state_->pstep[0])->dot(y_->dual());
194 Real eta = -one / ((state_->pstep[0])->norm()*std::min(eta_0,(state_->grad[0])->norm()));
195 beta = std::max(beta, eta);
202 y_->axpy(-one, *(state_->grad[0]));
204 Real mult = ( y_->dot(*y_) / (state_->pstep[0])->dot(y_->dual()) );
205 yd_->axpy(-mult, (state_->pstep[0])->dual());
206 beta = - yd_->dot(g) / (state_->pstep[0])->dot(y_->dual());
207 Real eta = -one / ((state_->pstep[0])->norm()*std::min(eta_0,(state_->grad[0])->norm()));
208 beta = std::max(beta, eta);
214 std::invalid_argument,
215 ">>> ERROR (ROL_NonlinearCG.hpp): Invalid nonlinear CG type in the 'run' method!");
218 s.axpy(beta, *(state_->pstep[0]));
222 if (state_->iter == 0) {
223 (state_->grad[0]) = g.clone();
224 (state_->pstep[0]) = s.clone();
226 (state_->grad[0])->set(g);
227 (state_->pstep[0])->set(s);
Contains definitions of custom data types in ROL.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
ENonlinearCG
Enumeration of nonlinear CG algorithms.
int isValidNonlinearCG(ENonlinearCG s)
Verifies validity of a NonlinearCG enum.