Image not available

697x295

1739315438659069.png

🧵 Any SVD autists here?

Anonymous No. 16620522 Report

I have 2 sets of unit vectors and I want to find the optimal rotation matrix from A to B. BUT keep in mind the optimal rotation:
- will make sure that each colour is only closest to its own colour
- the vectors are unit vectors, but NOT necessarily orthonormal
- only the rotation is needed, not scale or reflection

Anonymous No. 16620533 Report

>>16620522
Learn some linear algebra, nibba.

Anonymous No. 16620544 Report

>>16620533
You first.

Anonymous No. 16620545 Report

>>16620522
type numpy. and then hit tab a lot

Anonymous No. 16620550 Report

>>16620522
PS: when I said they're not orthornomal I also meant A and B are not equal. So it should be the best rotation in the least squares sense. That's why it's not a simple problem.

Anonymous No. 16620585 Report

idk

Anonymous No. 16620623 Report

>>16620550
It is very fucking simple, you retard.

Anonymous No. 16620626 Report

>>16620623
You're very fucking simple.

Image not available

827x1254

978-1-4612-0089-5.jpg

Anonymous No. 16620742 Report

>>16620522
>only the rotation is needed, not scale or reflection
Rotations should be thought of as a pair of reflections in two planes. The rotation axis is the intersection of those two planes.

Image not available

407x60

rotation matrix.gif

Anonymous No. 16620806 Report

>>16620522
one can use the depicted rotation matrix

(a, b, c) is the axis of rotation
a^2 + b^2 + c^2 = 1

theta is the angle of rotation

https://www.wolframalpha.com/input?i=%7B%7B1%2C+0%2C+0%7D%2C+%7B0%2C+1%2C+0%7D%2C+%7B0%2C+0%2C+1%7D%7D+%2B+Sin%5B%CE%B8%5D+%7B%7B0%2C+-c%2C+b%7D%2C+%7Bc%2C+0%2C+-a%7D%2C+%7B-b%2C+a%2C+0%7D%7D+%2B+%281+-+Cos%5B%CE%B8%5D%29+MatrixPower%5B%7B%7B0%2C+-c%2C+b%7D%2C+%7Bc%2C+0%2C+-a%7D%2C+%7B-b%2C+a%2C+0%7D%7D%2C+2%5D

Anonymous No. 16620809 Report

>>16620742
Your quote has nothing to do with the problem you midwit. I'm saying if A could be turned into B by reflecting it, that's incorrect.

Anonymous No. 16620813 Report

>>16620806
And then a million monkeys should input numbers into the matrix until it works?

Anonymous No. 16620865 Report

>>16620813
>And then a million monkeys should input numbers into the matrix until it works?
One step at a time.
The first step was to get the rotation matrix.

You're free to toy with it, in the meantime.

Anonymous No. 16620893 Report

>>16620809
>I'm saying if A could be turned into B by reflecting it, that's incorrect.
because that would be more like dealing with imaginary axis planes?

Anonymous No. 16620899 Report

>>16620809
>I want to double a number, but if there's any addition it's wrong.

Anonymous No. 16620931 Report

>>16620899
I guess that depends on "what" you're trying to double.
If it's just 2x'ing a digit, then +orx can both can pretty much do that.
But if you need to double the value of a specific variable, that could restrict options available.
I think, idk honestly desu

Anonymous No. 16620949 Report

>>16620893
>>16620899
Two objects are not equivalent by reflection. Just like you can rotate all you want but you can't match your face in the mirror only by rotation.

Anonymous No. 16621011 Report

>>16620949
>Two objects are not equivalent by reflection.
Objects A and B are.

Image not available

370x142

poop.png

Anonymous No. 16621041 Report

>>16620522
orthogonal procrustes analysis.
i did a write up in my dissertation on this problem.
you can get the analytic solution using the SVD.
the U and V matrices here are from applying the SVD to a matrix built using the position vectors, specifically BΔAΔT=UΣVT, where BDelta and ADelta are matrices formed from the position vectors with their respective centers of mass subtracted off.
the derivation is too long to post here, but ask question if you want

Anonymous No. 16621044 Report

btw, i was applying procrustes analysis to small sets (5ish) of unlabeled points. to figure out the correspondence between the points, i just tried all the permutations of points when constructing the augmented matrices.
of course, this method does not scale past a few points, but works well enough if your datasets are small and your application is not time-sensitive.
if this wasn't the case, it would be wise to spend more time optimizing the solution for larger datasets

Anonymous No. 16621108 Report

>>16620949
>Two objects are not equivalent by reflection. Just like you can rotate all you want but you can't match your face in the mirror only by rotation.
I think that might have been what I was meaning to say.
Where the total sum of all the information being transferred to the reflected side, but you have to account for this -not necessarily intuitive(and for lack of better terminology), but more like- 'variable' or 'dimension'?

Anonymous No. 16621116 Report

>>16620806
A = {b1, g1, r1} = {blue1, green1, red1}
B = {b2, g2, r2}

If A and B are orthonormal, then:

M1 = M1(u1; t1) = matrix1
u1 = (b1×b2)/|b1×b2| = axis1
t1 = arccos(b1.b2) = angle1

M2 = M2(u2; t2)
u2 = b2
cos(t2) = g2.(M1.g1)

M3 = M2.M1

Anonymous No. 16621321 Report

>>16621041
>>16621044
In this case the correspondence is known and it's only 3 points, but the points between the two sets are not necessarily the same. Finding out how similar they are using only rigid motion rotation is the problem.

Anonymous No. 16621322 Report

>>16621116
>If A and B are orthonormal
They're not.

Anonymous No. 16621336 Report

>>16621322
>They're not
necessarily

🗑️ Anonymous No. 16621396 Report

>>16621041
Tried your method. It works well for 2D, and it works for 3D when the vectors are orthonormal to each other. But it shits itself profoundly when the 3D vectors are not orthonormal. Maybe a Gimbal issue? I found a paper which uses a similar idea with but quaternions.

🗑️ Anonymous No. 16621406 Report

>>16621041
Tried your method and it only works well in 2D. Maybe a gimbal issue? Found a similar paper but with quaternions.

Anonymous No. 16621638 Report

>>16620522
This is less a SVD problem and more a "change of basis" problem. It has a very simple solution. Say you want to transform vectors a1,a2,a3 to align with vectors b1,b2,b3 respectively

First step, treating each of these as column vectors, smoosh all the a's together into a matrix A and all the b's together to get matrix B. In other words

A=[a1a2a3],B=[b1b2b3]

The matrix TBA which maps a1b1,a2b2,a3b3 is given by

TBA=BA1

Anonymous No. 16621658 Report

>>16621638
It's not a change of basis problem. It's a recover the rigid motion in the least squares sense problem.

Anonymous No. 16621948 Report

>>16621321
the derivation which i ain't including is phrased in terms of a least squares minimization problem.
the formula i posted >>16621041 is the solution to the minimization problem R=argminRO(3)RAΔBΔ2.
the optimal solution minimizes the norm squared of all the distances (not the total distance, but a high dimension analog of total distance). the value of the cost function serves as a metric for how good a fit the solution is.
also, this handles any number of three or greater points (remember you have to figure out the ordering, though)
also, it the problem can be formulated to include translation and rotation, but it sounds like you don't care about those.

once again, the magic words are "procrustes analysis"

Anonymous No. 16621953 Report

>>16621638
you need svd if you want to consider N != dim(V) vectors. even if you have a bag of N = dim(V) vectors, they don't necessarily have to span V / be linearly independent, so the inverse of a augmented matrix built from them doesn't necessarily have to exist

Anonymous No. 16624174 Report

>>16621948
I've been playing around with this. Unfortunately SVD solutions don't work on planar / linear problems. In other words it doesn't work when there are only 3 points in 3D. Works well for 2D problems though. But it shits itself too often in 3D. Shame.

Anonymous No. 16624424 Report

>>16624174
>In other words it doesn't work when there are only 3 points in 3D.
it absolutely works when you have 3 points with no symmetry.
it works if the points don't perfectly align.
the solution i gave also always gives a proper rotation.
the only restriction is that the sets have the same number of points (and that you have to figure out the correspondence between unlabeled points, which i did by brute force permutation)
it is exactly what OP is asking for.

Anonymous No. 16624427 Report

hell, it even works when you have symmetry, the only issue is that the solution is no longer unique and sensitive to initial conditions

Anonymous No. 16624551 Report

>>16620522
Look up the connection between rotations in 3d and quaternions. Each unit quaterion represents a rotation because it can operate on the pure quaternions (those with no real part) by conjugation.
The fact that you have 3 vectors in each set is a red herring, the solution works for n vectors in each set. The dot product between each rotated source vector and the corresponding target vector is a quadratic function of the quaternion coordinates, so the same is true of the sum over all the source (and target) vectors.
Thus, you need to maximise a quadratic function over the unit 3-sphere (in R^4). This is a syymetric eigenvalue problem. The unit eigenvector corresponding to the largest eigenvalue is the quaternion corresponding to your optimal rotation.

Anonymous No. 16624552 Report

>>16624551
Me again. I had to solve this problem to callibrate a camera's pointing direction.

Anonymous No. 16624573 Report

>>16624552
perhaps let the thread know what your fucking problem is?
as in, what information are you given (e.g. 2d points on a photo, 3d points, a known set of points, etc.)

Anonymous No. 16624591 Report

>>16624573
I am not OP. My problem (>10 years ago) was that I had images of points in a photograph and I knew the points' locations and the camera's. I had to find the orientation of the camera. I used the quaternion method that I summarised above. You fucking fucking.

Anonymous No. 16624798 Report

>>16624424
Looks like you're right. I made a mistake when porting to numpy because of the matrix order difference. Have to remember to multiply the last row of V by the det(V.T @ U.T). Numpy matrices are all transposed from standard math matrices.