I have a non-linear system I'm using Ceres to solve. It's a sparse system with a sparse block structure. Since I'm also working on image data, I've based my code off of the 'denoising.cc' example.
The issue I'm encountering is that my code fails with "Terminating: Residual and Jacobian evaluation failed.". I'm able to fix the issue by hard-coding the variable 'num_weights' in Evaluate.
The issue persists when I call this function on one or on many pixels. For each pixel, my weights are different.
Any insight as to why this is will help.
Thanks!
Cost::Cost(const std::vector<double> &weights) : _weights(weights)
{
set_num_residuals(1);
mutable_parameter_block_sizes()->push_back(1); //has more parameters than weights
for (int i = 0; i < _weights.size(); ++i)
mutable_parameter_block_sizes()->push_back(1);
}
bool Cost::Evaluate(double const* const* parameters,
double *residuals,
double **jacobians) const
{
int num_weights = (int)_weights.size();
float d0 = parameters[0][0];
residuals[0] = d0;
for (int i = 0; i < num_weights; ++i)
{
residuals[0] += parameters[i+1][0];
}
if (jacobians != NULL)
{
for (int i = 0; i < num_weights+1; ++i)
{
if (jacobians[i] != NULL)
{
jacobians[i][0] = 0;
}
}
}
return true;
}