Eigenvalue of non-square matrix in Slicer 4

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Eigenvalue of non-square matrix in Slicer 4

quentan
Hi there,

I am solving an eigenvalue problem inside Slicer 4.5, but found `numpy.linalg.eig(a)` is intended for square arrays. I have to do this for non-sqaure array and then imported `scipy.linalg` manually, as `scipy.linalg.eig` can do this,

```
import sys
sys.path.append('/usr/lib/python2.7/dist-packages')
import scipy
import scipy.linalg
```
but making the code inelegant and hard to run for others.

I know Scipy is still hard to natively work with Slicer 4, but is there a better way to specifically solve the eigenvalue problem for general matrix?

Cheers,
Quentan

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Eigenvalue of non-square matrix in Slicer 4

Sharp, Gregory C.

Hi Quentan,

 

I’m no expert of python or even slicer.  But if memory serves, eigendecomposition

is only defined for square matrices.  Maybe you could use singular values instead?  

Would numpy.linalg.svd serve?

 

Greg

 

From: slicer-users [mailto:[hidden email]] On Behalf Of Quentan Qi
Sent: Wednesday, October 05, 2016 12:40 AM
To: SPL Slicer Users
Subject: [slicer-users] Eigenvalue of non-square matrix in Slicer 4

 

Hi there,

 

I am solving an eigenvalue problem inside Slicer 4.5, but found `numpy.linalg.eig(a)` is intended for square arrays. I have to do this for non-sqaure array and then imported `scipy.linalg` manually, as `scipy.linalg.eig` can do this,

 

```

import sys

sys.path.append('/usr/lib/python2.7/dist-packages')

import scipy

import scipy.linalg

```

but making the code inelegant and hard to run for others.

 

I know Scipy is still hard to natively work with Slicer 4, but is there a better way to specifically solve the eigenvalue problem for general matrix?

 

Cheers,

Quentan


_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Eigenvalue of non-square matrix in Slicer 4

inorton
In reply to this post by quentan
Please give an example, this doesn't really make sense because `scipy.linalg.eig` also checks for square matrices (as it should):

In [12]: scipy.linalg.eig(np.random.rand(3,2))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-81b26856b275> in <module>()
----> 1 scipy.linalg.eig(np.random.rand(3,2))

/opt/anaconda/lib/python2.7/site-packages/scipy/linalg/decomp.pyc in eig(a, b, left, right, overwrite_a, overwrite_b, check_finite)
    146     a1 = _asarray_validated(a, check_finite=check_finite)
    147     if len(a1.shape) != 2 or a1.shape[0] != a1.shape[1]:
--> 148         raise ValueError('expected square matrix')
    149     overwrite_a = overwrite_a or (_datacopied(a1, a))
    150     if b is not None:

ValueError: expected square matrix

On Wed, Oct 5, 2016 at 12:40 AM, Quentan Qi <[hidden email]> wrote:
Hi there,

I am solving an eigenvalue problem inside Slicer 4.5, but found `numpy.linalg.eig(a)` is intended for square arrays. I have to do this for non-sqaure array and then imported `scipy.linalg` manually, as `scipy.linalg.eig` can do this,

```
import sys
sys.path.append('/usr/lib/python2.7/dist-packages')
import scipy
import scipy.linalg
```
but making the code inelegant and hard to run for others.

I know Scipy is still hard to natively work with Slicer 4, but is there a better way to specifically solve the eigenvalue problem for general matrix?

Cheers,
Quentan

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ


_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Eigenvalue of non-square matrix in Slicer 4

inorton
In reply to this post by quentan
On Wed, Oct 5, 2016 at 12:40 AM, Quentan Qi <[hidden email]> wrote:

I know Scipy is still hard to natively work with Slicer 4, but is there a better way to specifically solve the eigenvalue problem for general matrix?

There is an overview of matrix decomposition techniques here:

numpy.linalg only supports qr, cholesky, and svd. If you need something fancier you could potentially write a small wrapper to call in to VNL [1] or Eigen [2] (available for extensions), although probably you need to know the matrix dimensions ahead of time.

 

Cheers,
Quentan

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ


_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ