🧵 Any SVD autists here?
Anonymous at Sun, 16 Mar 2025, 07:01:32 GMT No. 16620522
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 at Sun, 16 Mar 2025, 07:46:24 GMT No. 16620533
>>16620522
Learn some linear algebra, nibba.
Anonymous at Sun, 16 Mar 2025, 08:09:08 GMT No. 16620544
>>16620533
You first.
Anonymous at Sun, 16 Mar 2025, 08:13:34 GMT No. 16620545
>>16620522
type numpy. and then hit tab a lot
Anonymous at Sun, 16 Mar 2025, 08:30:17 GMT No. 16620550
>>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 at Sun, 16 Mar 2025, 10:15:55 GMT No. 16620585
idk
Anonymous at Sun, 16 Mar 2025, 11:09:57 GMT No. 16620623
>>16620550
It is very fucking simple, you retard.
Anonymous at Sun, 16 Mar 2025, 11:17:07 GMT No. 16620626
>>16620623
You're very fucking simple.
Anonymous at Sun, 16 Mar 2025, 14:29:29 GMT No. 16620742
>>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.
Anonymous at Sun, 16 Mar 2025, 15:28:02 GMT No. 16620806
>>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?
Anonymous at Sun, 16 Mar 2025, 15:29:20 GMT No. 16620809
>>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 at Sun, 16 Mar 2025, 15:30:44 GMT No. 16620813
>>16620806
And then a million monkeys should input numbers into the matrix until it works?
Anonymous at Sun, 16 Mar 2025, 16:05:12 GMT No. 16620865
>>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 at Sun, 16 Mar 2025, 16:19:42 GMT No. 16620893
>>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 at Sun, 16 Mar 2025, 16:23:09 GMT No. 16620899
>>16620809
>I want to double a number, but if there's any addition it's wrong.
Anonymous at Sun, 16 Mar 2025, 16:48:23 GMT No. 16620931
>>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 at Sun, 16 Mar 2025, 17:20:47 GMT No. 16620949
>>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 at Sun, 16 Mar 2025, 18:28:41 GMT No. 16621011
>>16620949
>Two objects are not equivalent by reflection.
Objects A and B are.
Anonymous at Sun, 16 Mar 2025, 18:59:08 GMT No. 16621041
>>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
the derivation is too long to post here, but ask question if you want
Anonymous at Sun, 16 Mar 2025, 19:02:57 GMT No. 16621044
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 at Sun, 16 Mar 2025, 20:13:19 GMT No. 16621108
>>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 at Sun, 16 Mar 2025, 20:25:11 GMT No. 16621116
>>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 at Mon, 17 Mar 2025, 02:25:18 GMT No. 16621321
>>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 at Mon, 17 Mar 2025, 02:26:19 GMT No. 16621322
>>16621116
>If A and B are orthonormal
They're not.
Anonymous at Mon, 17 Mar 2025, 02:58:06 GMT No. 16621336
>>16621322
>They're not
necessarily
🗑️ Anonymous at Mon, 17 Mar 2025, 05:54:57 GMT No. 16621396
>>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 at Mon, 17 Mar 2025, 06:14:57 GMT No. 16621406
>>16621041
Tried your method and it only works well in 2D. Maybe a gimbal issue? Found a similar paper but with quaternions.
Anonymous at Mon, 17 Mar 2025, 14:48:13 GMT No. 16621638
>>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
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
The matrix
Anonymous at Mon, 17 Mar 2025, 15:15:44 GMT No. 16621658
>>16621638
It's not a change of basis problem. It's a recover the rigid motion in the least squares sense problem.
Anonymous at Mon, 17 Mar 2025, 21:49:46 GMT No. 16621948
>>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
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 at Mon, 17 Mar 2025, 21:54:18 GMT No. 16621953
>>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 at Thu, 20 Mar 2025, 09:01:40 GMT No. 16624174
>>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 at Thu, 20 Mar 2025, 19:04:55 GMT No. 16624424
>>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 at Thu, 20 Mar 2025, 19:11:31 GMT No. 16624427
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 at Thu, 20 Mar 2025, 22:29:14 GMT No. 16624551
>>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 at Thu, 20 Mar 2025, 22:31:14 GMT No. 16624552
>>16624551
Me again. I had to solve this problem to callibrate a camera's pointing direction.
Anonymous at Thu, 20 Mar 2025, 22:49:31 GMT No. 16624573
>>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 at Thu, 20 Mar 2025, 23:06:00 GMT No. 16624591
>>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 at Fri, 21 Mar 2025, 07:40:17 GMT No. 16624798
>>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.