15#ifndef ROL_HELPERFUNCTIONS_HPP
16#define ROL_HELPERFUNCTIONS_HPP
22#include "ROL_LinearAlgebra.hpp"
23#include "ROL_LAPACK.hpp"
30 Real tol = std::sqrt(ROL_EPSILON<Real>());
33 ROL::LA::Matrix< Real> H(
dim,
dim);
35 ROL::Ptr<Vector<Real> > e = x.
clone();
36 ROL::Ptr<Vector<Real> > h = x.
dual().
clone();
38 for (
int i=0; i<
dim; i++) {
41 for (
int j=0; j<
dim; j++) {
44 H(j,i) = e->apply(*h);
56 Real tol = std::sqrt(ROL_EPSILON<Real>());
59 ROL::LA::Matrix< Real> H(
dim,
dim);
61 ROL::Ptr<Vector<Real> > ei = x.
clone();
62 ROL::Ptr<Vector<Real> > ej = x.
dual().
clone();
63 ROL::Ptr<Vector<Real> > h = x.
dual().
clone();
65 for (
int i=0; i<
dim; i++) {
68 for (
int j=0; j<
dim; j++) {
83 ROL::LA::Matrix< Real> M(
dim,
dim);
85 ROL::Ptr<Vector<Real> > ei = x.
clone();
86 ROL::Ptr<Vector<Real> > ej = x.
clone();
88 for (
int i=0; i<
dim; i++) {
90 for (
int j=0; j<
dim; j++) {
92 M(j,i) = ej->dot(*ei);
103 ROL::LAPACK<int, Real> lapack;
105 ROL::LA::Matrix< Real> mymat(mat);
110 int n = mat.numRows();
112 std::vector<Real> real(n, 0);
113 std::vector<Real> imag(n, 0);
114 std::vector<std::vector<Real> > eigenvals;
124 std::vector<Real> work(lwork, 0);
128 lapack.GEEV(jobvl, jobvr, n, &mymat(0,0), n, &real[0], &imag[0], vl, ldvl, vr, ldvr, &work[0], lwork, &info);
130 eigenvals.push_back(real);
131 eigenvals.push_back(imag);
140 const ROL::LA::Matrix< Real> & B) {
142 ROL::LAPACK<int, Real> lapack;
144 ROL::LA::Matrix< Real> myA(A);
145 ROL::LA::Matrix< Real> myB(B);
152 std::vector<Real> real(n, 0);
153 std::vector<Real> imag(n, 0);
154 std::vector<Real> beta(n, 0);
155 std::vector<std::vector<Real> > eigenvals;
165 std::vector<Real> work(lwork, 0);
169 lapack.GGEV(jobvl, jobvr, n, &myA(0,0), n, &myB(0,0), n, &real[0], &imag[0], &beta[0],
170 vl, ldvl, vr, ldvr, &work[0], lwork, &info);
172 for (
int i=0; i<n; i++) {
177 eigenvals.push_back(real);
178 eigenvals.push_back(imag);
188 ROL::LAPACK<int, Real> lapack;
190 ROL::LA::Matrix< Real> mymat(mat);
192 int n = mat.numRows();
194 std::vector<int> ipiv(n, 0);
198 std::vector<Real> work(lwork, 0);
202 lapack.GETRF(n, n, &mymat(0,0), n, &ipiv[0], &info);
203 lapack.GETRI(n, &mymat(0,0), n, &ipiv[0], &work[0], lwork, &info);
214 ROL::Ptr<Objective<Real> >
obj_;
215 ROL::Ptr<BoundConstraint<Real> >
con_;
229 bool useSecantPrecond =
false,
230 bool useSecantHessVec =
false,
234 obj_ = ROL::makePtrFromRef(obj);
235 con_ = ROL::makePtrFromRef(con);
240 obj_->update(x,flag,iter);
241 con_->update(x,flag,iter);
245 return obj_->value(x,tol);
249 obj_->gradient(g,x,tol);
253 return obj_->dirDeriv(x,d,tol);
261 obj_->hessVec( Hv, v, x, tol );
270 obj_->invHessVec(Hv,v,x,tol);
279 obj_->precond( Mv, v, x, tol );
296 if (
con_->isActivated() ) {
336 if (
con_->isActivated() ) {
377 if (
con_->isActivated() ) {
417 if (
con_->isActivated() ) {
458 if (
con_->isActivated() ) {
498 if (
con_->isActivated() ) {
547 return con_->isFeasible(v);
551 return con_->isActivated();
555 con_->computeProjectedStep(v,x);
Provides the interface to apply upper and lower bound constraints.
Provides the interface to evaluate objective functions.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void project(Vector< Real > &x)
ROL::Ptr< ROL::Vector< Real > > dualV_
Real value(const Vector< Real > &x, Real &tol)
Compute value.
void reducedPrecond(Vector< Real > &Mv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &d, const Vector< Real > &x, Real &tol)
Apply the reduced preconditioner to a vector, v. The reduced preconditioner first removes elements ...
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void reducedInvHessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &x, Real &tol)
Apply the reduced inverse Hessian to a vector, v. The reduced inverse Hessian first removes element...
void reducedInvHessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &d, const Vector< Real > &x, Real &tol)
Apply the reduced inverse Hessian to a vector, v. The reduced inverse Hessian first removes element...
ROL::Ptr< ROL::Vector< Real > > primalV_
bool isFeasible(const Vector< Real > &v)
void pruneActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x)
ROL::Ptr< BoundConstraint< Real > > con_
void pruneActive(Vector< Real > &v, const Vector< Real > &x)
void reducedHessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &d, const Vector< Real > &x, Real &tol)
Apply the reduced Hessian to a vector, v. The reduced Hessian first removes elements of v correspondi...
void reducedPrecond(Vector< Real > &Mv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &x, Real &tol)
Apply the reduced preconditioner to a vector, v. The reduced preconditioner first removes elements ...
void precond(Vector< Real > &Mv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply preconditioner to vector.
ROL::Ptr< Secant< Real > > secant_
void reducedHessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &x, Real &tol)
Apply the reduced Hessian to a vector, v. The reduced Hessian first removes elements of v correspondi...
void pruneInactive(Vector< Real > &v, const Vector< Real > &x)
void invHessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
void computeProjectedStep(Vector< Real > &v, const Vector< Real > &x)
ProjectedObjective(Objective< Real > &obj, BoundConstraint< Real > &con, ROL::Ptr< Secant< Real > > &secant, bool useSecantPrecond=false, bool useSecantHessVec=false, Real eps=0.0)
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
void pruneInactive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x)
Real dirDeriv(const Vector< Real > &x, const Vector< Real > &d, Real &tol)
Compute directional derivative.
bool isConActivated(void)
ROL::Ptr< Objective< Real > > obj_
void hessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Provides interface for and implements limited-memory secant operators.
Defines the linear algebra or vector space interface.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual int dimension() const
Return dimension of the vector space.
virtual ROL::Ptr< Vector > basis(const int i) const
Return i-th basis vector.
std::vector< std::vector< Real > > computeEigenvalues(const ROL::LA::Matrix< Real > &mat)
ROL::LA::Matrix< Real > computeDotMatrix(const Vector< Real > &x)
ROL::LA::Matrix< Real > computeScaledDenseHessian(Objective< Real > &obj, const Vector< Real > &x)
std::vector< std::vector< Real > > computeGenEigenvalues(const ROL::LA::Matrix< Real > &A, const ROL::LA::Matrix< Real > &B)
ROL::LA::Matrix< Real > computeDenseHessian(Objective< Real > &obj, const Vector< Real > &x)
ROL::LA::Matrix< Real > computeInverse(const ROL::LA::Matrix< Real > &mat)