ROL
ROL_LogBarrierObjective.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_LOG_BARRIER_OBJECTIVE_H
11 #define ROL_LOG_BARRIER_OBJECTIVE_H
12 
13 #include "ROL_Objective.hpp"
14 
20 namespace ROL {
21 
22 template <class Real>
23 class LogBarrierObjective : public Objective<Real> {
24 public:
25 
26 
27 
28  /* \brief Objective value J(x) = \f$-\sum_i \log(x_i) \f$ */
29  Real value( const Vector<Real> &x, Real &tol ) {
30 
31  ROL::Ptr<Vector<Real> > logx = x.clone();
32  logx->set(x);
33 
34  Elementwise::Logarithm<Real> log;
35 
36  logx->applyUnary(log);
37 
38  Elementwise::ReductionSum<Real> sum;
39 
40  Real result = -(logx->reduce(sum));
41 
42  return result;
43  }
44 
45  /* \brief gradient g_i = \f$ 1/x_i \f$ */
46  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
47 
48  g.set(x);
49 
50  Elementwise::Reciprocal<Real> reciprocal;
51 
52  g.applyUnary(reciprocal);
53  g.scale(-1.0);
54  }
55 
56  Real dirDeriv( const Vector<Real> &x, const Vector<Real> &d, Real &tol ) {
57 
58  ROL::Ptr<Vector<Real> > dbyx = d.clone();
59  dbyx->set(x);
60 
61  struct Division : public Elementwise::BinaryFunction<Real> {
62  Real apply( const Real &xc, const Real &dc ) const {
63  return dc/xc;
64  }
65  } division;
66 
67  dbyx->applyBinary( division, d );
68 
69  Elementwise::ReductionSum<Real> sum;
70 
71  return -dbyx->reduce(sum);
72  }
73 
74  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
75  hv.set(v);
76 
77  struct HessianApply : public Elementwise::BinaryFunction<Real> {
78  Real apply( const Real &vc, const Real &xc ) const {
79  return vc/(xc*xc);
80  }
81  } hessian;
82 
83  hv.applyBinary(hessian,x);
84 
85  }
86 
87 };
88 
89 } // namespace ROL
90 
91 #endif // ROL_LOG_BARRIER_OBJECTIVE_H
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Provides the interface to evaluate objective functions.
virtual void scale(const Real alpha)=0
Compute where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
Definition: ROL_Vector.hpp:214
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Real dirDeriv(const Vector< Real > &x, const Vector< Real > &d, Real &tol)
Compute directional derivative.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &f)
Definition: ROL_Vector.hpp:208
ROL::DiagonalOperator apply
Log barrier objective for interior point methods.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175