source: pacpusframework/branches/2.0-beta1/include/extlib/levmar/lm.h@ 89

Last change on this file since 89 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 11.1 KB
Line 
1/*
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 _LM_H_
23#define _LM_H_
24
25/************************************* Start of configuration options *************************************/
26
27/* specify whether to use LAPACK or not. The first option is strongly recommended */
28#define HAVE_LAPACK /* use LAPACK */
29/* #undef HAVE_LAPACK */ /* uncomment this to force not using LAPACK */
30
31/* to avoid the overhead of repeated mallocs(), routines in Axb.c can be instructed to
32 * retain working memory between calls. Such a choice, however, renders these routines
33 * non-reentrant and is not safe in a shared memory multiprocessing environment.
34 * Bellow, this option is turned on only when not compiling with OpenMP.
35 */
36#if !defined(_OPENMP)
37# ifndef LINSOLVERS_RETAIN_MEMORY
38# define LINSOLVERS_RETAIN_MEMORY /* comment this if you don't want routines in Axb.c retain working memory between calls */
39# endif // LINSOLVERS_RETAIN_MEMORY
40#endif
41
42/* determine the precision variants to be build. Default settings build
43 * both the single and double precision routines
44 */
45#define LM_DBL_PREC /* comment this if you don't want the double precision routines to be compiled */
46#define LM_SNGL_PREC /* comment this if you don't want the single precision routines to be compiled */
47
48/****************** End of configuration options, no changes necessary beyond this point ******************/
49
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55
56#define FABS(x) (((x)>=0.0)? (x) : -(x))
57
58/* work arrays size for ?levmar_der and ?levmar_dif functions.
59 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
60 */
61#define LM_DER_WORKSZ(npar, nmeas) (2*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar))
62#define LM_DIF_WORKSZ(npar, nmeas) (4*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar))
63
64/* work arrays size for ?levmar_bc_der and ?levmar_bc_dif functions.
65 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
66 */
67#define LM_BC_DER_WORKSZ(npar, nmeas) (2*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar))
68#define LM_BC_DIF_WORKSZ(npar, nmeas) LM_BC_DER_WORKSZ((npar), (nmeas)) /* LEVMAR_BC_DIF currently implemented using LEVMAR_BC_DER()! */
69
70/* work arrays size for ?levmar_lec_der and ?levmar_lec_dif functions.
71 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
72 */
73#define LM_LEC_DER_WORKSZ(npar, nmeas, nconstr) LM_DER_WORKSZ((npar)-(nconstr), (nmeas))
74#define LM_LEC_DIF_WORKSZ(npar, nmeas, nconstr) LM_DIF_WORKSZ((npar)-(nconstr), (nmeas))
75
76/* work arrays size for ?levmar_blec_der and ?levmar_blec_dif functions.
77 * should be multiplied by sizeof(double) or sizeof(float) to be converted to bytes
78 */
79#define LM_BLEC_DER_WORKSZ(npar, nmeas, nconstr) LM_LEC_DER_WORKSZ((npar), (nmeas)+(npar), (nconstr))
80#define LM_BLEC_DIF_WORKSZ(npar, nmeas, nconstr) LM_LEC_DIF_WORKSZ((npar), (nmeas)+(npar), (nconstr))
81
82#define LM_OPTS_SZ 5 /* max(4, 5) */
83#define LM_INFO_SZ 9
84#define LM_ERROR -1
85#define LM_INIT_MU 1E-03
86#define LM_STOP_THRESH 1E-17
87#define LM_DIFF_DELTA 1E-06
88#define LM_VERSION "2.3 (May 2008)"
89
90#ifdef LM_DBL_PREC
91/* double precision LM, with & without Jacobian */
92/* unconstrained minimization */
93extern int dlevmar_der(
94 void (*func)(double *p, double *hx, int m, int n, void *adata),
95 void (*jacf)(double *p, double *j, int m, int n, void *adata),
96 double *p, double *x, int m, int n, int itmax, double *opts,
97 double *info, double *work, double *covar, void *adata);
98
99extern int dlevmar_dif(
100 void (*func)(double *p, double *hx, 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/* box-constrained minimization */
105extern int dlevmar_bc_der(
106 void (*func)(double *p, double *hx, int m, int n, void *adata),
107 void (*jacf)(double *p, double *j, int m, int n, void *adata),
108 double *p, double *x, int m, int n, double *lb, double *ub,
109 int itmax, double *opts, double *info, double *work, double *covar, void *adata);
110
111extern int dlevmar_bc_dif(
112 void (*func)(double *p, double *hx, 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#ifdef HAVE_LAPACK
117/* linear equation constrained minimization */
118extern int dlevmar_lec_der(
119 void (*func)(double *p, double *hx, int m, int n, void *adata),
120 void (*jacf)(double *p, double *j, int m, int n, void *adata),
121 double *p, double *x, int m, int n, double *A, double *b, int k,
122 int itmax, double *opts, double *info, double *work, double *covar, void *adata);
123
124extern int dlevmar_lec_dif(
125 void (*func)(double *p, double *hx, 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/* box & linear equation constrained minimization */
130extern int dlevmar_blec_der(
131 void (*func)(double *p, double *hx, int m, int n, void *adata),
132 void (*jacf)(double *p, double *j, int m, int n, void *adata),
133 double *p, double *x, int m, int n, double *lb, double *ub, double *A, double *b, int k, double *wghts,
134 int itmax, double *opts, double *info, double *work, double *covar, void *adata);
135
136extern int dlevmar_blec_dif(
137 void (*func)(double *p, double *hx, 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#endif /* HAVE_LAPACK */
141
142#endif /* LM_DBL_PREC */
143
144
145#ifdef LM_SNGL_PREC
146/* single precision LM, with & without Jacobian */
147/* unconstrained minimization */
148extern int slevmar_der(
149 void (*func)(float *p, float *hx, int m, int n, void *adata),
150 void (*jacf)(float *p, float *j, int m, int n, void *adata),
151 float *p, float *x, int m, int n, int itmax, float *opts,
152 float *info, float *work, float *covar, void *adata);
153
154extern int slevmar_dif(
155 void (*func)(float *p, float *hx, int m, int n, void *adata),
156 float *p, float *x, int m, int n, int itmax, float *opts,
157 float *info, float *work, float *covar, void *adata);
158
159/* box-constrained minimization */
160extern int slevmar_bc_der(
161 void (*func)(float *p, float *hx, int m, int n, void *adata),
162 void (*jacf)(float *p, float *j, int m, int n, void *adata),
163 float *p, float *x, int m, int n, float *lb, float *ub,
164 int itmax, float *opts, float *info, float *work, float *covar, void *adata);
165
166extern int slevmar_bc_dif(
167 void (*func)(float *p, float *hx, int m, int n, void *adata),
168 float *p, float *x, int m, int n, float *lb, float *ub,
169 int itmax, float *opts, float *info, float *work, float *covar, void *adata);
170
171#ifdef HAVE_LAPACK
172/* linear equation constrained minimization */
173extern int slevmar_lec_der(
174 void (*func)(float *p, float *hx, int m, int n, void *adata),
175 void (*jacf)(float *p, float *j, int m, int n, void *adata),
176 float *p, float *x, int m, int n, float *A, float *b, int k,
177 int itmax, float *opts, float *info, float *work, float *covar, void *adata);
178
179extern int slevmar_lec_dif(
180 void (*func)(float *p, float *hx, int m, int n, void *adata),
181 float *p, float *x, int m, int n, float *A, float *b, int k,
182 int itmax, float *opts, float *info, float *work, float *covar, void *adata);
183
184/* box & linear equation constrained minimization */
185extern int slevmar_blec_der(
186 void (*func)(float *p, float *hx, int m, int n, void *adata),
187 void (*jacf)(float *p, float *j, int m, int n, void *adata),
188 float *p, float *x, int m, int n, float *lb, float *ub, float *A, float *b, int k, float *wghts,
189 int itmax, float *opts, float *info, float *work, float *covar, void *adata);
190
191extern int slevmar_blec_dif(
192 void (*func)(float *p, float *hx, int m, int n, void *adata),
193 float *p, float *x, int m, int n, float *lb, float *ub, float *A, float *b, int k, float *wghts,
194 int itmax, float *opts, float *info, float *work, float *covar, void *adata);
195#endif /* HAVE_LAPACK */
196
197#endif /* LM_SNGL_PREC */
198
199/* linear system solvers */
200#ifdef HAVE_LAPACK
201
202#ifdef LM_DBL_PREC
203extern int dAx_eq_b_QR(double *A, double *B, double *x, int m);
204extern int dAx_eq_b_QRLS(double *A, double *B, double *x, int m, int n);
205extern int dAx_eq_b_Chol(double *A, double *B, double *x, int m);
206extern int dAx_eq_b_LU(double *A, double *B, double *x, int m);
207extern int dAx_eq_b_SVD(double *A, double *B, double *x, int m);
208#endif /* LM_DBL_PREC */
209
210#ifdef LM_SNGL_PREC
211extern int sAx_eq_b_QR(float *A, float *B, float *x, int m);
212extern int sAx_eq_b_QRLS(float *A, float *B, float *x, int m, int n);
213extern int sAx_eq_b_Chol(float *A, float *B, float *x, int m);
214extern int sAx_eq_b_LU(float *A, float *B, float *x, int m);
215extern int sAx_eq_b_SVD(float *A, float *B, float *x, int m);
216#endif /* LM_SNGL_PREC */
217
218#else /* no LAPACK */
219
220#ifdef LM_DBL_PREC
221extern int dAx_eq_b_LU_noLapack(double *A, double *B, double *x, int n);
222#endif /* LM_DBL_PREC */
223
224#ifdef LM_SNGL_PREC
225extern int sAx_eq_b_LU_noLapack(float *A, float *B, float *x, int n);
226#endif /* LM_SNGL_PREC */
227
228#endif /* HAVE_LAPACK */
229
230/* Jacobian verification, double & single precision */
231#ifdef LM_DBL_PREC
232extern void dlevmar_chkjac(
233 void (*func)(double *p, double *hx, int m, int n, void *adata),
234 void (*jacf)(double *p, double *j, int m, int n, void *adata),
235 double *p, int m, int n, void *adata, double *err);
236#endif /* LM_DBL_PREC */
237
238#ifdef LM_SNGL_PREC
239extern void slevmar_chkjac(
240 void (*func)(float *p, float *hx, int m, int n, void *adata),
241 void (*jacf)(float *p, float *j, int m, int n, void *adata),
242 float *p, int m, int n, void *adata, float *err);
243#endif /* LM_SNGL_PREC */
244
245/* standard deviation & Pearson's correlation coefficient for best-fit parameters */
246#ifdef LM_DBL_PREC
247extern double dlevmar_stddev( double *covar, int m, int i);
248extern double dlevmar_corcoef(double *covar, int m, int i, int j);
249#endif /* LM_DBL_PREC */
250
251#ifdef LM_SNGL_PREC
252extern float slevmar_stddev( float *covar, int m, int i);
253extern float slevmar_corcoef(float *covar, int m, int i, int j);
254#endif /* LM_SNGL_PREC */
255
256#ifdef __cplusplus
257}
258#endif
259
260#endif /* _LM_H_ */
Note: See TracBrowser for help on using the repository browser.