1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 |
|
---|
5 | #include "levmar-2.6/levmar.h"
|
---|
6 | #include "levmar_h.h"
|
---|
7 |
|
---|
8 | void callback_func(double *p, double *x, int m, int n, void *data) {
|
---|
9 | Callback_func(p,x,data);
|
---|
10 | }
|
---|
11 |
|
---|
12 | void callback_jacfunc(double *p, double *jac, int m, int n, void *data) {
|
---|
13 | Callback_jacfunc(p,jac,data);
|
---|
14 | }
|
---|
15 |
|
---|
16 | void levmar_der( double* ygiven, double* p, const int m, const int n, void* data ) {
|
---|
17 | double opts[LM_OPTS_SZ], info[LM_INFO_SZ];
|
---|
18 |
|
---|
19 | // optimization control parameters; passing to levmar NULL instead of opts reverts to defaults
|
---|
20 | opts[0]=LM_INIT_MU; opts[1]=1E-15; opts[2]=1E-15; opts[3]=1E-20;
|
---|
21 | opts[4]=LM_DIFF_DELTA; // relevant only if the finite difference Jacobian version is used
|
---|
22 |
|
---|
23 | // invoke the optimization function
|
---|
24 | dlevmar_der(callback_func, callback_jacfunc, p, ygiven, m, n, 1000, opts, info, NULL, NULL, data); // with analytic Jacobian
|
---|
25 | }
|
---|
26 |
|
---|
27 | void levmar_dif( double* ygiven, double* p, const int m, const int n, void* data ) {
|
---|
28 | double opts[LM_OPTS_SZ], info[LM_INFO_SZ];
|
---|
29 |
|
---|
30 | // optimization control parameters; passing to levmar NULL instead of opts reverts to defaults
|
---|
31 | opts[0]=LM_INIT_MU; opts[1]=1E-15; opts[2]=1E-15; opts[3]=1E-20;
|
---|
32 | opts[4]=LM_DIFF_DELTA; // relevant only if the finite difference Jacobian version is used
|
---|
33 |
|
---|
34 | // invoke the optimization function
|
---|
35 | dlevmar_dif(callback_func, p, ygiven, m, n, 1000, opts, info, NULL, NULL, data); // without Jacobian
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|