Re: mpfit: multivariate fit [message #53919 is a reply to message #53918] |
Tue, 08 May 2007 07:11   |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On May 7, 11:19 pm, Dave <Confused.Scient...@gmail.com> wrote:
> Hi all,
>
> I'm trying to use MPFIT to numerically estimate a coordinate
> transformation matrix that relates two sensors. One set is
> uncalibrated, and the other has a known calibration. So, I have a set
> of observed vectors (xyz_obs) and a set of known vectors (xyz_known)
> and I'm trying to estimate (in a least squares sense) the
> transformation matrix T that relates them. Judiciously choosing the
> data in the fictional example below, I expect the transformation
> matrix to be 2 * identity(3,3).
>
> When I execute the code below, I get:
>
> IDL> .r foo
> % Compiled module: TRANS.
> % Compiled module: $MAIN$.
> Iter 1 CHI-SQUARE = 1278958.0 DOF = 291
> P(0) = 1.00000
> P(1) = 0.00000
> P(2) = 0.00000
> P(3) = 0.00000
> P(4) = 1.00000
> P(5) = 0.00000
> P(6) = 0.00000
> P(7) = 0.00000
> P(8) = 1.00000
> % MPFIT: Error detected while calling MPFIT_FDJAC2:
> % MPFIT: Out of range subscript encountered: FJAC.
> % MPFIT: Error condition detected. Returning to MAIN level.
>
> Any ideas on what I'm doing wrong here?
>
> Thanks!
> Dave
>
> %%%
> % Contents of foo.pro
> %%%
>
> function trans, K, X=x, Y=y, err=err, forward=fw
> model = K ## x
> if keyword_set(fw) then return, model else return, (y-model)/err
> end
>
> ; MAIN
>
> ; Attempt to estimate the transformation matrix given a set
> ; of observed Cartesian vectors and a set of known cartesian
> ; vectors.
>
> n = 100 ; number of 'observations'
>
> v = [1.0d, 0.15, 0.5] ; template vector
> xyz_obs = dblarr(n, 3) ; observations
> for i=0, n-1 do $
> xyz_obs[i,*] = reform( v+0.01*randomn(seed,3), 1, 3)
>
> xyz_known = dblarr(n, 3) ; known values (trivial scaling)
> for i=0, n-1 do $
> xyz_known[i,*] = reform( v*2.0, 1, 3)
>
> ; Estimate the transformation matrix, T
> T0 = identity(3, /DOUBLE) ; initial guess transformation matrix
> f = {x: xyz_obs, y: xyz_known, err: 0.01}
> T = mpfit('trans', T0, functargs=f, COVAR=S2)
>
> end
In the file mpfit.pro, in function mpfit_fdjac2() (line 1119) I
changed fjac[0,j] = to fjac[*,j] = and it runs(?). I was getting a
subscript out of range error before.
if abs(dside[j]) LE 1 then begin
;; COMPUTE THE ONE-SIDED DERIVATIVE
;; Note optimization fjac(0:*,j)
--> fjac[*,j] = (fp-fvec)/h[j]
The results are:
Iter 2 CHI-SQUARE = 377.98996 DOF = 291
P(0) = 1.49186
P(1) = 0.112292
P(2) = 0.982288
P(3) = 0.223779
P(4) = 0.0168439
P(5) = 0.147343
P(6) = 0.745930
P(7) = 0.0561463
P(8) = 0.491144
I'm not sure if this helps. Maybe Craig can answer better.
|
|
|