\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
cpp_gradient¶
View page sourceC++ Abstract Class For Calculating Gradient¶
Syntax¶
# include <cmpad/gradient.hpp>template< template<class ADVector > class Algo > class: public cmpad::gradient {Source Code¶
# include <cmpad/vector.hpp>
# include <cmpad/fun_obj.hpp>
namespace cmpad {
// gradient
class gradient : public fun_obj< cmpad::vector<double> > {
public:
// scalar_type
typedef double scalar_type;
// setup
virtual void setup(const option_t& option) override = 0;
// option
virtual const option_t& option(void) const override = 0;
// domain
virtual size_t domain(void) const override = 0;
// range
size_t range(void) const override
{ return domain(); }
// operator
virtual const cmpad::vector<double>& operator()(
const cmpad::vector<double>& x
) override = 0;
};
}
ADVector¶
This is a Vector type chosen by the package.
The type ADVector::value_type is the scalar type used by the package
to record the operations in the algorithm.
Algo¶
The Algo class is derived from the cpp_fun_obj class
(we use algo for a corresponding object).
The gradient is for the last component of the range space of the algorithm.
Hence, algo.range() can be greater than one.
setup¶
An Algo object is initialized using its setup member function.
Grad¶
This is a cpp_fun_obj interface to the gradient of the function corresponding to Algo (we use grad for a corresponding object). The object grad calculates the gradient of the last component of the vector returned by algo.
setup¶
The object grad is initialized using its setup member function
(which in turn initializes algo using its setup member function).
The setup functions should do calculations that do not depend on x
(to make the evaluation of the gradient faster).
vector_type¶
The type of the vectors x and g is
typedef cmpad::vector<double> Grad :: vector_typeThis is different from Algo :: vector_type which usually is
an AD vector type for a particular package..
scalar_type¶
The type of the elements of x and g is
typedef double Grad :: scalar_typeThis is different from Algo :: scalar_type which usually is
an AD scalar type for a particular package.
domain¶
This returns the dimension of the domain space dimension for the function and gradient.
range¶
This returns the dimension of the
range space dimension for the gradient.
The dimension of the range space for the gradient is equal
to the dimension of the domain space for the gradient and function.
Hence range is implemented by this interface and not virtual.
x¶
This vector has size equal to the dimension of the domain space. It is the point at which the gradient, of the function represented by algo , is evaluated.
g¶
This result is has equal to the dimension of the range space for the gradient, which is equal to the size of x . It is the gradient evaluated at the point x .
Example and Derived Classes¶
Name |
Title |
|---|---|
xam_gradient |
|
adept_gradient.hpp |
|
adolc_gradient.hpp |
|
autodiff_gradient.hpp |
|
codi_gradient.hpp |
|
cppad_gradient |
|
cppad_jit_gradient.hpp |
|
cppadcg_gradient.hpp |
|
sacado_gradient.hpp |
|
xad_gradient.hpp |