15 template<
class Functor,
class Type>
19 gradient_t(Functor f_) : f(f_) {}
20 AD<Type> userfun(
vector<AD<Type> > x){
24 CppAD::vector<AD<Type> > x( x0 );
25 CppAD::vector<AD<Type> > y( 1 );
26 CppAD::Independent(x);
28 CppAD::ADFun<Type> F(x, y);
29 CppAD::vector<Type> x_eval(x0);
30 return F.Jacobian(x_eval);
66 template<
class Functor,
class Type>
68 #ifdef CPPAD_FRAMEWORK 69 gradient_t<Functor, Type> f(F);
72 #ifdef TMBAD_FRAMEWORK 80 template<
class Functor,
class Type>
84 gradient_t<Functor,AD<Type> > gr;
85 hessian_t(Functor f_) : f(f_), gr(f_) {}
90 CppAD::vector<AD<Type> > x( x0 );
91 CppAD::vector<AD<Type> > y( x0 );
92 CppAD::Independent(x);
94 CppAD::ADFun<Type> F(x, y);
95 CppAD::vector<Type> x_eval(x0);
97 return asMatrix(ans, x.size(), x.size());
133 template<
class Functor,
class Type>
135 #ifdef CPPAD_FRAMEWORK 136 hessian_t<Functor, Type> H(f);
139 #ifdef TMBAD_FRAMEWORK 143 return asMatrix(Fx, x.size(), x.size());
148 template<
class Functor,
class Type>
152 jacobian_t(Functor f_) : f(f_) {}
157 CppAD::vector<AD<Type> > x( x0 );
158 CppAD::Independent(x);
159 CppAD::vector<AD<Type> > y = userfun(x);
160 CppAD::ADFun<Type> F(x, y);
161 CppAD::vector<Type> x_eval(x0);
163 return asMatrix(ans, x.size(), y.size()).transpose();
202 template<
class Functor,
class Type>
204 #ifdef CPPAD_FRAMEWORK 205 jacobian_t<Functor, Type> J(f);
208 #ifdef TMBAD_FRAMEWORK 213 return asMatrix(Jx, x.size(), m).transpose();
Vector class used by TMB.
Automatic differentiation (gradient, hessian, jacobian)
matrix< Type > jacobian(Functor f, vector< Type > x)
Calculate jacobian of vector function with vector values.
ADFun JacFun(std::vector< bool > keep_x=std::vector< bool >(0), std::vector< bool > keep_y=std::vector< bool >(0))
Get Jacobian function object.
Matrix class used by TMB.
matrix< Type > hessian(Functor f, vector< Type > x)
Calculate hessian of vector function with scalar values.
Interoperability with other vector classes.
vector< Type > gradient(Functor F, vector< Type > x)
Calculate gradient of vector function with scalar values.
matrix< Type > asMatrix(const vector< Type > &x, int nr, int nc)
Vector <-> Matrix conversion (for row-major matrices)