// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /** \file \brief Contains definitions for least squares function. \author Created by D. Ridzal and D. Kouri. */ #ifndef USE_HESSVEC #define USE_HESSVEC 1 #endif #ifndef ROL_LEASTSQUARES_HPP #define ROL_LEASTSQUARES_HPP #include "ROL_StdVector.hpp" #include "ROL_TestProblem.hpp" namespace ROL { namespace ZOO { /** \brief Least squares function. */ template class Objective_LeastSquares : public Objective { typedef typename std::vector::size_type uint; public: Real value( const Vector &x, Real &tol ) { ROL::Ptr > ex = dynamic_cast&>(x).getVector(); uint n = ex->size(); Real h = 1.0/((Real)n+1.0); Real val = 0.0; Real res = 0.0; for (uint i=0; i &g, const Vector &x, Real &tol ) { ROL::Ptr > eg = dynamic_cast&>(g).getVector(); ROL::Ptr > ex = dynamic_cast&>(x).getVector(); uint n = ex->size(); Real h = 1.0/((Real)n+1.0); std::vector res(n,0.0); for (uint i=0; i &hv, const Vector &v, const Vector &x, Real &tol ) { ROL::Ptr > ehv = dynamic_cast&>(hv).getVector(); ROL::Ptr > ev = dynamic_cast&>(v).getVector(); ROL::Ptr > ex = dynamic_cast&>(x).getVector(); uint n = ex->size(); Real h = 1.0/((Real)n+1.0); std::vector res(n,0.0); for (uint i=0; i class getLeastSquares : public TestProblem { public: getLeastSquares(void){} Ptr> getObjective(void) const { // Instantiate Objective Function return ROL::makePtr>(); } Ptr> getInitialGuess(void) const { // Problem dimension int n = 32; // Get Initial Guess ROL::Ptr > x0p = ROL::makePtr>(n,0.0); for ( int i = 0; i < n; i++ ) { (*x0p)[i] = 0.0; } return ROL::makePtr>(x0p); } Ptr> getSolution(const int i = 0) const { // Problem dimension int n = 32; // Get Solution ROL::Ptr > xp = ROL::makePtr>(n,0.0); Real h = 1.0/((Real)n+1.0), pt = 0.0; for( int i = 0; i < n; i++ ) { pt = (Real)(i+1)*h; (*xp)[i] = pt*(1.0-pt); } return ROL::makePtr>(xp); } }; } // End ZOO Namespace } // End ROL Namespace #endif