51#include "ROL_ParameterList.hpp"
79class Secant :
public LinearOperator<Real> {
96 Secant(
int M = 10,
bool useDefaultScaling =
true, Real Bscaling = Real(1), ESecantMode
mode = SECANTMODE_BOTH )
97 : state_(makePtr<SecantState<Real>>(M,
mode)),
98 useDefaultScaling_(useDefaultScaling), Bscaling_(Bscaling),
99 isInitialized_(false) {}
102 const Ptr<SecantState<Real>>&
get_state()
const {
return state_; }
105 virtual void updateStorage(
const Vector<Real> &x,
const Vector<Real> &grad,
106 const Vector<Real> &gp,
const Vector<Real> &s,
109 if ( !isInitialized_ ) {
110 state_->iterate = x.clone();
112 isInitialized_ =
true;
114 state_->iterate->set(x);
120 Real sy = s.apply(*y_);
122 if (state_->current < state_->storage-1) {
124 state_->iterDiff.push_back(s.clone());
125 state_->gradDiff.push_back(grad.clone());
128 state_->iterDiff.push_back(state_->iterDiff[0]);
129 state_->gradDiff.push_back(state_->gradDiff[0]);
130 state_->iterDiff.erase(state_->iterDiff.begin());
131 state_->gradDiff.erase(state_->gradDiff.begin());
132 state_->product.erase(state_->product.begin());
134 state_->iterDiff[state_->current]->set(s);
135 state_->gradDiff[state_->current]->set(*y_);
136 state_->product.push_back(sy);
141 virtual void applyH( Vector<Real> &Hv,
const Vector<Real> &v )
const = 0;
144 virtual void applyH0( Vector<Real> &Hv,
const Vector<Real> &v )
const {
146 if (useDefaultScaling_) {
147 if (state_->iter != 0 && state_->current != -1) {
148 Real yy = state_->gradDiff[state_->current]->dot(*(state_->gradDiff[state_->current]));
149 Hv.scale(state_->product[state_->current]/yy);
153 Hv.scale(
static_cast<Real
>(1)/Bscaling_);
158 virtual void applyB( Vector<Real> &Bv,
const Vector<Real> &v )
const = 0;
161 virtual void applyB0( Vector<Real> &Bv,
const Vector<Real> &v )
const {
163 if (useDefaultScaling_) {
164 if (state_->iter != 0 && state_->current != -1) {
165 Real yy = state_->gradDiff[state_->current]->dot(*(state_->gradDiff[state_->current]));
166 Bv.scale(yy/state_->product[state_->current]);
175 void test(std::ostream &stream = std::cout )
const {
176 if (isInitialized_) {
177 Ptr<Vector<Real>> v = state_->iterate->clone();
178 Ptr<Vector<Real>> Hv = state_->iterate->clone();
179 Ptr<Vector<Real>> Bv = state_->iterate->dual().clone();
183 v->randomize(-one,one);
187 stream <<
" ||BHv-v|| = " << v->norm() << std::endl;
190 v->randomize(-one,one);
194 stream <<
" ||HBv-v|| = " << v->norm() << std::endl;
198 void apply(Vector<Real> &Hv,
const Vector<Real> &v, Real &tol)
const {
202 void applyInverse(Vector<Real> &Hv,
const Vector<Real> &v, Real &tol)
const {
Ptr< Vector< Real > > iterate
std::vector< Ptr< Vector< Real > > > iterDiff
std::vector< Real > product2
std::vector< Real > product
std::vector< Ptr< Vector< Real > > > gradDiff
Contains definitions of custom data types in ROL.
Provides interface for and implements limited-memory secant operators.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
virtual void applyB0(Vector< Real > &Bv, const Vector< Real > &v) const
virtual void updateStorage(const Vector< Real > &x, const Vector< Real > &grad, const Vector< Real > &gp, const Vector< Real > &s, const Real snorm, const int iter)
const Ptr< SecantState< Real > > state_
virtual void applyH0(Vector< Real > &Hv, const Vector< Real > &v) const
const Ptr< SecantState< Real > > & get_state() const
Ptr< SecantState< Real > > & get_state()
virtual void applyB(Vector< Real > &Bv, const Vector< Real > &v) const =0
virtual void applyH(Vector< Real > &Hv, const Vector< Real > &v) const =0
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Secant(int M=10, bool useDefaultScaling=true, Real Bscaling=Real(1), ESecantMode mode=SECANTMODE_BOTH)
void test(std::ostream &stream=std::cout) const