44 #ifndef ROL_PRIMALDUALRISK_H
45 #define ROL_PRIMALDUALRISK_H
63 const Ptr<OptimizationProblem<Real>>
input_;
65 Ptr<PD_RandVarFunctional<Real>>
rvf_;
99 ParameterList &parlist)
103 maxit_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Iteration Limit",100);
104 print_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Print Subproblem Solve History",
false);
105 gtolmin_ = parlist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
106 ctolmin_ = parlist.sublist(
"Status Test").get(
"Constraint Tolerance", 1e-8);
107 ltolmin_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Dual Tolerance",1e-6);
108 gtolmin_ = (gtolmin_ <= static_cast<Real>(0) ? std::sqrt(ROL_EPSILON<Real>()) :
gtolmin_);
109 ctolmin_ = (ctolmin_ <= static_cast<Real>(0) ? std::sqrt(ROL_EPSILON<Real>()) :
ctolmin_);
110 ltolmin_ = (ltolmin_ <= static_cast<Real>(0) ? 1e2*std::sqrt(ROL_EPSILON<Real>()) :
ltolmin_);
112 gtol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Gradient Tolerance", 1e-4);
113 ctol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Constraint Tolerance", 1e-4);
114 ltol_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Dual Tolerance", 1e-2);
115 tolupdate_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Solver Tolerance Update Scale", 1e-1);
120 penaltyParam_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Initial Penalty Parameter", 10.0);
121 maxPen_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Maximum Penalty Parameter", -1.0);
122 update_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Penalty Update Scale", 10.0);
123 maxPen_ = (maxPen_ <= static_cast<Real>(0) ? ROL_INF<Real>() :
maxPen_);
126 freq_ = parlist.sublist(
"SOL").sublist(
"Primal Dual Risk").get(
"Update Frequency", 0);
128 std::string type = parlist.sublist(
"SOL").get(
"Stochastic Component Type",
"Risk Averse");
129 if (type ==
"Risk Averse") {
130 name_ = parlist.sublist(
"SOL").sublist(
"Risk Measure").get(
"Name",
"CVaR");
132 else if (type ==
"Probability") {
133 name_ = parlist.sublist(
"SOL").sublist(
"Probability").
get(
"Name",
"bPOE");
136 std::stringstream message;
137 message <<
">>> " << type <<
" is not implemented!";
140 Ptr<ParameterList> parlistptr = makePtrFromRef<ParameterList>(parlist);
141 if (
name_ ==
"CVaR") {
142 parlistptr->sublist(
"SOL").set(
"Stochastic Component Type",
"Risk Averse");
143 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"CVaR");
144 Real alpha = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"CVaR").get(
"Convex Combination Parameter", 1.0);
145 Real beta = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"CVaR").get(
"Confidence Level", 0.9);
146 rvf_ = makePtr<PD_CVaR<Real>>(alpha, beta);
148 else if (
name_ ==
"Mean Plus Semi-Deviation") {
149 parlistptr->sublist(
"SOL").set(
"Stochastic Component Type",
"Risk Averse");
150 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"Mean Plus Semi-Deviation");
151 Real coeff = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation").get(
"Coefficient", 0.5);
152 rvf_ = makePtr<PD_MeanSemiDeviation<Real>>(coeff);
154 else if (
name_ ==
"Mean Plus Semi-Deviation From Target") {
155 parlistptr->sublist(
"SOL").set(
"Stochastic Component Type",
"Risk Averse");
156 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"Mean Plus Semi-Deviation From Target");
157 Real coeff = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation From Target").get(
"Coefficient", 0.5);
158 Real target = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Semi-Deviation From Target").get(
"Target", 1.0);
159 rvf_ = makePtr<PD_MeanSemiDeviationFromTarget<Real>>(coeff, target);
161 else if (
name_ ==
"HMCR") {
162 parlistptr->sublist(
"SOL").set(
"Stochastic Component Type",
"Risk Averse");
163 parlistptr->sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",
"HMCR");
165 Real beta = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"HMCR").get(
"Confidence Level", 0.9);
166 rvf_ = makePtr<PD_HMCR2<Real>>(beta);
168 else if (
name_ ==
"bPOE") {
169 parlistptr->sublist(
"SOL").set(
"Stochastic Component Type",
"Probability");
170 parlistptr->sublist(
"SOL").sublist(
"Probability").set(
"Name",
"bPOE");
171 Real thresh = parlist.sublist(
"SOL").sublist(
"Probability").sublist(
"bPOE").get(
"Threshold", 1.0);
172 rvf_ = makePtr<PD_BPOE<Real>>(thresh);
175 std::stringstream message;
176 message <<
">>> " <<
name_ <<
" is not implemented!";
179 pd_vector_ = makePtr<RiskVector<Real>>(parlistptr,
180 input_->getSolutionVector());
185 pd_bound_ = makePtr<RiskBoundConstraint<Real>>(parlistptr,
186 input_->getBoundConstraint());
189 if (
input_->getConstraint() != nullPtr) {
190 pd_constraint_ = makePtr<RiskLessConstraint<Real>>(
input_->getConstraint());
197 input_->getMultiplierVector());
200 void check(std::ostream &outStream = std::cout) {
204 void run(std::ostream &outStream = std::cout) {
210 Ptr<OptimizationSolver<Real>> solver;
212 parlist_.sublist(
"Status Test").set(
"Gradient Tolerance",
gtol_);
213 parlist_.sublist(
"Status Test").set(
"Constraint Tolerance",
ctol_);
216 solver->solve(outStream);
224 spiter += solver->getAlgorithmState()->iter;
225 nfval_ += solver->getAlgorithmState()->nfval;
226 ngrad_ += solver->getAlgorithmState()->ngrad;
227 ncval_ += solver->getAlgorithmState()->ncval;
230 print(*solver->getAlgorithmState(),outStream);
232 if (
checkStatus(*solver->getAlgorithmState(),outStream)) {
240 rvf_->updatePenalty(penaltyParam_);
249 input_->getSolutionVector()->set(
252 if (
iter_ >= maxit_) {
253 outStream <<
"Maximum number of iterations exceeded" << std::endl;
255 outStream <<
"Primal Dual Risk required " << spiter
256 <<
" subproblem iterations" << std::endl;
261 std::ios_base::fmtflags flags = outStream.flags();
262 outStream << std::scientific << std::setprecision(6);
263 outStream << std::endl <<
"Primal Dual Risk Minimization using "
264 <<
name_ << std::endl <<
" "
265 << std::setw(8) << std::left <<
"iter"
266 << std::setw(15) << std::left <<
"value";
268 outStream << std::setw(15) << std::left <<
"cnorm";
270 outStream << std::setw(15) << std::left <<
"gnorm"
271 << std::setw(15) << std::left <<
"lnorm"
272 << std::setw(15) << std::left <<
"penalty";
274 outStream << std::setw(15) << std::left <<
"ctol";
276 outStream << std::setw(15) << std::left <<
"gtol"
277 << std::setw(15) << std::left <<
"ltol"
278 << std::setw(10) << std::left <<
"nfval"
279 << std::setw(10) << std::left <<
"ngrad";
281 outStream << std::setw(10) << std::left <<
"ncval";
283 outStream << std::setw(10) << std::left <<
"subiter"
284 << std::setw(8) << std::left <<
"success"
286 outStream.setf(flags);
290 std::ios_base::fmtflags flags = outStream.flags();
291 outStream << std::scientific << std::setprecision(6);
293 << std::setw(8) << std::left <<
iter_+1
294 << std::setw(15) << std::left << state.
value;
296 outStream << std::setw(15) << std::left << state.
cnorm;
298 outStream << std::setw(15) << std::left << state.
gnorm
299 << std::setw(15) << std::left <<
lnorm_
302 outStream << std::setw(15) << std::left <<
ctol_;
304 outStream << std::setw(15) << std::left <<
gtol_
305 << std::setw(15) << std::left <<
ltol_
306 << std::setw(10) << std::left <<
nfval_
307 << std::setw(10) << std::left <<
ngrad_;
309 outStream << std::setw(10) << std::left <<
ncval_;
311 outStream << std::setw(10) << std::left << state.
iter
314 outStream.setf(flags);
327 outStream <<
"Solver tolerance met"
328 <<
" and the difference in the multipliers was less than "
335 outStream <<
"Solver tolerance met"
336 <<
" and the difference in the multipliers was less than "
Ptr< PD_RandVarFunctional< Real > > rvf_
Ptr< Vector< Real > > pd_vector_
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
const Ptr< OptimizationProblem< Real > > input_
State for algorithm class. Will be used for restarts.
bool checkStatus(const AlgorithmState< Real > &state, std::ostream &outStream) const
Ptr< Constraint< Real > > pd_constraint_
const Ptr< SampleGenerator< Real > > sampler_
Ptr< StochasticObjective< Real > > pd_objective_
void check(std::ostream &outStream=std::cout)
Ptr< OptimizationProblem< Real > > pd_problem_
PrimalDualRisk(const Ptr< OptimizationProblem< Real >> &input, const Ptr< SampleGenerator< Real >> &sampler, ParameterList &parlist)
Ptr< BoundConstraint< Real > > pd_bound_