1 ;;; Compiled by f2cl version:
2 ;;; ("f2cl1.l,v 1.215 2009/04/07 22:05:21 rtoy Exp $"
3 ;;; "f2cl2.l,v 1.37 2008/02/22 22:19:33 rtoy Exp $"
4 ;;; "f2cl3.l,v 1.6 2008/02/22 22:19:33 rtoy Exp $"
5 ;;; "f2cl4.l,v 1.7 2008/02/22 22:19:34 rtoy Exp $"
6 ;;; "f2cl5.l,v 1.200 2009/01/19 02:38:17 rtoy Exp $"
7 ;;; "f2cl6.l,v 1.48 2008/08/24 00:56:27 rtoy Exp $"
8 ;;; "macros.l,v 1.112 2009/01/08 12:57:19 rtoy Exp $")
10 ;;; Using Lisp CMU Common Lisp 19f (19F)
12 ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls nil)
13 ;;; (:coerce-assigns :as-needed) (:array-type ':array)
14 ;;; (:array-slicing t) (:declare-common nil)
15 ;;; (:float-format double-float))
20 (let ((factor 100.0) (zero 0.0))
21 (declare (type (double-float) factor zero
))
22 (defun lmder1 (fcn m n x fvec fjac ldfjac tol info ipvt wa lwa
)
23 (declare (type (array f2cl-lib
:integer4
(*)) ipvt
)
24 (type (double-float) tol
)
25 (type (array double-float
(*)) wa fjac fvec x
)
26 (type (f2cl-lib:integer4
) lwa info ldfjac n m
))
27 (f2cl-lib:with-multi-array-data
28 ((x double-float x-%data% x-%offset%
)
29 (fvec double-float fvec-%data% fvec-%offset%
)
30 (fjac double-float fjac-%data% fjac-%offset%
)
31 (wa double-float wa-%data% wa-%offset%
)
32 (ipvt f2cl-lib
:integer4 ipvt-%data% ipvt-%offset%
))
33 (prog ((ftol 0.0) (gtol 0.0) (xtol 0.0) (maxfev 0) (mode 0) (nfev 0)
35 (declare (type (f2cl-lib:integer4
) nprint njev nfev mode maxfev
)
36 (type (double-float) xtol gtol ftol
))
41 '" the purpose of lmder1 is to minimize the sum of the squares of"
42 '" m nonlinear functions in n variables by a modification of the"
43 '" levenberg-marquardt algorithm. this is done by using the more"
44 '" general least-squares solver lmder. the user must provide a"
45 '" subroutine which calculates the functions and the jacobian."
47 '" the subroutine statement is"
49 '" subroutine lmder1(fcn,m,n,x,fvec,fjac,ldfjac,tol,info,"
54 '" fcn is the name of the user-supplied subroutine which"
55 '" calculates the functions and the jacobian. fcn must"
56 '" be declared in an external statement in the user"
57 '" calling program, and should be written as follows."
59 '" subroutine fcn(m,n,x,fvec,fjac,ldfjac,iflag)"
60 '" integer m,n,ldfjac,iflag"
61 '" double precision x(n),fvec(m),fjac(ldfjac,n)"
63 '" if iflag = 1 calculate the functions at x and"
64 '" return this vector in fvec. do not alter fjac."
65 '" if iflag = 2 calculate the jacobian at x and"
66 '" return this matrix in fjac. do not alter fvec."
71 '" the value of iflag should not be changed by fcn unless"
72 '" the user wants to terminate execution of lmder1."
73 '" in this case set iflag to a negative integer."
75 '" m is a positive integer input variable set to the number"
78 '" n is a positive integer input variable set to the number"
79 '" of variables. n must not exceed m."
81 '" x is an array of length n. on input x must contain"
82 '" an initial estimate of the solution vector. on output x"
83 '" contains the final estimate of the solution vector."
85 '" fvec is an output array of length m which contains"
86 '" the functions evaluated at the output x."
88 '" fjac is an output m by n array. the upper n by n submatrix"
89 '" of fjac contains an upper triangular matrix r with"
90 '" diagonal elements of nonincreasing magnitude such that"
93 '" p *(jac *jac)*p = r *r,"
95 '" where p is a permutation matrix and jac is the final"
96 '" calculated jacobian. column j of p is column ipvt(j)"
97 '" (see below) of the identity matrix. the lower trapezoidal"
98 '" part of fjac contains information generated during"
99 '" the computation of r."
101 '" ldfjac is a positive integer input variable not less than m"
102 '" which specifies the leading dimension of the array fjac."
104 '" tol is a nonnegative input variable. termination occurs"
105 '" when the algorithm estimates either that the relative"
106 '" error in the sum of squares is at most tol or that"
107 '" the relative error between x and the solution is at"
110 '" info is an integer output variable. if the user has"
111 '" terminated execution, info is set to the (negative)"
112 '" value of iflag. see description of fcn. otherwise,"
113 '" info is set as follows."
115 '" info = 0 improper input parameters."
117 '" info = 1 algorithm estimates that the relative error"
118 '" in the sum of squares is at most tol."
120 '" info = 2 algorithm estimates that the relative error"
121 '" between x and the solution is at most tol."
123 '" info = 3 conditions for info = 1 and info = 2 both hold."
125 '" info = 4 fvec is orthogonal to the columns of the"
126 '" jacobian to machine precision."
128 '" info = 5 number of calls to fcn with iflag = 1 has"
129 '" reached 100*(n+1)."
131 '" info = 6 tol is too small. no further reduction in"
132 '" the sum of squares is possible."
134 '" info = 7 tol is too small. no further improvement in"
135 '" the approximate solution x is possible."
137 '" ipvt is an integer output array of length n. ipvt"
138 '" defines a permutation matrix p such that jac*p = q*r,"
139 '" where jac is the final calculated jacobian, q is"
140 '" orthogonal (not stored), and r is upper triangular"
141 '" with diagonal elements of nonincreasing magnitude."
142 '" column j of p is column ipvt(j) of the identity matrix."
144 '" wa is a work array of length lwa."
146 '" lwa is a positive integer input variable not less than 5*n+m."
148 '" subprograms called"
150 '" user-supplied ...... fcn"
152 '" minpack-supplied ... lmder"
154 '" argonne national laboratory. minpack project. march 1980."
155 '" burton s. garbow, kenneth e. hillstrom, jorge j. more"
160 '" check the input parameters for errors."
167 (< lwa
(f2cl-lib:int-add
(f2cl-lib:int-mul
5 n
) m
)))
172 (setf maxfev
(f2cl-lib:int-mul
100 (f2cl-lib:int-add n
1)))
179 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9
180 var-10 var-11 var-12 var-13 var-14 var-15 var-16 var-17 var-18
181 var-19 var-20 var-21 var-22 var-23
)
182 (lmder fcn m n x fvec fjac ldfjac ftol xtol gtol maxfev
183 (f2cl-lib:array-slice wa double-float
(1) ((1 lwa
))) mode factor
184 nprint info nfev njev ipvt
185 (f2cl-lib:array-slice wa double-float
((+ n
1)) ((1 lwa
)))
186 (f2cl-lib:array-slice wa
188 ((+ (f2cl-lib:int-mul
2 n
) 1))
190 (f2cl-lib:array-slice wa
192 ((+ (f2cl-lib:int-mul
3 n
) 1))
194 (f2cl-lib:array-slice wa
196 ((+ (f2cl-lib:int-mul
4 n
) 1))
198 (f2cl-lib:array-slice wa
200 ((+ (f2cl-lib:int-mul
5 n
) 1))
202 (declare (ignore var-0 var-3 var-4 var-5 var-7 var-8 var-9 var-10
203 var-11 var-12 var-13 var-14 var-18 var-19 var-20
204 var-21 var-22 var-23
))
211 (if (= info
8) (setf info
4))
215 '" last card of subroutine lmder1."
218 (return (values nil m n nil nil nil ldfjac nil info nil nil nil
))))))
220 (in-package #:cl-user
)
221 #+#.
(cl:if
(cl:find-package
'#:f2cl
) '(and) '(or))
222 (eval-when (:load-toplevel
:compile-toplevel
:execute
)
223 (setf (gethash 'fortran-to-lisp
::lmder1
224 fortran-to-lisp
::*f2cl-function-info
*)
225 (fortran-to-lisp::make-f2cl-finfo
226 :arg-types
'(t (fortran-to-lisp::integer4
)
227 (fortran-to-lisp::integer4
) (array double-float
(*))
228 (array double-float
(*)) (array double-float
(*))
229 (fortran-to-lisp::integer4
) (double-float)
230 (fortran-to-lisp::integer4
)
231 (array fortran-to-lisp
::integer4
(*))
232 (array double-float
(*)) (fortran-to-lisp::integer4
))
233 :return-values
'(nil fortran-to-lisp
::m fortran-to-lisp
::n nil nil
234 nil fortran-to-lisp
::ldfjac nil
235 fortran-to-lisp
::info nil nil nil
)
236 :calls
'(fortran-to-lisp::lmder
))))