Dear Ceres community,
I am attempting to use Ceres for peak fitting in gamma spectroscopy. Sorry if my question is naive, as I am totally new to this framework, and I am not even sure that this is the right tool in the first place.
How would one define an AutoDiff function for a polynomial of degree N? In a more generalized sense, for a function that is a sum of N components, as in, for example, a sum of N Gaussian peaks, each with a different set of parameters? Having defined such a function as y=f(x), I would then like to fit it to a set of (x,y) points.
So far, I am concluding this is impossible with Ceres, because:
a) If each coefficient is a parameter, I must hardcode each one as const T* in the operator() function, and I can only have up to 9 of them, which is not scalable or
b) If I put them all into one parameter block, I must already known the number of parameters at compile-time, because I must initialize it as "AutoDiffCostFunction<PolynomialResidual, 1, N>", so I must also know N at compile time and on top of that then still hard-code array element access in operator() since the functor is not informed about the number of parameters even at compile time, much less dynamically.
Maybe my C++fu is weak or I am not getting something? If this is, after all, possible, perhaps there could be an example of such a case? I have tried googling "Ceres Solver polynomial" only to discover internal classes for root-finding.
Thanks,
Martin