This is a simple forwarddifferences Jacobian estimator. I've modified
it a little to reduce the required context, so it hasn't been directly
tested.
You can get better estimates using central or higherorder differences.
vnl_matrix<double> forward_differences(
my_functor_t& f, // the function
vnl_vector<double> x_0, // the central point
const vnl_vector<double> &scale) // the measurement scale.
{
vnl_vector<double> r_0 = f(x_0);
unsigned nr = r_0.size();
unsigned nx = x_0.size();
vnl_matrix<double> jacobian(nr, nx);
for (unsigned i=0; i<nx; ++i)
{
vnl_vector<double> x=x_0;
x(i) += scale(i);
rf_inst.set_x(x);
vnl_vector<double> r=rf_inst.calc_residual();
vnl_vector<double> dr = r  r_0;
dr /= scale(i);
jacobian.set_column(i, dr);
}
return jacobian;
}
XIN LI wrote:
> Hello,
>
> Sorry. I should say that I would like to get the jacobian matrix of a vector value function. Just as the traditional definition of Jacobian.
>
> Could you please tell me how to implement this funcion using VXL library?
>
> Thank you very much!
>
> Xin
>
>
>
>  Original Message 
> From: Ian Scott <ian.m.scott@...>
> Date: Tuesday, May 1, 2007 4:15 am
> Subject: Re: [Vxlusers] question about jacobian
> To: XIN LI <xli16@...>
> Cc: VXL users <vxlusers@...>
>
>
>> Li,
>>
>> This probably isn't what you want to hear but  are you sure you
>> understand what you are asking for?
>>
>> The Jacobian is traditionally defined on a vector function Y=F(X),
>> where
>> Y in a m element vector and X is an n element vector.
>>
>> The Jacobian is the matrix of first derivatives of Y, w.r.t. to each
>>
>> element in X,
>>
>> dY_i
>> J_ij = ____
>> dX_J
>>
>> (or possibly the transpose  I can't remember)
>>
>> You can talk about an analogous Jacobian of a matrix, but usually
>> after
>> defining a flattening of the matrix into a vector, and then defining
>> the
>> variables against which you want to calculate the derivative.
>>
>> The are plenty of other meanings of "the Jacobian of a matrix", e.g.
>>
>> assuming the matrix is a Hessian of F, its square is a rough
>> approximation to the Jacobian.
>>
>> The code to perform these calculations is available in VXL, but not
>> as a
>> simple class, since the implementation depends on what exactly you
>> mean
>> by "Jacobian of a matrix"
>>
>> Ian.
>>
>> XIN LI wrote:
>> > Hello,
>> >
>> > I am using vxl1.8.0. I would like to get the jacobian of a matrix.
>>
>> > Could you please tell me which class I should use to get the
>> jacobian
>> > matrix?
>> >
>> > Thanks!
>> >
>> > Xin
>> >
