Calculating eigen vectors for a given matrix with VEX

   3414   7   1
User Avatar
Member
209 posts
Joined: March 2018
Offline
Hello everyone!
I would like to know if there is any way to compute eigenvectors for a given matrix via VEX.
There is a VEX function called eigenvalues but as its name suggests it only calculates eigenvalues, not eigenvectors!
Any help would greatly be appreciated!
User Avatar
Member
209 posts
Joined: March 2018
Offline
Is this too hard really?
User Avatar
Member
55 posts
Joined: Feb. 2017
Offline
Not really a VEX solution, but a solution anyway; if you have python modules configured and numpy installed you could store 3x3 matrices on points and feed those into a python SOP. Then iterate over those points and use the numpy / linear algebra functions to convert into eigenvalues and eigenvectors that you then write back to those points.

I basically just implemented the explanation on this page [web.physics.utah.edu] in a python SOP. The matrix here is a 3x3 matrix stored in the 'covariance' attribute.

import numpy as np
from numpy import linalg as LA

node = hou.pwd()
geo = node.geometry()
points = geo.points()

for point in points:
    m = point.attribValue("covariance")
    arr = np.asarray(m)
    mm = arr.reshape(3,3)
    w, v = LA.eig(mm)
    point.setAttribValue("eigenvalues",w)
    point.setAttribValue("xeigenvector",v[:,0])
    point.setAttribValue("yeigenvector",v[:,1])
    point.setAttribValue("zeigenvector",v[:,2])


Here are two other sources that helped me out;
https://www.visiondummy.com/2014/04/geometric-interpretation-covariance-matrix/ [www.visiondummy.com]
https://houdinigubbins.wordpress.com/2017/06/07/covariance-matrix/ [houdinigubbins.wordpress.com]
Technical VFX artist @ Housemarque / Sony Interactive Entertainment
User Avatar
Member
209 posts
Joined: March 2018
Offline
Thanks a lot, man!
I'm just curious to know why SideFX doesn't add the eigenvector function to VEX!
User Avatar
Member
4730 posts
Joined: Feb. 2012
Offline
N-G
Thanks a lot, man!
I'm just curious to know why SideFX doesn't add the eigenvector function to VEX!

VEX have svddecomp (singular value decomposition). I posted an example of it here:
https://www.sidefx.com/forum/topic/84345/#post-364636 [www.sidefx.com]

This is one of the topics I plan to cover in Pragmatic VEX: Volume 2.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
209 posts
Joined: March 2018
Offline
animatrix_
N-G
Thanks a lot, man!
I'm just curious to know why SideFX doesn't add the eigenvector function to VEX!

VEX have svddecomp (singular value decomposition). I posted an example of it here:
https://www.sidefx.com/forum/topic/84345/#post-364636 [www.sidefx.com]

This is one of the topics I plan to cover in Pragmatic VEX: Volume 2.

Thanks a lot, dear @animatrix.
I am in doubt if SVD decomposition can yield eigenvectors of a matrix, instead, it gives eigenvectors for matrix times transpose of the matrix!
User Avatar
Member
4730 posts
Joined: Feb. 2012
Offline
N-G
animatrix_
N-G
Thanks a lot, man!
I'm just curious to know why SideFX doesn't add the eigenvector function to VEX!

VEX have svddecomp (singular value decomposition). I posted an example of it here:
https://www.sidefx.com/forum/topic/84345/#post-364636 [www.sidefx.com]

This is one of the topics I plan to cover in Pragmatic VEX: Volume 2.

Thanks a lot, dear @animatrix.
I am in doubt if SVD decomposition can yield eigenvectors of a matrix, instead, it gives eigenvectors for matrix times transpose of the matrix!

Sorry I didn't see your reply but for the record:

If your matrix is symmetric, you can use diagonalizesymmetric which computes the eigenvalue decomposition of a symmetric matrix: which is guaranteed to have a real spectrum. VEX doesn't have eigenvalue decompositions for general matrices since they would require complex numbers.

There is also eigenvalues VEX function that predates diagonalizesymmetric:
https://www.sidefx.com/docs/houdini/vex/functions/eigenvalues.html [www.sidefx.com]

There is an RFE to support non-symmetric matrices for eigenvalue decomposition: #132742. So feel free to bump that up if you want to see it in a future version of Houdini.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
209 posts
Joined: March 2018
Offline
Thanks a lot, dear Animatrix.
  • Quick Links