54 #include "Teuchos_oblackholestream.hpp"
55 #include "Teuchos_GlobalMPISession.hpp"
65 template <
class Real,
class Element=Real>
68 template <
class Real,
class Element=Real>
75 template <
class Real,
class Element>
80 mutable Teuchos::RCP<OptDualStdVector<Real> >
dual_vec_;
88 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
91 (*std_vec_)[i] += (*xvalptr)[i];
95 void scale(
const Real alpha ) {
98 (*std_vec_)[i] *= alpha;
105 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
108 val += (*std_vec_)[i]*(*xvalptr)[i];
115 val = std::sqrt(
dot(*
this) );
119 Teuchos::RCP<ROL::Vector<Real> >
clone()
const {
120 return Teuchos::rcp(
new OptStdVector( Teuchos::rcp(
new std::vector<Element>(
std_vec_->size()) ) ) );
123 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
127 Teuchos::RCP<ROL::Vector<Real> >
basis(
const int i )
const {
128 Teuchos::RCP<OptStdVector> e = Teuchos::rcp(
new OptStdVector( Teuchos::rcp(
new std::vector<Element>(
std_vec_->size(), 0.0)) ) );
129 (const_cast <std::vector<Element> &> (*e->getVector()))[i]= 1.0;
144 template <
class Real,
class Element>
157 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
160 (*std_vec_)[i] += (*xvalptr)[i];
167 (*std_vec_)[i] *= alpha;
174 Teuchos::RCP<const std::vector<Element> > xvalptr = ex.
getVector();
177 val += (*std_vec_)[i]*(*xvalptr)[i];
184 val = std::sqrt(
dot(*
this) );
188 Teuchos::RCP<ROL::Vector<Real> >
clone()
const {
192 Teuchos::RCP<const std::vector<Element> >
getVector()
const {
196 Teuchos::RCP<ROL::Vector<Real> >
basis(
const int i )
const {
197 Teuchos::RCP<OptDualStdVector> e = Teuchos::rcp(
new OptDualStdVector( Teuchos::rcp(
new std::vector<Element>(
std_vec_->size(), 0.0)) ) );
198 (const_cast <std::vector<Element> &> (*e->getVector()))[i]= 1.0;
219 int main(
int argc,
char *argv[]) {
221 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
224 int iprint = argc - 1;
225 Teuchos::RCP<std::ostream> outStream;
226 Teuchos::oblackholestream bhs;
228 outStream = Teuchos::rcp(&std::cout,
false);
230 outStream = Teuchos::rcp(&bhs,
false);
241 Teuchos::ParameterList parlist;
243 parlist.
set(
"Descent Type",
"Quasi-Newton Method");
244 parlist.set(
"Secant Type",
"Limited-memory BFGS");
245 parlist.set(
"Linesearch Type",
"Cubic Interpolation");
246 parlist.set(
"Linesearch Curvature Condition",
"Wolfe");
248 parlist.set(
"Maximum Number of Function Evaluations", 20);
249 parlist.set(
"Sufficient Decrease Parameter", 1.e-4);
250 parlist.set(
"Curvature Conditions Parameter", 0.9);
251 parlist.set(
"Backtracking Rate", 0.5);
252 parlist.set(
"Initial Linesearch Parameter", 1.0);
253 parlist.set(
"User Defined Linesearch Parameter",
false);
255 parlist.set(
"Absolute Krylov Tolerance", 1.e-4);
256 parlist.set(
"Relative Krylov Tolerance", 1.e-2);
257 parlist.set(
"Maximum Number of Krylov Iterations", 10);
259 parlist.set(
"Trust-Region Subproblem Solver Type",
"Truncated CG");
260 parlist.set(
"Use Secant Hessian-Times-A-Vector",
true);
276 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
277 Teuchos::RCP<std::vector<RealT> > g_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
279 for (
int i=0; i<dim/2; i++) {
280 (*x_rcp)[2*i] = -1.2;
281 (*x_rcp)[2*i+1] = 1.0;
290 Teuchos::RCP<std::vector<RealT> > aa_rcp = Teuchos::rcp(
new std::vector<RealT> (1, 1.0) );
292 Teuchos::RCP<std::vector<RealT> > bb_rcp = Teuchos::rcp(
new std::vector<RealT> (1, 2.0) );
294 Teuchos::RCP<std::vector<RealT> > cc_rcp = Teuchos::rcp(
new std::vector<RealT> (1, 3.0) );
300 std::vector<std::string> output = algo.
run(x,g, obj,
false);
301 for (
unsigned i = 0; i < output.size(); i++ ) {
302 std::cout << output[i];
306 Teuchos::RCP<std::vector<RealT> > xtrue_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 1.0) );
313 *outStream << std::scientific <<
"\n Absolute Error: " << abserr;
314 *outStream << std::scientific <<
"\n Relative Error: " << relerr <<
"\n";
319 catch (std::logic_error err) {
320 *outStream << err.what() <<
"\n";
325 std::cout <<
"End Result: TEST FAILED\n";
327 std::cout <<
"End Result: TEST PASSED\n";
Teuchos::RCP< std::vector< Element > > std_vec_
Teuchos::RCP< OptDualStdVector< Real > > dual_vec_
void scale(const Real alpha)
Compute where .
OptStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec)
Teuchos::RCP< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual std::vector< Real > checkVector(const Vector< Real > &x, const Vector< Real > &y, const bool printToStream=true, std::ostream &outStream=std::cout) const
Verify vector-space methods.
int main(int argc, char *argv[])
Teuchos::RCP< OptStdVector< Real > > dual_vec_
Teuchos::RCP< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Contains definitions for Rosenbrock's function.
Teuchos::RCP< const std::vector< Element > > getVector() const
Defines the linear algebra or vector space interface.
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
OptDualStdVector(const Teuchos::RCP< std::vector< Element > > &std_vec)
Teuchos::RCP< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
void scale(const Real alpha)
Compute where .
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
Real dot(const ROL::Vector< Real > &x) const
Compute where .
int dimension() const
Return dimension of the vector space.
Real norm() const
Returns where .
Provides an interface to check status of optimization algorithms.
Teuchos::RCP< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
int dimension() const
Return dimension of the vector space.
Real dot(const ROL::Vector< Real > &x) const
Compute where .
virtual void set(const Vector &x)
Set where .
Teuchos::RCP< const std::vector< Element > > getVector() const
Teuchos::RCP< std::vector< Element > > std_vec_
void plus(const ROL::Vector< Real > &x)
Compute , where .
void plus(const ROL::Vector< Real > &x)
Compute , where .
Real norm() const
Returns where .
Provides the interface to compute optimization steps with trust regions.
static const double ROL_EPSILON
Platform-dependent machine epsilon.