Fuse.Problem
|
An example for a shared object that cna be used with fuse.problem. More...
#include "problemShared.hpp"
Macros | |
#define | PROBLEM_PRECISION double |
An example for a shared object that cna be used with fuse.problem.
This is an example for an external library that uses the rosenbrock function. It defines the function rosenbrock, the gradient and the hessian. The rosenbrock function is:
$$ f(x, y) = (a - x)^2 + b (y- x^2)^2 $$
that is of dimension 1. The gradient with respecto to x and y:
$$ \nabla f = \left[ \begin{array}{c} 4 a x^3 - 4 b x y - 2 a + 2 x \\ 3 b (y - x^2) \end{array} \right] $$
that is of dimension 2x1, and than the hessian:
$$ \nabla ^2 f = \left[ \begin{array}{cc} 2 + (12 x - 4 y) b & -4 b x \\ -4 b x & 2 b \end{array} \right] $$
that is of dimension 2x2 and will be stored with row mayor order in the vector in form {ddf[xx], ddf[xy], ddf[yx], ddf[yy]}.
For the actual implementation:
A function is defined using FUNCTION_DEFINE(function_name, { function body }) While the registration of the function to be exported is performed through the macro FUNCTION_EXPORT(function_size, x_size, p_size, funcA, funcB, ...) Optionally, the precision of the problem can be defined "before" including the required header "problemShared" in the macro PROBLEM_PRECISION.
The shared object can be compiled with:
g++ -I../include -fPIC -shared -lm librosenbrock.cpp -o librosenbrock.so
The system can be mounted as:
fuse.problem -s /tmp/rosenbrock shared/librosenbrock.so