ROL
ROL_ObjectiveFromBoundConstraint.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_OBJECTIVE_FROM_BOUND_CONSTRAINT_H
36 #define ROL_OBJECTIVE_FROM_BOUND_CONSTRAINT_H
37 
38 #include "ROL_Objective.hpp"
39 #include "ROL_BoundConstraint.hpp"
40 
41 namespace ROL {
42 
43 
49 template <class Real>
51 
52  typedef Vector<Real> V;
53 
54 private:
55  Teuchos::RCP<V> lo_;
56  Teuchos::RCP<V> up_;
57 
58  Teuchos::RCP<V> x_minus_lo_;
59  Teuchos::RCP<V> up_minus_x_;
60 
61  class LogarithmLower : public Elementwise::BinaryFunction<Real> {
62  public:
63 
64  Real apply( const Real &x, const Real &y ) const {
65  return y>ROL_NINF ? std::log(x-y) : 0.0;
66  }
67  };
68 
69  class LogarithmUpper : public Elementwise::BinaryFunction<Real> {
70  public:
71 
72  Real apply( const Real &x, const Real &y ) const {
73  return y<ROL_INF ? std::log(y-x) : 0.0;
74  }
75  };
76 
77  class ReciprocalLower : public Elementwise::BinaryFunction<Real> {
78  public:
79 
80  Real apply( const Real &x, const Real &y ) const {
81  return y>ROL_NINF ? 1.0/(x-y) : 0.0;
82  }
83  };
84 
85  class ReciprocalUpper : public Elementwise::BinaryFunction<Real> {
86  public:
87 
88  Real apply( const Real &x, const Real &y ) const {
89  return y<ROL_INF ? 1./(y-x) : 0.0;
90  }
91  };
92 
93 
94  Elementwise::Multiply<Real> mult_;
95  Elementwise::ReductionSum<Real> sum_;
96 
97 
98 
99 public:
100 
102  lo_( bc.getLowerVectorRCP() ),
103  up_( bc.getUpperVectorRCP() ) {
104 
105  x_minus_lo_ = lo_->clone();
106  up_minus_x_ = up_->clone();
107 
108  }
109 
110  Real value( const Vector<Real> &x, Real &tol ) {
111 
112  x_minus_lo_->set(x);
113  up_minus_x_->set(x);
114 
115  LogarithmLower logl;
116  LogarithmUpper logu;
117 
118  x_minus_lo_->applyBinary(logl,*lo_);
119  up_minus_x_->applyBinary(logu,*up_);
120 
121  Real result = -(x_minus_lo_->reduce(sum_));
122  result -= (up_minus_x_->reduce(sum_));
123 
124  return result;
125 
126  }
127 
128  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
129 
130  x_minus_lo_->set(x);
131  up_minus_x_->set(x);
132 
133  ReciprocalLower recipl;
134  ReciprocalUpper recipu;
135 
136  x_minus_lo_->applyBinary(recipl, *lo_);
137  up_minus_x_->applyBinary(recipu, *up_);
138 
139  g.set(*up_minus_x_);
140  g.axpy(-1.0,*x_minus_lo_);
141 
142  }
143 
144  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
145 
146  x_minus_lo_->set(x);
147  up_minus_x_->set(x);
148 
149  ReciprocalLower recipl;
150  ReciprocalUpper recipu;
151 
152  x_minus_lo_->applyBinary(recipl, *lo_);
153  up_minus_x_->applyBinary(recipu, *up_);
154 
155  x_minus_lo_->applyBinary(mult_,*x_minus_lo_);
156  up_minus_x_->applyBinary(mult_,*up_minus_x_);
157 
158 
159  hv.set(*x_minus_lo_);
160  hv.plus(*up_minus_x_);
161  hv.applyBinary(mult_,v);
162 
163  }
164 
165 
166 }; // class ObjectiveFromBoundConstraint
167 
168 }
169 
170 
171 #endif // ROL_OBJECTIVE_FROM_BOUND_CONSTRAINT_H
172 
Provides the interface to evaluate objective functions.
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:143
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
Definition: ROL_Vector.hpp:222
ObjectiveFromBoundConstraint(const BoundConstraint< Real > &bc)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Provides the interface to apply upper and lower bound constraints.
static const double ROL_INF
Definition: ROL_Types.hpp:128
Real value(const Vector< Real > &x, Real &tol)
Compute value.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
static const double ROL_NINF
Definition: ROL_Types.hpp:129
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Create a logarithmic penalty objective from upper and lower bound vectors.