The biggest advantage of libdogleg is it supports problems with sparse Jacobians. This can result in huge savings for large least squares problems.
Generally speaking, we just need to recover the sparse storage buffers of the compressed-column sparse (CCS) matrix of type cholmod_sparse and fill them with our Jacobian values. In C, the unpacking is done as follows:
static void optimizerCallback(const double* p,
double* x,
cholmod_sparse* Jt,
void* cookie __attribute__ ((unused)) )
{
// These are convenient so that I only apply the casts once
int* Jrowptr = (int*)Jt->p;
int* Jcolidx = (int*)Jt->i;
double* Jval = (double*)Jt->x;
Notably, the Jacobian matrix is referenced as J^T. The array Jrowptr is of size Nmeas + 1 (recall the output vector is of size Nmeas). The arrays Jcolidx and Jval are of size Jnnz, which is the number of non-zero values in the sparse matrix.
The number of non-zeros must be given explicitly to the libdogleg optimizer:
optimum = dogleg_optimize2(p, Nstate, Nmeasurements, Jnnz,
&optimizerCallback, NULL,
&dogleg_parameters, NULL);
A full description of the CHOLMOD sparse storage format is given in the user guide: https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/master/CHOLMOD/Doc/CHOLMOD_UserGuide.pdf
The biggest advantage of libdogleg is it supports problems with sparse Jacobians. This can result in huge savings for large least squares problems.
Generally speaking, we just need to recover the sparse storage buffers of the compressed-column sparse (CCS) matrix of type
cholmod_sparseand fill them with our Jacobian values. In C, the unpacking is done as follows:Notably, the Jacobian matrix is referenced as
J^T. The arrayJrowptris of sizeNmeas + 1(recall the output vector is of sizeNmeas). The arraysJcolidxandJvalare of sizeJnnz, which is the number of non-zero values in the sparse matrix.The number of non-zeros must be given explicitly to the libdogleg optimizer:
A full description of the CHOLMOD sparse storage format is given in the user guide: https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/master/CHOLMOD/Doc/CHOLMOD_UserGuide.pdf