10 #ifndef ROL_NONLINEARCG_H
11 #define ROL_NONLINEARCG_H
43 struct NonlinearCGState {
44 std::vector<ROL::Ptr<Vector<Real> > > grad;
45 std::vector<ROL::Ptr<Vector<Real> > > pstep;
55 ROL::Ptr<NonlinearCGState<Real> > state_;
57 ROL::Ptr<Vector<Real> > y_;
58 ROL::Ptr<Vector<Real> > yd_;
62 virtual ~NonlinearCG() {}
66 state_ = ROL::makePtr<NonlinearCGState<Real>>();
68 state_->grad.resize(1);
69 state_->pstep.resize(1);
71 std::invalid_argument,
72 ">>> ERROR (ROL_NonlinearCG.hpp): Invalid nonlinear CG type in constructor!");
73 state_->nlcg_type = type;
74 ROL_TEST_FOR_EXCEPTION((restart < 1),
75 std::invalid_argument,
76 ">>> ERROR (ROL_NonlinearCG.hpp): Non-positive restart integer in constructor!");
77 state_->restart = restart;
80 ROL::Ptr<NonlinearCGState<Real> >& get_state() {
return this->state_; }
83 virtual void run( Vector<Real> &s ,
const Vector<Real> &g,
const Vector<Real> &x, Objective<Real> &obj ) {
86 if ( state_->iter == 0 ) {
99 if ((state_->iter % state_->restart) != 0) {
100 Real beta(0),
zero(0);
101 switch(state_->nlcg_type) {
105 y_->axpy(-one, *(state_->grad[0]));
106 beta = - g.dot(*y_) / (state_->pstep[0]->dot(y_->dual()));
107 beta = std::max(beta,
zero);
112 beta = g.dot(g) / (state_->grad[0])->dot(*(state_->grad[0]));
118 obj.hessVec( *y_, *(state_->pstep[0]), x, htol );
119 beta = - g.dot(*y_) / (state_->pstep[0])->dot(y_->dual());
120 beta = std::max(beta,
zero);
126 y_->axpy(-one, *(state_->grad[0]));
127 beta = g.dot(*y_) / (state_->grad[0])->dot(*(state_->grad[0]));
128 beta = std::max(beta,
zero);
133 beta = g.dot(g) / (state_->pstep[0])->dot((state_->grad[0])->dual());
139 y_->axpy(-one, *(state_->grad[0]));
140 beta = g.dot(*y_) / (state_->pstep[0])->dot((state_->grad[0])->dual());
147 y_->axpy(-one, *(state_->grad[0]));
148 beta = - g.dot(g) / (state_->pstep[0])->dot(y_->dual());
153 Real eta_0(1e-2), two(2);
155 y_->axpy(-one, *(state_->grad[0]));
157 Real mult = two * ( y_->dot(*y_) / (state_->pstep[0])->dot(y_->dual()) );
158 yd_->axpy(-mult, (state_->pstep[0])->dual());
159 beta = - yd_->dot(g) / (state_->pstep[0])->dot(y_->dual());
160 Real eta = -one / ((state_->pstep[0])->norm()*std::min(eta_0,(state_->grad[0])->norm()));
161 beta = std::max(beta, eta);
168 y_->axpy(-one, *(state_->grad[0]));
170 Real mult = ( y_->dot(*y_) / (state_->pstep[0])->dot(y_->dual()) );
171 yd_->axpy(-mult, (state_->pstep[0])->dual());
172 beta = - yd_->dot(g) / (state_->pstep[0])->dot(y_->dual());
173 Real eta = -one / ((state_->pstep[0])->norm()*std::min(eta_0,(state_->grad[0])->norm()));
174 beta = std::max(beta, eta);
180 std::invalid_argument,
181 ">>> ERROR (ROL_NonlinearCG.hpp): Invalid nonlinear CG type in the 'run' method!");
184 s.axpy(beta, *(state_->pstep[0]));
188 if (state_->iter == 0) {
189 (state_->grad[0]) = g.clone();
190 (state_->pstep[0]) = s.clone();
192 (state_->grad[0])->set(g);
193 (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.