ROL
ROL_SROMGenerator.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_SROMGENERATOR_HPP
45 #define ROL_SROMGENERATOR_HPP
46 
47 #include "ROL_SampleGenerator.hpp"
48 
49 #include "ROL_Objective.hpp"
50 #include "ROL_BoundConstraint.hpp"
52 
53 #include "ROL_Algorithm.hpp"
54 
55 #include "ROL_MomentObjective.hpp"
58 #include "ROL_SROMVector.hpp"
59 
60 #include "ROL_StdVector.hpp"
61 
62 namespace ROL {
63 
64 template<class Real>
65 class SROMGenerator : public SampleGenerator<Real> {
66 private:
67  Teuchos::RCP<Objective<Real> > obj_;
68  Teuchos::RCP<BoundConstraint<Real> > bnd_;
69  Teuchos::RCP<EqualityConstraint<Real> > con_;
70 
71  Teuchos::RCP<Algorithm<Real> > algo_;
72 
73  Teuchos::ParameterList parlist_;
74 
75  const size_t dimension_;
76  size_t nSamp_;
77  const size_t numNewSamps_;
78  const bool adaptive_;
79 
80  void buildOptimizer(const bool useAugLag = true) {
81  if ( !useAugLag ) {
82  parlist_.sublist("Step").sublist("Moreau-Yosida Penalty").set("Initial Penalty Parameter",10.);
83  parlist_.sublist("Step").sublist("Moreau-Yosida Penalty").set("Penalty Parameter Growth Factor",1.);
84  parlist_.sublist("Step").sublist("Moreau-Yosida Penalty").sublist("Subproblem").set("Optimality Tolerance",1.e-8);
85  parlist_.sublist("Step").sublist("Moreau-Yosida Penalty").sublist("Subproblem").set("Feasibility Tolerance",1.e-8);
86  parlist_.sublist("Step").sublist("Moreau-Yosida Penalty").sublist("Subproblem").set("Iteration Limit",1000);
87  parlist_.sublist("Step").sublist("Moreau-Yosida Penalty").sublist("Subproblem").set("Print History",false);
88 
89  parlist_.sublist("Status Test").set("Gradient Tolerance", 1.e-4);
90  parlist_.sublist("Status Test").set("Constraint Tolerance", 1.e-6);
91  parlist_.sublist("Status Test").set("Iteration Limit", 15);
92 
93  algo_ = Teuchos::rcp(new Algorithm<Real>("Moreau-Yosida Penalty",parlist_,false));
94  }
95  else {
96  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Initial Penalty Parameter",1.e1);
97  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Penalty Parameter Growth Factor",1.e2);
98  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Optimality Tolerance Update Exponent",1.);
99  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Feasibility Tolerance Update Exponent",0.1);
100  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Optimality Tolerance Decrease Exponent",1.);
101  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Feasibility Tolerance Decrease Exponent",0.9);
102  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Initial Optimality Tolerance",1.);
103  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Initial Feasibility Tolerance",1.);
104  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Minimum Penalty Parameter Reciprocal",0.1);
105  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Print Intermediate Optimization History",false);
106  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Subproblem Iteration Limit",1000);
107  parlist_.sublist("Step").sublist("Augmented Lagrangian").set("Subproblem Step Type","Trust Region");
108 
109  parlist_.sublist("Status Test").set("Gradient Tolerance", 1.e-4);
110  parlist_.sublist("Status Test").set("Constraint Tolerance", 1.e-6);
111  parlist_.sublist("Status Test").set("Iteration Limit", 15);
112 
113  algo_ = Teuchos::rcp(new Algorithm<Real>("Augmented Lagrangian",parlist_,false));
114  }
115  }
116 
117  void splitSamples(const std::vector<std::vector<Real> > &allPoints,
118  const std::vector<Real> &allWeights) {
119  // Separate samples/weights across batches
120  size_t rank = (size_t)SampleGenerator<Real>::batchID();
121  size_t nProc = (size_t)SampleGenerator<Real>::numBatches();
122  size_t frac = nSamp_ / nProc;
123  size_t rem = nSamp_ % nProc;
124  size_t N = frac + ((rank < rem) ? 1 : 0);
125  size_t index = 0;
126 
127  std::vector<std::vector<Real> > pts;
128  std::vector<Real> wts;
129  for (size_t i = 0; i < N; i++) {
130  index = i*nProc + rank;
131  pts.push_back(allPoints[index]);
132  wts.push_back(allWeights[index]);
133  }
136  }
137 
138  void pruneSamples(std::vector<std::vector<Real> > &pts, std::vector<Real> &wts,
139  const SROMVector<Real> &x) {
140  // Remove points with zero weight
141  for (size_t i = 0; i < nSamp_; i++) {
142  if ( x.getWeight(i) > ROL_EPSILON ) {
143  pts.push_back(*(x.getPoint(i)));
144  wts.push_back(x.getWeight(i));
145  }
146  }
147  nSamp_ = wts.size();
148  }
149 
150 public:
151  SROMGenerator(Teuchos::RCP<BatchManager<Real> > &bman,
152  Teuchos::RCP<Objective<Real> > &obj,
153  const size_t dimension,
154  const size_t nSamp = 10,
155  const bool adaptive = false,
156  const size_t numNewSamps = 0 )
157  : SampleGenerator<Real>(bman), obj_(obj), dimension_(dimension),
158  nSamp_(nSamp), numNewSamps_(numNewSamps), adaptive_(adaptive) {
159  // Build ROL algorithm and solve SROM optimization problem
160  SROMVector<Real> x(Teuchos::rcp(new std::vector<Real>(dimension_*nSamp_,0.)),
161  Teuchos::rcp(new std::vector<Real>(nSamp_,0.)));
162  StdVector<Real> l(Teuchos::rcp(new std::vector<Real>(1,0.)));
163  bnd_ = Teuchos::rcp(new SROMBoundConstraint<Real>(dimension_));
164  con_ = Teuchos::rcp(new SROMEqualityConstraint<Real>);
165  bool useAugLag = false;
166  buildOptimizer(useAugLag);
167  algo_->run(x,l,*obj_,*con_,*bnd_,!SampleGenerator<Real>::batchID());
168  // Prune samples with zero weight and set samples/weights
169  std::vector<std::vector<Real> > allPoints;
170  std::vector<Real> allWeights;
171  pruneSamples(allPoints,allWeights,x);
172  splitSamples(allPoints,allWeights);
173  }
174 
175  SROMGenerator(Teuchos::RCP<BatchManager<Real> > &bman,
176  Teuchos::RCP<Objective<Real> > &obj,
177  Teuchos::RCP<BoundConstraint<Real> > &bnd,
178  const size_t dimension,
179  const size_t nSamp = 10,
180  const bool adaptive = false,
181  const size_t numNewSamps = 0 )
182  : SampleGenerator<Real>(bman), obj_(obj), bnd_(bnd), dimension_(dimension),
183  nSamp_(nSamp), numNewSamps_(numNewSamps), adaptive_(adaptive) {
184  // Build ROL algorithm and solve SROM optimization problem
185  SROMVector<Real> x(Teuchos::rcp(new std::vector<Real>(dimension_*nSamp_,0.)),
186  Teuchos::rcp(new std::vector<Real>(nSamp_,0.)));
187  StdVector<Real> l(Teuchos::rcp(new std::vector<Real>(1,0.)));
188  con_ = Teuchos::rcp(new SROMEqualityConstraint<Real>);
189  bool useAugLag = false;
190  buildOptimizer(useAugLag);
191  algo_->run(x,l,*obj_,*con_,*bnd_,!SampleGenerator<Real>::batchID());
192  // Prune samples with zero weight and set samples/weights
193  std::vector<std::vector<Real> > allPoints;
194  std::vector<Real> allWeights;
195  pruneSamples(allPoints,allWeights,x);
196  splitSamples(allPoints,allWeights);
197  }
198 
199  SROMGenerator(Teuchos::RCP<BatchManager<Real> > &bman,
200  Teuchos::RCP<Objective<Real> > &obj,
201  Teuchos::RCP<BoundConstraint<Real> > &bnd,
202  Teuchos::RCP<Vector<Real> > &x,
203  const size_t dimension,
204  const size_t nSamp = 10,
205  const bool adaptive = false,
206  const size_t numNewSamps = 0 )
207  : SampleGenerator<Real>(bman), obj_(obj), bnd_(bnd), dimension_(dimension),
208  nSamp_(nSamp), numNewSamps_(numNewSamps), adaptive_(adaptive) {
209  // Build ROL algorithm and solve SROM optimization problem
210  StdVector<Real> l(Teuchos::rcp(new std::vector<Real>(1,0.)));
211  con_ = Teuchos::rcp(new SROMEqualityConstraint<Real>);
212  bool useAugLag = true;
213  buildOptimizer(useAugLag);
214  algo_->run(*x,l,*obj_,*con_,*bnd_,!SampleGenerator<Real>::batchID());
215  // Prune samples with zero weight and set samples/weights
216  const SROMVector<Real> &ex = Teuchos::dyn_cast<const SROMVector<Real> >(*x);
217  std::vector<std::vector<Real> > allPoints;
218  std::vector<Real> allWeights;
219  pruneSamples(allPoints,allWeights,ex);
220  splitSamples(allPoints,allWeights);
221  }
222 
223  void refine(void) {}
224 };
225 
226 }
227 
228 #endif
Provides the interface to evaluate objective functions.
Teuchos::RCP< const std::vector< Element > > getPoint(const size_t i) const
const Element getWeight(const size_t i) const
void splitSamples(const std::vector< std::vector< Real > > &allPoints, const std::vector< Real > &allWeights)
Teuchos::RCP< EqualityConstraint< Real > > con_
Contains definitions for std::vector bound constraints.
SROMGenerator(Teuchos::RCP< BatchManager< Real > > &bman, Teuchos::RCP< Objective< Real > > &obj, Teuchos::RCP< BoundConstraint< Real > > &bnd, Teuchos::RCP< Vector< Real > > &x, const size_t dimension, const size_t nSamp=10, const bool adaptive=false, const size_t numNewSamps=0)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Provides the std::vector implementation of the ROL::Vector interface.
void pruneSamples(std::vector< std::vector< Real > > &pts, std::vector< Real > &wts, const SROMVector< Real > &x)
SROMGenerator(Teuchos::RCP< BatchManager< Real > > &bman, Teuchos::RCP< Objective< Real > > &obj, const size_t dimension, const size_t nSamp=10, const bool adaptive=false, const size_t numNewSamps=0)
Provides an interface to run optimization algorithms.
Teuchos::ParameterList parlist_
Provides the std::vector implementation of the ROL::Vector interface.
Provides the interface to apply upper and lower bound constraints.
Teuchos::RCP< Objective< Real > > obj_
Teuchos::RCP< Algorithm< Real > > algo_
SROMGenerator(Teuchos::RCP< BatchManager< Real > > &bman, Teuchos::RCP< Objective< Real > > &obj, Teuchos::RCP< BoundConstraint< Real > > &bnd, const size_t dimension, const size_t nSamp=10, const bool adaptive=false, const size_t numNewSamps=0)
void setPoints(std::vector< std::vector< Real > > &p)
Teuchos::RCP< BoundConstraint< Real > > bnd_
void buildOptimizer(const bool useAugLag=true)
void setWeights(std::vector< Real > &w)
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:118