|
Packit |
ea1746 |
Sampled Functions
|
|
Packit |
ea1746 |
--
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
It is common to not have an analytical representation of the optimization
|
|
Packit |
ea1746 |
problem but rather a table of values at specific inputs. This commonly occurs
|
|
Packit |
ea1746 |
when working with images or when the functions in the problem are expensive to
|
|
Packit |
ea1746 |
evaluate. To use this data in an optimization problem we can use interpolation
|
|
Packit |
ea1746 |
to evaluate the function and derivatives at intermediate input values.
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
There are many libraries that implement a variety of interpolation schemes, but
|
|
Packit |
ea1746 |
it is difficult to use them in Ceres' automatic differentiation framework.
|
|
Packit |
ea1746 |
Instead, Ceres provides the ability to interpolate one and two dimensional data.
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
The one dimensional interpolation is based on the Cubic Hermite Spline. This
|
|
Packit |
ea1746 |
interpolation method requires knowledge of the function derivatives at the
|
|
Packit |
ea1746 |
control points, however we only know the function values. Consequently, we will
|
|
Packit |
ea1746 |
use the data to estimate derivatives at the control points. The choice of how to
|
|
Packit |
ea1746 |
compute the derivatives is not unique and Ceres uses the Catmull–Rom Spline
|
|
Packit |
ea1746 |
variant which uses `0.5 * (p_{k+1} - p_{k-1})` as the derivative for control
|
|
Packit |
ea1746 |
point `p_k.` This produces a first order differentiable interpolating
|
|
Packit |
ea1746 |
function. The two dimensional interpolation scheme is a generalization of the
|
|
Packit |
ea1746 |
one dimensional scheme where the interpolating function is assumed to be
|
|
Packit |
ea1746 |
separable in the two dimensions.
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
This example shows how to use interpolation schemes within the Ceres automatic
|
|
Packit |
ea1746 |
differentiation framework. This is a one dimensional example and the objective
|
|
Packit |
ea1746 |
function is to minimize `0.5 * f(x)^2` where `f(x) = (x - 4.5)^2`.
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
It is also possible to use analytical derivatives with the provided
|
|
Packit |
ea1746 |
interpolation schemes by using a `SizedCostFunction` and defining the
|
|
Packit |
ea1746 |
``Evaluate` function. For this example, the evaluate function would be:
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
```c++
|
|
Packit |
ea1746 |
bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const {
|
|
Packit |
ea1746 |
if (jacobians == NULL || jacobians[0] == NULL)
|
|
Packit |
ea1746 |
interpolator_.Evaluate(parameters[0][0], residuals);
|
|
Packit |
ea1746 |
else
|
|
Packit |
ea1746 |
interpolator_.Evaluate(parameters[0][0], residuals, jacobians[0]);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
```
|