10 #ifndef ROL_PRIMALDUALRISK_H
11 #define ROL_PRIMALDUALRISK_H
32 Ptr<PD_RandVarFunctional<Real>>
rvf_;
71 ParameterList &parlist)
75 maxit_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Iteration Limit",100);
76 print_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Print Subproblem Solve History",
false);
77 gtolmin_ = parlist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
78 ctolmin_ = parlist.sublist(
"Status Test").get(
"Constraint Tolerance", 1e-8);
79 ltolmin_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance",1e-6);
80 gtolmin_ = (gtolmin_ <= static_cast<Real>(0) ? std::sqrt(ROL_EPSILON<Real>()) :
gtolmin_);
81 ctolmin_ = (ctolmin_ <= static_cast<Real>(0) ? std::sqrt(ROL_EPSILON<Real>()) :
ctolmin_);
82 ltolmin_ = (ltolmin_ <= static_cast<Real>(0) ? 1e2*std::sqrt(ROL_EPSILON<Real>()) :
ltolmin_);
84 gtol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Gradient Tolerance", 1e-4);
85 ctol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Constraint Tolerance", 1e-4);
86 ltol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Dual Tolerance", 1e-2);
87 ltolupdate_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance Update Scale", 1e-1);
88 tolupdate0_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Solver Tolerance Decrease Scale", 9e-1);
89 tolupdate1_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Solver Tolerance Update Scale", 1e-1);
90 lalpha_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance Decrease Exponent", 1e-1);
91 lbeta_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance Update Exponent", 9e-1);
96 penaltyParam_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Penalty Parameter", 10.0);
97 maxPen_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Maximum Penalty Parameter", -1.0);
98 update_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Penalty Update Scale", 10.0);
99 maxPen_ = (maxPen_ <= static_cast<Real>(0) ? ROL_INF<Real>() :
maxPen_);
102 freq_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Update Frequency", 0);
104 ParameterList olist; olist.sublist(
"SOL") = parlist.sublist(
"SOL").sublist(
"Objective");
105 std::string type = olist.sublist(
"SOL").get<std::string>(
"Type");
106 if (type ==
"Risk Averse") {
107 name_ = olist.sublist(
"SOL").sublist(
"Risk Measure").get<std::string>(
"Name");
109 else if (type ==
"Probability") {
110 name_ = olist.sublist(
"SOL").sublist(
"Probability"). get<std::string>(
"Name");
113 std::stringstream message;
114 message <<
">>> " << type <<
" is not implemented!";
117 Ptr<ParameterList> parlistptr = makePtrFromRef<ParameterList>(olist);
118 if (
name_ ==
"CVaR") {
119 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
120 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"CVaR");
121 Real alpha = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"CVaR").get(
"Convex Combination Parameter", 1.0);
122 Real beta = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"CVaR").get(
"Confidence Level", 0.9);
123 rvf_ = makePtr<PD_CVaR<Real>>(alpha, beta);
125 else if (
name_ ==
"Mean Plus Semi-Deviation") {
126 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
127 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"Mean Plus Semi-Deviation");
128 Real coeff = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation").get(
"Coefficient", 0.5);
129 rvf_ = makePtr<PD_MeanSemiDeviation<Real>>(coeff);
131 else if (
name_ ==
"Mean Plus Semi-Deviation From Target") {
132 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
133 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"Mean Plus Semi-Deviation From Target");
134 Real coeff = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation From Target").get(
"Coefficient", 0.5);
135 Real target = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation From Target").get(
"Target", 1.0);
136 rvf_ = makePtr<PD_MeanSemiDeviationFromTarget<Real>>(coeff, target);
138 else if (
name_ ==
"HMCR") {
139 parlistptr->sublist(
"SOL").set(
"Type",
"Risk Averse");
140 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"HMCR");
142 Real beta = olist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"HMCR").get(
"Confidence Level", 0.9);
143 rvf_ = makePtr<PD_HMCR2<Real>>(beta);
145 else if (
name_ ==
"bPOE") {
146 parlistptr->sublist(
"SOL").set(
"Type",
"Probability");
147 parlistptr->sublist(
"SOL").sublist(
"Probability").set(
"Name",
"bPOE");
148 Real thresh = olist.sublist(
"SOL").sublist(
"Probability").sublist(
"bPOE").get(
"Threshold", 1.0);
149 rvf_ = makePtr<PD_BPOE<Real>>(thresh);
152 std::stringstream message;
153 message <<
">>> " <<
name_ <<
" is not implemented!";
156 pd_vector_ = makePtr<RiskVector<Real>>(parlistptr,
157 input_->getPrimalOptimizationVector());
162 pd_bound_ = makePtr<RiskBoundConstraint<Real>>(parlistptr,
163 input_->getBoundConstraint());
166 if (
input_->getConstraint() != nullPtr) {
167 pd_constraint_ = makePtr<RiskLessConstraint<Real>>(
input_->getConstraint());
170 if (
input_->getPolyhedralProjection() != nullPtr) {
175 if (pd_bound_->isActivated()) {
178 if (pd_constraint_ != nullPtr) {
179 pd_problem_->addConstraint(
"PD Constraint",pd_constraint_,
input_->getMultiplierVector());
187 void check(std::ostream &outStream = std::cout) {
191 void run(std::ostream &outStream = std::cout) {
199 Ptr<Solver<Real>> solver;
201 parlist_.sublist(
"Status Test").set(
"Gradient Tolerance",
gtol_);
202 parlist_.sublist(
"Status Test").set(
"Constraint Tolerance",
ctol_);
204 if (
print_) solver->solve(outStream);
205 else solver->solve();
209 spiter += solver->getAlgorithmState()->iter;
210 nfval_ += solver->getAlgorithmState()->nfval;
211 ngrad_ += solver->getAlgorithmState()->ngrad;
212 ncval_ += solver->getAlgorithmState()->ncval;
215 print(*solver->getAlgorithmState(),outStream);
217 if (
checkStatus(*solver->getAlgorithmState(),outStream))
break;
223 rvf_->updatePenalty(penaltyParam_);
224 theta = std::min(one/penaltyParam_,one);
237 input_->getPrimalOptimizationVector()->set(
240 if (
iter_ >= maxit_) {
241 outStream <<
"Maximum number of iterations exceeded" << std::endl;
243 outStream <<
"Primal Dual Risk required " << spiter
244 <<
" subproblem iterations" << std::endl;
249 std::ios_base::fmtflags flags = outStream.flags();
250 outStream << std::scientific << std::setprecision(6);
251 outStream << std::endl <<
"Primal Dual Risk Minimization using "
252 <<
name_ << std::endl <<
" "
253 << std::setw(8) << std::left <<
"iter"
254 << std::setw(15) << std::left <<
"value";
256 outStream << std::setw(15) << std::left <<
"cnorm";
258 outStream << std::setw(15) << std::left <<
"gnorm"
259 << std::setw(15) << std::left <<
"lnorm"
260 << std::setw(15) << std::left <<
"penalty";
262 outStream << std::setw(15) << std::left <<
"ctol";
264 outStream << std::setw(15) << std::left <<
"gtol"
265 << std::setw(15) << std::left <<
"ltol"
266 << std::setw(10) << std::left <<
"nfval"
267 << std::setw(10) << std::left <<
"ngrad";
269 outStream << std::setw(10) << std::left <<
"ncval";
271 outStream << std::setw(10) << std::left <<
"subiter"
272 << std::setw(8) << std::left <<
"success"
274 outStream.setf(flags);
278 std::ios_base::fmtflags flags = outStream.flags();
279 outStream << std::scientific << std::setprecision(6);
281 << std::setw(8) << std::left <<
iter_+1
282 << std::setw(15) << std::left << state.
value;
284 outStream << std::setw(15) << std::left << state.
cnorm;
286 outStream << std::setw(15) << std::left << state.
gnorm
287 << std::setw(15) << std::left <<
lnorm_
290 outStream << std::setw(15) << std::left <<
ctol_;
292 outStream << std::setw(15) << std::left <<
gtol_
293 << std::setw(15) << std::left <<
ltol_
294 << std::setw(10) << std::left <<
nfval_
295 << std::setw(10) << std::left <<
ngrad_;
297 outStream << std::setw(10) << std::left <<
ncval_;
299 outStream << std::setw(10) << std::left << state.
iter
302 outStream.setf(flags);
315 outStream <<
"Solver tolerance met"
316 <<
" and the difference in the multipliers was less than "
323 outStream <<
"Solver tolerance met"
324 <<
" 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_