Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a classic linear algebra problem, the key phrase to search on is "multiple linear regression".</p> <p>I've had to code some variation of this many times over the years. For example, code to calibrate a digitizer tablet or stylus touch-screen uses the same math. </p> <hr> <p>Here's the math:</p> <p>Let <strong>p</strong> be an input vector and <strong>q</strong> the corresponding output vector.</p> <p>The transformation you want is a 3x3 matrix; call it <strong>A</strong>.</p> <p>For a single input and output vector <strong>p</strong> and <strong>q</strong>, there is an error vector <strong>e</strong></p> <p><strong>e</strong> = <strong>q</strong> - <strong>A</strong> x <strong>p</strong></p> <p>The square of the magnitude of the error is a scalar value:</p> <p><strong>e</strong>T x <strong>e</strong> = (<strong>q</strong> - <strong>A</strong> x <strong>p</strong>)T x (<strong>q</strong> - <strong>A</strong> x <strong>p</strong>)</p> <p>(where the T operator is transpose).</p> <p>What you really want to minimize is the sum of <strong>e</strong> values over the sets:</p> <p><strong>E</strong> = sum (<strong>e</strong>)</p> <p>This minimum satisfies the matrix equation <strong>D</strong> = 0 where</p> <p><strong>D</strong>(i,j) = the partial derivative of <strong>E</strong> with respect to <strong>A</strong>(i,j)</p> <p>Say you have N input and output vectors.</p> <p>Your set of input 3-vectors is a 3xN matrix; call this matrix <strong>P</strong>. The ith column of <strong>P</strong> is the ith input vector.</p> <p>So is the set of output 3-vectors; call this matrix <strong>Q</strong>.</p> <p>When you grind thru all of the algebra, the solution is</p> <p><strong>A</strong> = <strong>Q</strong> x <strong>P</strong>T x (<strong>P</strong> x <strong>P</strong>T) ^-1</p> <p>(where ^-1 is the inverse operator -- sorry about no superscripts or subscripts)</p> <hr> <p>Here's the algorithm:</p> <p>Create the 3xN matrix <strong>P</strong> from the set of input vectors.</p> <p>Create the 3xN matrix <strong>Q</strong> from the set of output vectors.</p> <p>Matrix Multiply <strong>R</strong> = <strong>P</strong> x transpose (<strong>P</strong>)</p> <p>Compute the inverseof <strong>R</strong></p> <p>Matrix Multiply <strong>A</strong> = <strong>Q</strong> x transpose(<strong>P</strong>) x inverse (<strong>R</strong>)</p> <p>using the matrix multiplication and matrix inversion routines of your linear algebra library of choice. </p> <hr> <p><strong>However</strong>, a 3x3 affine transform matrix is capable of scaling and rotating the input vectors, but <strong>not</strong> doing any translation! This might not be general enough for your problem. It's usually a good idea to append a "1" on the end of each of the 3-vectors to make then a 4-vector, and look for the best 3x4 transform matrix that minimizes the error. This can't hurt; it can only lead to a better fit of the data.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload