ROL
ROL_TypeP_InexactNewtonAlgorithm.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Rapid Optimization Library (ROL) Package
4//
5// Copyright 2014 NTESS and the ROL contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef ROL_TYPEP_INEXACTNEWTONALGORITHM_HPP
11#define ROL_TYPEP_INEXACTNEWTONALGORITHM_HPP
12
14
19namespace ROL {
20namespace TypeP {
21
22template<typename Real>
24private:
25 Real t0_;
27
28 int maxit_;
29 Real rhodec_;
30 Real c1_;
31 Real sigma1_;
32 Real sigma2_;
35 Real sp_exp_;
37 std::string algoName_;
38
39 ParameterList list_;
40
44
45 using TypeP::Algorithm<Real>::pgstep;
46 using TypeP::Algorithm<Real>::status_;
47 using TypeP::Algorithm<Real>::state_;
48
49 class NewtonObj : public Objective<Real> {
50 private:
51 const Ptr<Objective<Real>> obj_;
52 const Ptr<Vector<Real>> x_;
53 const Ptr<Vector<Real>> g_;
54 Ptr<Vector<Real>> pwa_, dwa_, Hx_;
56 int nhess_;
57
58 public:
59 NewtonObj(const Ptr<Objective<Real>> &obj, const Vector<Real> &x, const Vector<Real> &g)
60 : obj_(obj), x_(x.clone()), g_(g.clone()), pwa_(x.clone()),
61 dwa_(g.clone()), Hx_(g.clone()), isHessApplied_(false), nhess_(0) {}
62 void update(const Vector<Real> &x, UpdateType type, int iter) {
63 isHessApplied_ = false;
64 }
65 Real value(const Vector<Real> &x, Real &tol) {
66 const Real half(0.5), one(1);
67 pwa_->set(x); pwa_->axpy(-one,*x_);
68 if (!isHessApplied_) {
69 obj_->hessVec(*Hx_,*pwa_,*x_,tol); nhess_++;
70 isHessApplied_ = true;
71 }
72 dwa_->set(*Hx_);
73 dwa_->scale(half);
74 dwa_->plus(*g_);
75 return dwa_->apply(*pwa_);
76 }
77 void gradient(Vector<Real> &g, const Vector<Real> &x, Real &tol) {
78 const Real one(1);
79 if (!isHessApplied_) {
80 pwa_->set(x); pwa_->axpy(-one,*x_);
81 obj_->hessVec(*Hx_,*pwa_,*x_,tol); nhess_++;
82 isHessApplied_ = true;
83 }
84 g.set(*Hx_);
85 g.plus(*g_);
86 }
87 void hessVec(Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol) {
88 obj_->hessVec(hv,v,*x_,tol); nhess_++;
89 }
90 int numHessVec(bool reset = true) {
91 int nhess = nhess_;
92 if (reset) nhess_ = 0;
93 return nhess;
94 }
95 void setData(const Vector<Real> &x, const Vector<Real> &g) {
96 x_->set(x);
97 g_->set(g);
98 }
99 };
100
101 void initialize(Vector<Real> &x,
102 const Vector<Real> &g,
103 Objective<Real> &sobj,
104 Objective<Real> &nobj,
105 Vector<Real> &dg,
106 Vector<Real> &px,
107 std::ostream &outStream = std::cout);
108
109public:
110
111 InexactNewtonAlgorithm(ParameterList &list);
112
113 using TypeP::Algorithm<Real>::run;
114
115 void run( Vector<Real> &x,
116 const Vector<Real> &g,
117 Objective<Real> &sobj,
118 Objective<Real> &nobj,
119 std::ostream &outStream = std::cout) override;
120
121 void writeHeader( std::ostream& os ) const override;
122
123 void writeName( std::ostream& os ) const override;
124
125 void writeOutput( std::ostream &os, bool write_header = false ) const override;
126
127}; // class ROL::TypeP::InexactNewtonAlgorithm
128
129} // namespace TypeP
130} // namespace ROL
131
133
134#endif
Provides the interface to evaluate objective functions.
Provides an interface to run optimization algorithms to minimize composite optimization problems f+ph...
void pgstep(Vector< Real > &pgiter, Vector< Real > &pgstep, Objective< Real > &nobj, const Vector< Real > &x, const Vector< Real > &dg, Real t, Real &tol) const
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
void setData(const Vector< Real > &x, const Vector< Real > &g)
Real value(const Vector< Real > &x, Real &tol)
Compute value.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
NewtonObj(const Ptr< Objective< Real > > &obj, const Vector< Real > &x, const Vector< Real > &g)
void update(const Vector< Real > &x, UpdateType type, int iter)
Update objective function.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Provides an interface to run the inexact proximal Newton algorithm.
Real c1_
Sufficient Decrease Parameter (default: 1e-4)
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout) override
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, Vector< Real > &dg, Vector< Real > &px, std::ostream &outStream=std::cout)
Real sigma2_
Upper safeguard for quadratic line search (default: 0.9)
Real sigma1_
Lower safeguard for quadratic line search (default: 0.1)
void writeName(std::ostream &os) const override
Print step name.
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
int maxit_
Maximum number of line search steps (default: 20)
Real rhodec_
Backtracking rate (default: 0.5)
void writeHeader(std::ostream &os) const override
Print iterate header.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual void plus(const Vector &x)=0
Compute , where .