4 #include "ocra/optim/FunctionProperties.h" 25 DotProductFunction::DotProductFunction(Function* f,
const Vector& v)
26 :Function(f->getVariable(), 1, L_UNDEFINED, C_UNDEFINED,
27 f->getContinuityProperty(), f->canComputeHessian(), f->canComputeGradient())
28 , _f1(f), _v(v), _f2(NULL), _twoFunctions(false), _tmp(f->getVariable().getSize())
30 assert(_f1->getDimension()==_v.getSize());
38 throw std::runtime_error(
"[ocra::SubtractionFunction::changeV]: no vector involved in this DotProductFunction");
48 _value[0] = CML_dot(_f1->getValues(), _f2->getValues());
50 _value[0] = CML_dot(_f1->getValues(), _v);
59 CML_gemv<'t'>(1., _f1->getGradients(), _f2->getValues(), 0., _tmp);
60 CML_gemv<'t'>(1., _f2->getGradients(), _f1->getValues(), 1., _tmp);
63 CML_gemv<'t'>(1., _f1->getGradients(), _v, 0., _tmp);
65 for (cfl_size_t i=0; i<_tmp.getSize(); ++i)
66 _gradient(0,i) = _tmp[i];
78 (
const_cast<Matrix*
>(_hessians[0]))->copyValuesFrom(*_f1->getHessian(0));
79 (
const_cast<Matrix*
>(_hessians[0]))->scalarMultInPlace(_v[0]);
80 for (cfl_size_t i=1; i<_f1->getDimension(); ++i)
82 for (cfl_size_t j=0; j<_x->getSize(); ++j)
84 VectorWrap hessianColumn = ( (
const_cast<Matrix*
>(_hessians[0])) )->getColumnAsVector(j);
85 CML_axpy(_v[i], _f1->getHessian(i)->getColumnAsVector(j), hessianColumn);
98 CML_gemv<'t'>(1., _f1->getJdot(), _v, 0., _tmp);
100 for (cfl_size_t i=0; i<_tmp.getSize(); ++i)
101 _Jdot(0,i) = _tmp[i];
108 for (cfl_size_t i=0; i<_tmp.getSize(); ++i)
109 _JdotXdot[0] += getJdot()(0,i)*(*_x->getTimeDerivative())[i];
117 void DotProductFunction::initHessian(
void)
119 _hessians[0] =
new Matrix(_x->getSize(), _x->getSize());
virtual void computeJdot(void) const
void changeV(const Vector &v)
virtual void computeHessian(void) const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual void computeGradient(void) const
Declaration file of the DotProductFunction class.
virtual void computeValue(void) const
virtual void doUpdateSize(void)
virtual void computeJdotXdot(void) const