44 #ifndef ROL_PRIMALDUALRISK_H
45 #define ROL_PRIMALDUALRISK_H
66 Ptr<PD_RandVarFunctional<Real>>
rvf_;
105 ParameterList &parlist)
109 maxit_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Iteration Limit",100);
110 print_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Print Subproblem Solve History",
false);
111 gtolmin_ = parlist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
112 ctolmin_ = parlist.sublist(
"Status Test").get(
"Constraint Tolerance", 1e-8);
113 ltolmin_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance",1e-6);
114 gtolmin_ = (gtolmin_ <= static_cast<Real>(0) ? std::sqrt(ROL_EPSILON<Real>()) :
gtolmin_);
115 ctolmin_ = (ctolmin_ <= static_cast<Real>(0) ? std::sqrt(ROL_EPSILON<Real>()) :
ctolmin_);
116 ltolmin_ = (ltolmin_ <= static_cast<Real>(0) ? 1e2*std::sqrt(ROL_EPSILON<Real>()) :
ltolmin_);
118 gtol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Gradient Tolerance", 1e-4);
119 ctol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Constraint Tolerance", 1e-4);
120 ltol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Dual Tolerance", 1e-2);
121 ltolupdate_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance Update Scale", 1e-1);
122 tolupdate0_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Solver Tolerance Decrease Scale", 9e-1);
123 tolupdate1_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Solver Tolerance Update Scale", 1e-1);
124 lalpha_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance Decrease Exponent", 1e-1);
125 lbeta_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance Update Exponent", 9e-1);
130 penaltyParam_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Penalty Parameter", 10.0);
131 maxPen_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Maximum Penalty Parameter", -1.0);
132 update_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Penalty Update Scale", 10.0);
133 maxPen_ = (maxPen_ <= static_cast<Real>(0) ? ROL_INF<Real>() :
maxPen_);
136 freq_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Update Frequency", 0);
138 ParameterList olist; olist.sublist(
"SOL") = parlist.sublist(
"SOL").sublist(
"Objective");
139 std::string type = olist.sublist(
"SOL").get<std::string>(
"Type");
140 if (type ==
"Risk Averse") {
141 name_ = olist.sublist(
"SOL").sublist(
"Risk Measure").get<std::string>(
"Name");
143 else if (type ==
"Probability") {
144 name_ = olist.sublist(
"SOL").sublist(
"Probability"). get<std::string>(
"Name");
147 std::stringstream message;
148 message <<
">>> " << type <<
" is not implemented!";
151 Ptr<ParameterList> parlistptr = makePtrFromRef<ParameterList>(olist);
152 if (
name_ ==
"CVaR") {
153 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
154 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"CVaR");
155 Real alpha = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"CVaR").get(
"Convex Combination Parameter", 1.0);
156 Real beta = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"CVaR").get(
"Confidence Level", 0.9);
157 rvf_ = makePtr<PD_CVaR<Real>>(alpha, beta);
159 else if (
name_ ==
"Mean Plus Semi-Deviation") {
160 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
161 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"Mean Plus Semi-Deviation");
162 Real coeff = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation").get(
"Coefficient", 0.5);
163 rvf_ = makePtr<PD_MeanSemiDeviation<Real>>(coeff);
165 else if (
name_ ==
"Mean Plus Semi-Deviation From Target") {
166 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
167 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"Mean Plus Semi-Deviation From Target");
168 Real coeff = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation From Target").get(
"Coefficient", 0.5);
169 Real target = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation From Target").get(
"Target", 1.0);
170 rvf_ = makePtr<PD_MeanSemiDeviationFromTarget<Real>>(coeff, target);
172 else if (
name_ ==
"HMCR") {
173 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
174 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"HMCR");
176 Real beta = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"HMCR").get(
"Confidence Level", 0.9);
177 rvf_ = makePtr<PD_HMCR2<Real>>(beta);
179 else if (
name_ ==
"bPOE") {
180 parlistptr->sublist(
"SOL").set(
"Type",
"Probability");
181 parlistptr->sublist(
"SOL").sublist(
"Probability").set(
"Name",
"bPOE");
182 Real thresh = olist.sublist(
"SOL").sublist(
"Probability").sublist(
"bPOE").get(
"Threshold", 1.0);
183 rvf_ = makePtr<PD_BPOE<Real>>(thresh);
186 std::stringstream message;
187 message <<
">>> " <<
name_ <<
" is not implemented!";
190 pd_vector_ = makePtr<RiskVector<Real>>(parlistptr,
191 input_->getPrimalOptimizationVector());
196 pd_bound_ = makePtr<RiskBoundConstraint<Real>>(parlistptr,
197 input_->getBoundConstraint());
200 if (
input_->getConstraint() != nullPtr) {
201 pd_constraint_ = makePtr<RiskLessConstraint<Real>>(
input_->getConstraint());
204 if (
input_->getPolyhedralProjection() != nullPtr) {
209 if (pd_bound_->isActivated()) {
212 if (pd_constraint_ != nullPtr) {
213 pd_problem_->addConstraint(
"PD Constraint",pd_constraint_,
input_->getMultiplierVector());
221 void check(std::ostream &outStream = std::cout) {
225 void run(std::ostream &outStream = std::cout) {
233 Ptr<Solver<Real>> solver;
235 parlist_.sublist(
"Status Test").set(
"Gradient Tolerance",
gtol_);
236 parlist_.sublist(
"Status Test").set(
"Constraint Tolerance",
ctol_);
238 if (
print_) solver->solve(outStream);
239 else solver->solve();
243 spiter += solver->getAlgorithmState()->iter;
244 nfval_ += solver->getAlgorithmState()->nfval;
245 ngrad_ += solver->getAlgorithmState()->ngrad;
246 ncval_ += solver->getAlgorithmState()->ncval;
249 print(*solver->getAlgorithmState(),outStream);
251 if (
checkStatus(*solver->getAlgorithmState(),outStream))
break;
257 rvf_->updatePenalty(penaltyParam_);
258 theta = std::min(one/penaltyParam_,one);
271 input_->getPrimalOptimizationVector()->set(
274 if (
iter_ >= maxit_) {
275 outStream <<
"Maximum number of iterations exceeded" << std::endl;
277 outStream <<
"Primal Dual Risk required " << spiter
278 <<
" subproblem iterations" << std::endl;
283 std::ios_base::fmtflags flags = outStream.flags();
284 outStream << std::scientific << std::setprecision(6);
285 outStream << std::endl <<
"Primal Dual Risk Minimization using "
286 <<
name_ << std::endl <<
" "
287 << std::setw(8) << std::left <<
"iter"
288 << std::setw(15) << std::left <<
"value";
290 outStream << std::setw(15) << std::left <<
"cnorm";
292 outStream << std::setw(15) << std::left <<
"gnorm"
293 << std::setw(15) << std::left <<
"lnorm"
294 << std::setw(15) << std::left <<
"penalty";
296 outStream << std::setw(15) << std::left <<
"ctol";
298 outStream << std::setw(15) << std::left <<
"gtol"
299 << std::setw(15) << std::left <<
"ltol"
300 << std::setw(10) << std::left <<
"nfval"
301 << std::setw(10) << std::left <<
"ngrad";
303 outStream << std::setw(10) << std::left <<
"ncval";
305 outStream << std::setw(10) << std::left <<
"subiter"
306 << std::setw(8) << std::left <<
"success"
308 outStream.setf(flags);
312 std::ios_base::fmtflags flags = outStream.flags();
313 outStream << std::scientific << std::setprecision(6);
315 << std::setw(8) << std::left <<
iter_+1
316 << std::setw(15) << std::left << state.
value;
318 outStream << std::setw(15) << std::left << state.
cnorm;
320 outStream << std::setw(15) << std::left << state.
gnorm
321 << std::setw(15) << std::left <<
lnorm_
324 outStream << std::setw(15) << std::left <<
ctol_;
326 outStream << std::setw(15) << std::left <<
gtol_
327 << std::setw(15) << std::left <<
ltol_
328 << std::setw(10) << std::left <<
nfval_
329 << std::setw(10) << std::left <<
ngrad_;
331 outStream << std::setw(10) << std::left <<
ncval_;
333 outStream << std::setw(10) << std::left << state.
iter
336 outStream.setf(flags);
349 outStream <<
"Solver tolerance met"
350 <<
" and the difference in the multipliers was less than "
357 outStream <<
"Solver tolerance met"
358 <<
" and the difference in the multipliers was less than "
Ptr< PD_RandVarFunctional< Real > > rvf_
const Ptr< Problem< Real > > input_
Ptr< Vector< Real > > pd_vector_
Ptr< Constraint< Real > > pd_linear_constraint_
void printHeader(std::ostream &outStream) const
Contains definitions of custom data types in ROL.
void run(std::ostream &outStream=std::cout)
void print(const AlgorithmState< Real > &state, std::ostream &outStream) const
PrimalDualRisk(const Ptr< Problem< Real >> &input, const Ptr< SampleGenerator< Real >> &sampler, ParameterList &parlist)
State for algorithm class. Will be used for restarts.
bool checkStatus(const AlgorithmState< Real > &state, std::ostream &outStream) const
Ptr< Problem< Real > > pd_problem_
Ptr< Constraint< Real > > pd_constraint_
const Ptr< SampleGenerator< Real > > sampler_
Ptr< StochasticObjective< Real > > pd_objective_
void check(std::ostream &outStream=std::cout)
Ptr< BoundConstraint< Real > > pd_bound_