ROL
ROL_LogBarrierObjective.hpp
Go to the documentation of this file.
1 // Redistribution and use in source and binary forms, with or without
2 // modification, are permitted provided that the following conditions are
3 // met:
4 //
5 // 1. Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 //
8 // 2. Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 //
12 // 3. Neither the name of the Corporation nor the names of the
13 // contributors may be used to endorse or promote products derived from
14 // this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
17 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
20 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // Questions? Contact lead developers:
29 // Drew Kouri (dpkouri@sandia.gov) and
30 // Denis Ridzal (dridzal@sandia.gov)
31 //
32 // ************************************************************************
33 // @HEADER
34 
35 #ifndef ROL_LOG_BARRIER_OBJECTIVE_H
36 #define ROL_LOG_BARRIER_OBJECTIVE_H
37 
38 #include "ROL_Objective.hpp"
39 
45 namespace ROL {
46 
47 template <class Real>
48 class LogBarrierObjective : public Objective<Real> {
49 public:
50 
51  /* \brief Objective value J(x) = \f$-\sum_i \log(x_i) \f$ */
52  Real value( const Vector<Real> &x, Real &tol ) {
53 
54  Teuchos::RCP<Vector<Real> > logx = x.clone();
55  logx->set(x);
56 
57  struct Logarithm : public Elementwise::UnaryFunction<Real> {
58  Real apply( const Real &x ) const {
59  return std::log(x);
60  }
61  } log;
62 
63  logx->applyUnary(log);
64 
65  Elementwise::ReductionSum<Real> sum;
66 
67  Real result = -(logx->reduce(sum));
68 
69  return result;
70  }
71 
72  /* \brief gradient g_i = \f$ 1/x_i \f$ */
73  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
74 
75  g.set(x);
76 
77  struct Reciprocal : public Elementwise::UnaryFunction<Real> {
78  Real apply( const Real &x ) const {
79  return 1.0/x;
80  }
81  } reciprocal;
82 
83  g.applyUnary(reciprocal);
84  g.scale(-1.0);
85  }
86 
87  Real dirDeriv( const Vector<Real> &x, const Vector<Real> &d, Real &tol ) {
88 
89  Teuchos::RCP<Vector<Real> > dbyx = d.clone();
90  dbyx->set(x);
91 
92  struct Division : public Elementwise::BinaryFunction<Real> {
93  Real apply( const Real &x, const Real &d ) const {
94  return d/x;
95  }
96  } division;
97 
98  dbyx->applyBinary( division, d );
99 
100  Elementwise::ReductionSum<Real> sum;
101 
102  return -dbyx->reduce(sum);
103  }
104 
105  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
106  hv.set(v);
107 
108  struct HessianApply : public Elementwise::BinaryFunction<Real> {
109  Real apply( const Real &v, const Real &x ) const {
110  return v/(x*x);
111  }
112  } hessian;
113 
114  hv.applyBinary(hessian,x);
115 
116  }
117 
118 };
119 
120 } // namespace ROL
121 
122 #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 void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
Definition: ROL_Vector.hpp:222
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
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:217
Log barrier objective for interior point methods.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196