Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
levmar.h
✓ #include <levmar.h>
Fit a linear model y = p0*x + p1 using Levenberg-Marquardt
#include "levmar.h"
#include <cstdio>
int main() {
double p[2] = {1.0, 1.0};
double x[4] = {0.0, 1.0, 2.0, 3.0};
double y[4] = {0.1, 0.9, 4.1, 9.0};
double opts[LM_OPTS_SZ] = {LM_INIT_MU, 1E-15, 1E-15, 1E-20, LM_DIFF_DELTA};
double info[LM_INFO_SZ];
int ret = dlevmar_der(
[](double *p, double *hx, int m, int n, void *adata) {
for(int i=0; i<n; ++i) hx[i] = p[0]*x[i] + p[1];
},
[](double *p, double *jac, int m, int n, void *adata) {
for(int i=0; i<n; ++i) {
jac[i*m+0] = x[i];
jac[i*m+1] = 1.0;
}
},
p, x, y, 2, 4, 1000, opts, info, NULL, NULL, NULL);
printf("Result: p0=%f p1=%f\n", p[0], p[1]);
return 0;
}
Audit
Dependencies
No dependency data recorded yet.
Resources
No resource links recorded.