44 #ifndef ROL_NONLINEARCG_H 45 #define ROL_NONLINEARCG_H 77 struct NonlinearCGState {
78 std::vector<Teuchos::RCP<Vector<Real> > > grad;
79 std::vector<Teuchos::RCP<Vector<Real> > > pstep;
89 Teuchos::RCP<NonlinearCGState<Real> > state_;
91 Teuchos::RCP<Vector<Real> > y_;
92 Teuchos::RCP<Vector<Real> > yd_;
96 virtual ~NonlinearCG() {}
100 state_ = Teuchos::rcp(
new 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 TEUCHOS_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 Teuchos::RCP<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 ) {
119 if ( state_->iter == 0 ) {
132 if ((state_->iter % state_->restart) != 0) {
134 switch(state_->nlcg_type) {
138 y_->axpy(-1.0, *(state_->grad[0]));
139 beta = - g.dot(*y_) / (state_->pstep[0]->dot(y_->dual()));
140 beta = std::max(beta, 0.0);
145 beta = g.dot(g) / (state_->grad[0])->dot(*(state_->grad[0]));
151 obj.hessVec( *y_, *(state_->pstep[0]), x, htol );
152 beta = - g.dot(*y_) / (state_->pstep[0])->dot(y_->dual());
153 beta = std::max(beta, 0.0);
159 y_->axpy(-1.0, *(state_->grad[0]));
160 beta = g.dot(*y_) / (state_->grad[0])->dot(*(state_->grad[0]));
161 beta = std::max(beta, 0.0);
166 beta = g.dot(g) / (state_->pstep[0])->dot((state_->grad[0])->dual());
172 y_->axpy(-1.0, *(state_->grad[0]));
173 beta = g.dot(*y_) / (state_->pstep[0])->dot((state_->grad[0])->dual());
180 y_->axpy(-1.0, *(state_->grad[0]));
181 beta = - g.dot(g) / (state_->pstep[0])->dot(y_->dual());
188 y_->axpy(-1.0, *(state_->grad[0]));
190 Real mult = 2.0 * ( y_->dot(*y_) / (state_->pstep[0])->dot(y_->dual()) );
191 yd_->axpy(-mult, (state_->pstep[0])->dual());
192 beta = - yd_->dot(g) / (state_->pstep[0])->dot(y_->dual());
193 Real eta = -1.0 / ((state_->pstep[0])->norm()*std::min(eta_0,(state_->grad[0])->norm()));
194 beta = std::max(beta, eta);
201 y_->axpy(-1.0, *(state_->grad[0]));
203 Real mult = ( y_->dot(*y_) / (state_->pstep[0])->dot(y_->dual()) );
204 yd_->axpy(-mult, (state_->pstep[0])->dual());
205 beta = - yd_->dot(g) / (state_->pstep[0])->dot(y_->dual());
206 Real eta = -1.0 / ((state_->pstep[0])->norm()*std::min(eta_0,(state_->grad[0])->norm()));
207 beta = std::max(beta, eta);
213 std::invalid_argument,
214 ">>> ERROR (ROL_NonlinearCG.hpp): Invalid nonlinear CG type in the 'run' method!");
217 s.axpy(beta, *(state_->pstep[0]));
221 if (state_->iter == 0) {
222 (state_->grad[0]) = g.clone();
223 (state_->pstep[0]) = s.clone();
225 (state_->grad[0])->
set(g);
226 (state_->pstep[0])->
set(s);
Contains definitions of custom data types in ROL.
ENonlinearCG
Enumeration of nonlinear CG algorithms.
int isValidNonlinearCG(ENonlinearCG s)
Verifies validity of a NonlinearCG enum.