54 #include "Teuchos_GlobalMPISession.hpp"
60 int main(
int argc,
char *argv[]) {
62 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
65 int iprint = argc - 1;
66 ROL::Ptr<std::ostream> outStream;
69 outStream = ROL::makePtrFromRef(std::cout);
71 outStream = ROL::makePtrFromRef(bhs);
75 oldFormatState.copyfmt(std::cout);
80 RealT left = -1.0, right = 1.0;
87 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(dim, 0.0);
88 ROL::Ptr<std::vector<RealT> > y_ptr = ROL::makePtr<std::vector<RealT>>(dim, 0.0);
89 ROL::Ptr<std::vector<RealT> > z_ptr = ROL::makePtr<std::vector<RealT>>(dim, 0.0);
95 for (
int i=0; i<dim; i++) {
96 (*x_ptr)[i] = 10.0* (1.0 + (
RealT)rand() / (
RealT)RAND_MAX);
97 (*y_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
98 (*z_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
106 std::vector<std::vector<RealT> > gCheck = obj.
checkGradient(x, y);
108 for (
unsigned i=0; i<gCheck.size(); i++) {
110 *outStream << std::right
111 << std::setw(20) <<
"Step size"
112 << std::setw(20) <<
"grad'*dir"
113 << std::setw(20) <<
"FD approx"
114 << std::setw(20) <<
"abs error"
117 *outStream << std::scientific << std::setprecision(8) << std::right
118 << std::setw(20) << gCheck[i][0]
119 << std::setw(20) << gCheck[i][1]
120 << std::setw(20) << gCheck[i][2]
121 << std::setw(20) << gCheck[i][3]
126 std::vector<std::vector<RealT> > hvCheck = obj.
checkHessVec(x, y);
128 for (
unsigned i=0; i<hvCheck.size(); i++) {
130 *outStream << std::right
131 << std::setw(20) <<
"Step size"
132 << std::setw(20) <<
"norm(Hess*vec)"
133 << std::setw(20) <<
"norm(FD approx)"
134 << std::setw(20) <<
"norm(abs error)"
137 *outStream << std::scientific << std::setprecision(8) << std::right
138 << std::setw(20) << hvCheck[i][0]
139 << std::setw(20) << hvCheck[i][1]
140 << std::setw(20) << hvCheck[i][2]
141 << std::setw(20) << hvCheck[i][3]
146 std::vector<RealT> hsymCheck = obj.
checkHessSym(x, y, z);
148 *outStream << std::right
149 << std::setw(20) <<
"<w, H(x)v>"
150 << std::setw(20) <<
"<v, H(x)w>"
151 << std::setw(20) <<
"abs error"
153 *outStream << std::scientific << std::setprecision(8) << std::right
154 << std::setw(20) << hsymCheck[0]
155 << std::setw(20) << hsymCheck[1]
156 << std::setw(20) << hsymCheck[2]
166 for (
unsigned i=0; i<(eigenvals[0]).size(); i++) {
168 *outStream << std::right
169 << std::setw(20) <<
"Real"
170 << std::setw(20) <<
"Imag"
173 *outStream << std::scientific << std::setprecision(8) << std::right
174 << std::setw(20) << (eigenvals[0])[i]
175 << std::setw(20) << (eigenvals[1])[i]
180 catch (std::logic_error err) {
181 *outStream << err.what() <<
"\n";
186 std::cout <<
"End Result: TEST FAILED\n";
188 std::cout <<
"End Result: TEST PASSED\n";
191 std::cout.copyfmt(oldFormatState);
Contains definitions of test objective functions.
Contains definitions for helper functions in ROL.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Teuchos::SerialDenseMatrix< int, Real > computeDenseHessian(Objective< Real > &obj, const Vector< Real > &x)
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
std::vector< std::vector< Real > > computeEigenvalues(const Teuchos::SerialDenseMatrix< int, Real > &mat)
int dimension() const
Return dimension of the vector space.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
virtual std::vector< Real > checkHessSym(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &w, const bool printToStream=true, std::ostream &outStream=std::cout)
Hessian symmetry check.
Poisson material inversion.