/usr/include/roboptim/core/derivable-parametrized-function.hh is in libroboptim-core-dev 2.0-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | // Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA.
//
// This file is part of the roboptim.
//
// roboptim is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// roboptim is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with roboptim. If not, see <http://www.gnu.org/licenses/>.
#ifndef ROBOPTIM_TRAJECTORY_DERIVABLE_PARAMETRIZABLE_HH
# define ROBOPTIM_TRAJECTORY_DERIVABLE_PARAMETRIZABLE_HH
# include <utility>
# include <roboptim/core/fwd.hh>
# include <roboptim/core/parametrized-function.hh>
# include <roboptim/core/portability.hh>
namespace roboptim
{
/// \addtogroup roboptim_meta_function
/// @{
/// \brief Parametrized function with parameter derivative available.
///
/// Depending on inner function type, this class allows computation
/// of parameter derivative or combined parameter/function derivative.
///
/// \tparam F inner function type.
template <typename F>
class DerivableParametrizedFunction : public ParametrizedFunction<F>
{
public:
/// \brief Import value type.
typedef typename F::value_type value_type;
/// \brief Import size type.
typedef typename F::size_type size_type;
/// \brief Import vector type.
typedef typename F::vector_t vector_t;
/// \brief Import matrix type.
typedef typename F::matrix_t matrix_t;
/// \brief Import result type.
typedef F result_t;
/// \brief Import argument type.
typedef typename F::argument_t argument_t;
/// \brief Import gradient type.
typedef typename F::vector_t gradient_t;
/// \brief Import jacobian type.
typedef typename F::matrix_t jacobian_t;
/// \brief Import jacobian size type (pair of values).
typedef typename F::jacobianSize_t jacobianSize_t;
/// \brief Return the gradient size.
///
/// Gradient size is equals to the input size.
size_type gradientSize () const throw ()
{
return this->inputSize ();
}
/// \brief Return the jacobian size as a pair.
///
/// Gradient size is equals to (output size, input size).
jacobianSize_t jacobianSize () const throw ()
{
return std::make_pair (this->inputSize (),
this->functionOutputSize ());
}
/// \brief Check if the gradient is valid (check size).
/// \param gradient checked gradient
/// \return true if valid, false if not
bool isValidGradient (const gradient_t& gradient) const throw ()
{
return gradient.size () == this->gradientSize ();
}
/// \brief Check if the jacobian is valid (check sizes).
///
/// \param jacobian checked jacobian
/// \return true if valid, false if not
bool isValidJacobian (const jacobian_t& jacobian) const throw ()
{
return jacobian.rows () == this->jacobianSize ().first
&& jacobian.cols () == this->jacobianSize ().second;
}
/// \brief Computes the jacobian.
///
/// \param argument point at which the jacobian will be computed
/// \param order derivation order
/// \return jacobian matrix
jacobian_t jacobian (const argument_t& argument, size_type order = 0)
const throw ()
{
jacobian_t jacobian (jacobianSize ().first, jacobianSize ().second);
jacobian.setZero ();
this->jacobian (jacobian, argument, order);
return jacobian;
}
/// \brief Computes the jacobian.
///
/// Program will abort if the jacobian size is wrong before
/// or after the jacobian computation.
/// \param jacobian jacobian will be stored in this argument
/// \param order derivation order
/// \param argument inner function point argument value
void jacobian (jacobian_t& jacobian, const argument_t& argument,
size_type order = 0) const throw ()
{
assert (argument.size () == this->inputSize ());
assert (this->isValidJacobian (jacobian));
this->impl_jacobian (jacobian, argument, order);
assert (this->isValidJacobian (jacobian));
}
/// \brief Computes the gradient.
///
/// \param argument inner function argument value
/// \param functionId function id in split representation
/// \param order derivation order
/// \return gradient vector
gradient_t gradient (const argument_t& argument,
size_type functionId = 0,
size_type order = 0) const throw ()
{
gradient_t gradient (gradientSize ());
gradient.setZero ();
this->gradient (gradient, argument, functionId, order);
return gradient;
}
/// \brief Computes the gradient.
///
/// Program will abort if the gradient size is wrong before
/// or after the gradient computation.
/// \param gradient gradient will be stored in this argument
/// \param argument inner function point argument value
/// \param functionId function id in split representation
/// \param order derivation order
/// \return gradient vector
void gradient (gradient_t& gradient,
const argument_t& argument,
size_type functionId = 0,
size_type order = 0) const throw ()
{
assert (argument.size () == this->inputSize ());
assert (this->isValidGradient (gradient));
this->impl_gradient (gradient, argument, functionId, order);
assert (this->isValidGradient (gradient));
}
/// \brief Display the function on the specified output stream.
///
/// \param o output stream used for display
/// \return output stream
virtual std::ostream& print (std::ostream& o) const throw ()
{
return o << "Derivable parametrized function";
}
protected:
/// \brief Concrete class constructor should call this constructor.
///
/// \param inputSize parameter size
/// \param functionInputSize inner function argument size
/// \param functionOutputSize inner function result size
DerivableParametrizedFunction (size_type inputSize,
size_type functionInputSize,
size_type functionOutputSize) throw ()
: ParametrizedFunction<F> (inputSize,
functionInputSize,
functionOutputSize)
{
}
/// \brief Jacobian evaluation.
///
/// Computes the jacobian, can be overridden by concrete classes.
/// The default behavior is to compute the jacobian from the gradient.
/// \warning Do not call this function directly, call #jacobian instead.
/// \param jacobian jacobian will be store in this argument
/// \param arg point where the jacobian will be computed
virtual void impl_jacobian (jacobian_t& jacobian, const argument_t& arg)
const throw ()
{
for (size_type i = 0; i < this->functionOutputSize (); ++i)
{
gradient_t grad = this->gradient (arg, i);
for (size_type j = 0; j < this->inputSize (); ++j)
jacobian (i, j) = grad[j];
}
}
/// \brief Gradient evaluation.
///
/// Compute the gradient, has to be implemented in concrete classes.
/// The gradient is computed for a specific sub-function which id
/// is passed through the functionId argument.
/// \warning Do not call this function directly, call #gradient instead.
/// \param gradient gradient will be store in this argument
/// \param argument inner function point argument value
/// \param functionId evaluated function id in the split representation
/// \param order derivation order
virtual void impl_gradient (gradient_t& gradient,
const argument_t& argument,
size_type functionId = 0,
size_type order = 0)
const throw () = 0;
};
/// @}
} // end of namespace roboptim.
#endif //! ROBOPTIM_TRAJECTORY_N_TIMES_DERIVABLE_HH
|