12 unsigned int number_of_residuals)
14 if (number_of_unknowns > number_of_residuals)
15 std::cerr <<
"vnl_least_squares_function: WARNING: " 16 <<
"unknowns(" << number_of_unknowns <<
") > " 17 <<
"residuals("<< number_of_residuals <<
")\n";
23 std::cerr <<
"Warning: gradf() called but not implemented in derived class\n";
31 unsigned int dim = x.
size();
32 unsigned int n = jacobian.
rows();
35 assert(dim == jacobian.
columns());
40 for (
unsigned int i = 0; i < dim; ++i)
43 double tplus = tx[i] = x[i] + stepsize;
47 double tminus = tx[i] = x[i] - stepsize;
50 double h = 1.0 / (tplus - tminus);
51 for (
unsigned int j = 0; j < n; ++j)
52 jacobian(j,i) = (fplus[j] - fminus[j]) * h;
65 unsigned int dim = x.
size();
66 unsigned int n = jacobian.
rows();
69 assert(dim == jacobian.
columns());
75 for (
unsigned int i = 0; i < dim; ++i)
78 double tplus = tx[i] = x[i] + stepsize;
81 double h = 1.0 / (tplus - x[i]);
82 for (
unsigned int j = 0; j < n; ++j)
83 jacobian(j,i) = (fplus[j] - fcentre[j]) * h;
abs_t rms() const
Root Mean Squares of values.
Abstract base for minimising functions.
size_t size() const
Return the length, number of elements, dimension of this vector.
unsigned int get_number_of_unknowns() const
Return the number of unknowns.
double rms(vnl_vector< double > const &x)
Compute the rms error at x by calling f and returning the norm of the residual vector.
virtual void gradf(vnl_vector< double > const &x, vnl_matrix< double > &jacobian)
Calculate the Jacobian, given the parameter vector x.
void fdgradf(vnl_vector< double > const &x, vnl_matrix< double > &jacobian, double stepsize)
Use this to compute a finite-difference gradient other than lmdif.
void ffdgradf(vnl_vector< double > const &x, vnl_matrix< double > &jacobian, double stepsize)
Use this to compute a finite-forward-difference gradient other than lmdif.
virtual void trace(int iteration, vnl_vector< double > const &x, vnl_vector< double > const &fx)
Called after each LM iteration to print debugging etc.
unsigned int get_number_of_residuals() const
Return the number of residuals.
void dim_warning(unsigned int n_unknowns, unsigned int n_residuals)
unsigned int rows() const
Return the number of rows.
virtual void f(vnl_vector< double > const &x, vnl_vector< double > &fx)=0
The main function.
unsigned int columns() const
Return the number of columns.