public software.sextractor

[/] [trunk/] [src/] [levmar/] [levmar.h] - Blame information for rev 228

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 228 bertin
/*
2
////////////////////////////////////////////////////////////////////////////////////
3
//
4
//  Prototypes and definitions for the Levenberg - Marquardt minimization algorithm
5
//  Copyright (C) 2004  Manolis Lourakis (lourakis at ics forth gr)
6
//  Institute of Computer Science, Foundation for Research & Technology - Hellas
7
//  Heraklion, Crete, Greece.
8
//
9
//  This program is free software; you can redistribute it and/or modify
10
//  it under the terms of the GNU General Public License as published by
11
//  the Free Software Foundation; either version 2 of the License, or
12
//  (at your option) any later version.
13
//
14
//  This program is distributed in the hope that it will be useful,
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
//  GNU General Public License for more details.
18
//
19
////////////////////////////////////////////////////////////////////////////////////
20
*/
21
 
22
#ifndef _LEVMAR_H_
23
#define _LEVMAR_H_
24
 
25
 
26
/************************************* Start of configuration options *************************************/
27
 
28
/* specify whether to use LAPACK or not. The first option is strongly recommended */
29
/*#define HAVE_LAPACK*/ /* use LAPACK */
30
#undef HAVE_LAPACK      /* uncomment this to force not using LAPACK */
31
 
32
/* to avoid the overhead of repeated mallocs(), routines in Axb.c can be instructed to
33
 * retain working memory between calls. Such a choice, however, renders these routines
34
 * non-reentrant and is not safe in a shared memory multiprocessing environment.
35
 * Bellow, this option is turned on only when not compiling with OpenMP.
36
 */
37
#if !defined(_OPENMP) 
38
#define LINSOLVERS_RETAIN_MEMORY /* comment this if you don't want routines in Axb.c retain working memory between calls */
39
#endif
40
 
41
/* determine the precision variants to be build. Default settings build
42
 * both the single and double precision routines
43
 */
44
#define LM_DBL_PREC  /* comment this if you don't want the double precision routines to be compiled */
45
#define LM_SNGL_PREC /* comment this if you don't want the single precision routines to be compiled */
46
 
47
/****************** End of configuration options, no changes necessary beyond this point ******************/
48
 
49
 
50
#ifdef __cplusplus
51
extern "C" {
52
#endif
53
 
54
 
55
#define FABS(x) (((x)>=0.0)? (x) : -(x))
56
 
57
/* work arrays size for ?levmar_der and ?levmar_dif functions.
58
 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
59
 */
60
#define LM_DER_WORKSZ(npar, nmeas) (2*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar))
61
#define LM_DIF_WORKSZ(npar, nmeas) (4*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar))
62
 
63
/* work arrays size for ?levmar_bc_der and ?levmar_bc_dif functions.
64
 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
65
 */
66
#define LM_BC_DER_WORKSZ(npar, nmeas) (2*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar))
67
#define LM_BC_DIF_WORKSZ(npar, nmeas) LM_BC_DER_WORKSZ((npar), (nmeas)) /* LEVMAR_BC_DIF currently implemented using LEVMAR_BC_DER()! */
68
 
69
/* work arrays size for ?levmar_lec_der and ?levmar_lec_dif functions.
70
 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
71
 */
72
#define LM_LEC_DER_WORKSZ(npar, nmeas, nconstr) LM_DER_WORKSZ((npar)-(nconstr), (nmeas))
73
#define LM_LEC_DIF_WORKSZ(npar, nmeas, nconstr) LM_DIF_WORKSZ((npar)-(nconstr), (nmeas))
74
 
75
/* work arrays size for ?levmar_blec_der and ?levmar_blec_dif functions.
76
 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
77
 */
78
#define LM_BLEC_DER_WORKSZ(npar, nmeas, nconstr) LM_LEC_DER_WORKSZ((npar), (nmeas)+(npar), (nconstr))
79
#define LM_BLEC_DIF_WORKSZ(npar, nmeas, nconstr) LM_LEC_DIF_WORKSZ((npar), (nmeas)+(npar), (nconstr))
80
 
81
/* work arrays size for ?levmar_bleic_der and ?levmar_bleic_dif functions.
82
 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
83
 */
84
#define LM_BLEIC_DER_WORKSZ(npar, nmeas, nconstr1, nconstr2) LM_BLEC_DER_WORKSZ((npar)+(nconstr2), (nmeas)+(nconstr2), (nconstr1)+(nconstr2))
85
#define LM_BLEIC_DIF_WORKSZ(npar, nmeas, nconstr1, nconstr2) LM_BLEC_DIF_WORKSZ((npar)+(nconstr2), (nmeas)+(nconstr2), (nconstr1)+(nconstr2))
86
 
87
#define LM_OPTS_SZ       5 /* max(4, 5) */
88
#define LM_INFO_SZ       10
89
#define LM_ERROR         -1
90
#define LM_INIT_MU       1E-03
91
#define LM_STOP_THRESH   1E-17
92
#define LM_DIFF_DELTA    1E-06
93
#define LM_VERSION       "2.5 (December 2009)"
94
 
95
#ifdef LM_DBL_PREC
96
/* double precision LM, with & without Jacobian */
97
/* unconstrained minimization */
98
extern int dlevmar_der(
99
      void (*func)(double *p, double *hx, int m, int n, void *adata),
100
      void (*jacf)(double *p, double *j, int m, int n, void *adata),
101
      double *p, double *x, int m, int n, int itmax, double *opts,
102
      double *info, double *work, double *covar, void *adata);
103
 
104
extern int dlevmar_dif(
105
      void (*func)(double *p, double *hx, int m, int n, void *adata),
106
      double *p, double *x, int m, int n, int itmax, double *opts,
107
      double *info, double *work, double *covar, void *adata);
108
 
109
/* box-constrained minimization */
110
extern int dlevmar_bc_der(
111
       void (*func)(double *p, double *hx, int m, int n, void *adata),
112
       void (*jacf)(double *p, double *j, int m, int n, void *adata),
113
       double *p, double *x, int m, int n, double *lb, double *ub,
114
       int itmax, double *opts, double *info, double *work, double *covar, void *adata);
115
 
116
extern int dlevmar_bc_dif(
117
       void (*func)(double *p, double *hx, int m, int n, void *adata),
118
       double *p, double *x, int m, int n, double *lb, double *ub,
119
       int itmax, double *opts, double *info, double *work, double *covar, void *adata);
120
 
121
#ifdef HAVE_LAPACK
122
/* linear equation constrained minimization */
123
extern int dlevmar_lec_der(
124
      void (*func)(double *p, double *hx, int m, int n, void *adata),
125
      void (*jacf)(double *p, double *j, int m, int n, void *adata),
126
      double *p, double *x, int m, int n, double *A, double *b, int k,
127
      int itmax, double *opts, double *info, double *work, double *covar, void *adata);
128
 
129
extern int dlevmar_lec_dif(
130
      void (*func)(double *p, double *hx, int m, int n, void *adata),
131
      double *p, double *x, int m, int n, double *A, double *b, int k,
132
      int itmax, double *opts, double *info, double *work, double *covar, void *adata);
133
 
134
/* box & linear equation constrained minimization */
135
extern int dlevmar_blec_der(
136
      void (*func)(double *p, double *hx, int m, int n, void *adata),
137
      void (*jacf)(double *p, double *j, int m, int n, void *adata),
138
      double *p, double *x, int m, int n, double *lb, double *ub, double *A, double *b, int k, double *wghts,
139
      int itmax, double *opts, double *info, double *work, double *covar, void *adata);
140
 
141
extern int dlevmar_blec_dif(
142
      void (*func)(double *p, double *hx, int m, int n, void *adata),
143
      double *p, double *x, int m, int n, double *lb, double *ub, double *A, double *b, int k, double *wghts,
144
      int itmax, double *opts, double *info, double *work, double *covar, void *adata);
145
 
146
/* box, linear equations & inequalities constrained minimization */
147
extern int dlevmar_bleic_der(
148
      void (*func)(double *p, double *hx, int m, int n, void *adata),
149
      void (*jacf)(double *p, double *j, int m, int n, void *adata),
150
      double *p, double *x, int m, int n, double *lb, double *ub,
151
      double *A, double *b, int k1, double *C, double *d, int k2,
152
      int itmax, double *opts, double *info, double *work, double *covar, void *adata);
153
 
154
extern int dlevmar_bleic_dif(
155
      void (*func)(double *p, double *hx, int m, int n, void *adata),
156
      double *p, double *x, int m, int n, double *lb, double *ub,
157
      double *A, double *b, int k1, double *C, double *d, int k2,
158
      int itmax, double *opts, double *info, double *work, double *covar, void *adata);
159
 
160
/* box & linear inequality constraints */
161
extern int dlevmar_blic_der(
162
      void (*func)(double *p, double *hx, int m, int n, void *adata),
163
      void (*jacf)(double *p, double *j, int m, int n, void *adata),
164
      double *p, double *x, int m, int n, double *lb, double *ub, double *C, double *d, int k2,
165
      int itmax, double opts[4], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
166
 
167
extern int dlevmar_blic_dif(
168
      void (*func)(double *p, double *hx, int m, int n, void *adata),
169
      double *p, double *x, int m, int n, double *lb, double *ub, double *C, double *d, int k2,
170
      int itmax, double opts[5], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
171
 
172
/* linear equation & inequality constraints */
173
extern int dlevmar_leic_der(
174
      void (*func)(double *p, double *hx, int m, int n, void *adata),
175
      void (*jacf)(double *p, double *j, int m, int n, void *adata),
176
      double *p, double *x, int m, int n, double *A, double *b, int k1, double *C, double *d, int k2,
177
      int itmax, double opts[4], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
178
 
179
extern int dlevmar_leic_dif(
180
      void (*func)(double *p, double *hx, int m, int n, void *adata),
181
      double *p, double *x, int m, int n, double *A, double *b, int k1, double *C, double *d, int k2,
182
      int itmax, double opts[5], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
183
 
184
/* linear inequality constraints */
185
extern int dlevmar_lic_der(
186
      void (*func)(double *p, double *hx, int m, int n, void *adata),
187
      void (*jacf)(double *p, double *j, int m, int n, void *adata),
188
      double *p, double *x, int m, int n, double *C, double *d, int k2,
189
      int itmax, double opts[4], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
190
 
191
extern int dlevmar_lic_dif(
192
      void (*func)(double *p, double *hx, int m, int n, void *adata),
193
      double *p, double *x, int m, int n, double *C, double *d, int k2,
194
      int itmax, double opts[5], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
195
#endif /* HAVE_LAPACK */
196
 
197
#endif /* LM_DBL_PREC */
198
 
199
 
200
#ifdef LM_SNGL_PREC
201
/* single precision LM, with & without Jacobian */
202
/* unconstrained minimization */
203
extern int slevmar_der(
204
      void (*func)(float *p, float *hx, int m, int n, void *adata),
205
      void (*jacf)(float *p, float *j, int m, int n, void *adata),
206
      float *p, float *x, int m, int n, int itmax, float *opts,
207
      float *info, float *work, float *covar, void *adata);
208
 
209
extern int slevmar_dif(
210
      void (*func)(float *p, float *hx, int m, int n, void *adata),
211
      float *p, float *x, int m, int n, int itmax, float *opts,
212
      float *info, float *work, float *covar, void *adata);
213
 
214
/* box-constrained minimization */
215
extern int slevmar_bc_der(
216
       void (*func)(float *p, float *hx, int m, int n, void *adata),
217
       void (*jacf)(float *p, float *j, int m, int n, void *adata),
218
       float *p, float *x, int m, int n, float *lb, float *ub,
219
       int itmax, float *opts, float *info, float *work, float *covar, void *adata);
220
 
221
extern int slevmar_bc_dif(
222
       void (*func)(float *p, float *hx, int m, int n, void *adata),
223
       float *p, float *x, int m, int n, float *lb, float *ub,
224
       int itmax, float *opts, float *info, float *work, float *covar, void *adata);
225
 
226
#ifdef HAVE_LAPACK
227
/* linear equation constrained minimization */
228
extern int slevmar_lec_der(
229
      void (*func)(float *p, float *hx, int m, int n, void *adata),
230
      void (*jacf)(float *p, float *j, int m, int n, void *adata),
231
      float *p, float *x, int m, int n, float *A, float *b, int k,
232
      int itmax, float *opts, float *info, float *work, float *covar, void *adata);
233
 
234
extern int slevmar_lec_dif(
235
      void (*func)(float *p, float *hx, int m, int n, void *adata),
236
      float *p, float *x, int m, int n, float *A, float *b, int k,
237
      int itmax, float *opts, float *info, float *work, float *covar, void *adata);
238
 
239
/* box & linear equation constrained minimization */
240
extern int slevmar_blec_der(
241
      void (*func)(float *p, float *hx, int m, int n, void *adata),
242
      void (*jacf)(float *p, float *j, int m, int n, void *adata),
243
      float *p, float *x, int m, int n, float *lb, float *ub, float *A, float *b, int k, float *wghts,
244
      int itmax, float *opts, float *info, float *work, float *covar, void *adata);
245
 
246
extern int slevmar_blec_dif(
247
      void (*func)(float *p, float *hx, int m, int n, void *adata),
248
      float *p, float *x, int m, int n, float *lb, float *ub, float *A, float *b, int k, float *wghts,
249
      int itmax, float *opts, float *info, float *work, float *covar, void *adata);
250
 
251
/* box, linear equations & inequalities constrained minimization */
252
extern int slevmar_bleic_der(
253
      void (*func)(float *p, float *hx, int m, int n, void *adata),
254
      void (*jacf)(float *p, float *j, int m, int n, void *adata),
255
      float *p, float *x, int m, int n, float *lb, float *ub,
256
      float *A, float *b, int k1, float *C, float *d, int k2,
257
      int itmax, float *opts, float *info, float *work, float *covar, void *adata);
258
 
259
extern int slevmar_bleic_dif(
260
      void (*func)(float *p, float *hx, int m, int n, void *adata),
261
      float *p, float *x, int m, int n, float *lb, float *ub,
262
      float *A, float *b, int k1, float *C, float *d, int k2,
263
      int itmax, float *opts, float *info, float *work, float *covar, void *adata);
264
 
265
/* box & linear inequality constraints */
266
extern int slevmar_blic_der(
267
      void (*func)(float *p, float *hx, int m, int n, void *adata),
268
      void (*jacf)(float *p, float *j, int m, int n, void *adata),
269
      float *p, float *x, int m, int n, float *lb, float *ub, float *C, float *d, int k2,
270
      int itmax, float opts[4], float info[LM_INFO_SZ], float *work, float *covar, void *adata);
271
 
272
extern int slevmar_blic_dif(
273
      void (*func)(float *p, float *hx, int m, int n, void *adata),
274
      float *p, float *x, int m, int n, float *lb, float *ub, float *C, float *d, int k2,
275
      int itmax, float opts[5], float info[LM_INFO_SZ], float *work, float *covar, void *adata);
276
 
277
/* linear equality & inequality constraints */
278
extern int slevmar_leic_der(
279
      void (*func)(float *p, float *hx, int m, int n, void *adata),
280
      void (*jacf)(float *p, float *j, int m, int n, void *adata),
281
      float *p, float *x, int m, int n, float *A, float *b, int k1, float *C, float *d, int k2,
282
      int itmax, float opts[4], float info[LM_INFO_SZ], float *work, float *covar, void *adata);
283
 
284
extern int slevmar_leic_dif(
285
      void (*func)(float *p, float *hx, int m, int n, void *adata),
286
      float *p, float *x, int m, int n, float *A, float *b, int k1, float *C, float *d, int k2,
287
      int itmax, float opts[5], float info[LM_INFO_SZ], float *work, float *covar, void *adata);
288
 
289
/* linear inequality constraints */
290
extern int slevmar_lic_der(
291
      void (*func)(float *p, float *hx, int m, int n, void *adata),
292
      void (*jacf)(float *p, float *j, int m, int n, void *adata),
293
      float *p, float *x, int m, int n, float *C, float *d, int k2,
294
      int itmax, float opts[4], float info[LM_INFO_SZ], float *work, float *covar, void *adata);
295
 
296
extern int slevmar_lic_dif(
297
      void (*func)(float *p, float *hx, int m, int n, void *adata),
298
      float *p, float *x, int m, int n, float *C, float *d, int k2,
299
      int itmax, float opts[5], float info[LM_INFO_SZ], float *work, float *covar, void *adata);
300
#endif /* HAVE_LAPACK */
301
 
302
#endif /* LM_SNGL_PREC */
303
 
304
/* linear system solvers */
305
#ifdef HAVE_LAPACK
306
 
307
#ifdef LM_DBL_PREC
308
extern int dAx_eq_b_QR(double *A, double *B, double *x, int m);
309
extern int dAx_eq_b_QRLS(double *A, double *B, double *x, int m, int n);
310
extern int dAx_eq_b_Chol(double *A, double *B, double *x, int m);
311
extern int dAx_eq_b_LU(double *A, double *B, double *x, int m);
312
extern int dAx_eq_b_SVD(double *A, double *B, double *x, int m);
313
extern int dAx_eq_b_BK(double *A, double *B, double *x, int m);
314
#endif /* LM_DBL_PREC */
315
 
316
#ifdef LM_SNGL_PREC
317
extern int sAx_eq_b_QR(float *A, float *B, float *x, int m);
318
extern int sAx_eq_b_QRLS(float *A, float *B, float *x, int m, int n);
319
extern int sAx_eq_b_Chol(float *A, float *B, float *x, int m);
320
extern int sAx_eq_b_LU(float *A, float *B, float *x, int m);
321
extern int sAx_eq_b_SVD(float *A, float *B, float *x, int m);
322
extern int sAx_eq_b_BK(float *A, float *B, float *x, int m);
323
#endif /* LM_SNGL_PREC */
324
 
325
#else /* no LAPACK */
326
 
327
#ifdef LM_DBL_PREC
328
extern int dAx_eq_b_LU_noLapack(double *A, double *B, double *x, int n);
329
#endif /* LM_DBL_PREC */
330
 
331
#ifdef LM_SNGL_PREC
332
extern int sAx_eq_b_LU_noLapack(float *A, float *B, float *x, int n);
333
#endif /* LM_SNGL_PREC */
334
 
335
#endif /* HAVE_LAPACK */
336
 
337
/* Jacobian verification, double & single precision */
338
#ifdef LM_DBL_PREC
339
extern void dlevmar_chkjac(
340
    void (*func)(double *p, double *hx, int m, int n, void *adata),
341
    void (*jacf)(double *p, double *j, int m, int n, void *adata),
342
    double *p, int m, int n, void *adata, double *err);
343
#endif /* LM_DBL_PREC */
344
 
345
#ifdef LM_SNGL_PREC
346
extern void slevmar_chkjac(
347
    void (*func)(float *p, float *hx, int m, int n, void *adata),
348
    void (*jacf)(float *p, float *j, int m, int n, void *adata),
349
    float *p, int m, int n, void *adata, float *err);
350
#endif /* LM_SNGL_PREC */
351
 
352
/* standard deviation, coefficient of determination (R2) & Pearson's correlation coefficient for best-fit parameters */
353
#ifdef LM_DBL_PREC
354
extern double dlevmar_stddev( double *covar, int m, int i);
355
extern double dlevmar_corcoef(double *covar, int m, int i, int j);
356
extern double dlevmar_R2(void (*func)(double *p, double *hx, int m, int n, void *adata), double *p, double *x, int m, int n, void *adata);
357
 
358
#endif /* LM_DBL_PREC */
359
 
360
#ifdef LM_SNGL_PREC
361
extern float slevmar_stddev( float *covar, int m, int i);
362
extern float slevmar_corcoef(float *covar, int m, int i, int j);
363
extern float slevmar_R2(void (*func)(float *p, float *hx, int m, int n, void *adata), float *p, float *x, int m, int n, void *adata);
364
#endif /* LM_SNGL_PREC */
365
 
366
#ifdef __cplusplus
367
}
368
#endif
369
 
370
#endif /* _LEVMAR_H_ */