[comp.lang.c] RMS deviation between two sets of cartesian coords

jim@doctor.chem.yale.edu (James F. Blake) (12/05/90)

     I am looking for code to compute the RMS deviation between two
sets of cartesian coordinates.  The coordinates would be arbitrarily
oriented with respect to each other, so some sort of fitting would
be required (LLSQ, NLLSQ, or simplex).  General or specific code
would be appreciated.  Thanks.

  Jim

gwyn@smoke.brl.mil (Doug Gwyn) (12/06/90)

In article <27599@cs.yale.edu> jim@doctor.chem.yale.edu (James F. Blake) writes:
>     I am looking for code to compute the RMS deviation between two
>sets of cartesian coordinates.  The coordinates would be arbitrarily
>oriented with respect to each other, so some sort of fitting would
>be required (LLSQ, NLLSQ, or simplex).

Sounds to me like the sums of the squares of the (vector) differences
between corresponding coordinates would suffice -- or is it the
situation that you can't establish a correspondence between points
in the two sets (i.e. you want to compare clouds as such).

jim@doctor.chem.yale.edu (James F. Blake) (12/06/90)

From article <14660@smoke.brl.mil>, by gwyn@smoke.brl.mil (Doug Gwyn):
> In article <27599@cs.yale.edu> jim@doctor.chem.yale.edu (James F. Blake) writes:
>>     I am looking for code to compute the RMS deviation between two
>>sets of cartesian coordinates.  The coordinates would be arbitrarily
>>oriented with respect to each other, so some sort of fitting would
>>be required (LLSQ, NLLSQ, or simplex).
> 
> Sounds to me like the sums of the squares of the (vector) differences
> between corresponding coordinates would suffice -- or is it the
> situation that you can't establish a correspondence between points
> in the two sets (i.e. you want to compare clouds as such).

     That was the approach I took first.  It turns out that their is a
significant amount of "round off" error inherent in the least-squares
equations when solved in this manner.  If I computed the RMS deviations
between structures A -> B and B -> A, I would see as much as a 5%
difference in answers.  I was hoping that someone else had seen this
problem and decided to solve for the rotation/translation matrix
of [X][CTM] = [X'] directly.

  Jim

gwyn@smoke.brl.mil (Doug Gwyn) (12/07/90)

In article <27625@cs.yale.edu> jim@doctor.chem.yale.edu (James F. Blake) writes:
-From article <14660@smoke.brl.mil>, by gwyn@smoke.brl.mil (Doug Gwyn):
-> In article <27599@cs.yale.edu> jim@doctor.chem.yale.edu (James F. Blake) writes:
->-     I am looking for code to compute the RMS deviation between two
->-sets of cartesian coordinates.
-> Sounds to me like the sums of the squares of the (vector) differences
-> between corresponding coordinates would suffice --
-     That was the approach I took first.  It turns out that their is a
-significant amount of "round off" error inherent in the least-squares
-equations when solved in this manner.  If I computed the RMS deviations
-between structures A -> B and B -> A, I would see as much as a 5%
-difference in answers.

It's hard to see how you could get 5% fuzz in a variance computation
if you use the direct definition (sums of squares of deviations).
The textbook rewrite as mean-of-squares minus square-of-mean is well
known to produce bogus answers, however, particularly when the variance
is relatively small.

jim@doctor.chem.yale.edu (James F. Blake) (12/07/90)

From article <14666@smoke.brl.mil>, by gwyn@smoke.brl.mil (Doug Gwyn):
> 
> It's hard to see how you could get 5% fuzz in a variance computation
> if you use the direct definition (sums of squares of deviations).
> The textbook rewrite as mean-of-squares minus square-of-mean is well
> known to produce bogus answers, however, particularly when the variance
> is relatively small.

     You're correct.  I believe the problem was a combination of the
equations and a "feature."  The original code allowed the axis to be 
transformed such that they were nonorthogonal, if this would produce a
better fit.  This probably produced most of the fuzz.  Thanks to all who
have responded, your insight is very much appreciated.

  Jim