mahout-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastian Schelter <...@apache.org>
Subject Re: eigenvectors and eigenvalues of a matrix
Date Wed, 08 Jan 2014 11:28:09 GMT
I would rather use a List of Pair<Double,Vector> entries then a HashMap
with the eigenvalue as key. HashMap don't have an ordering and you will
get problems if you have to eigenvalues of the same magnitude.


On 08.01.2014 12:13, Tharindu Rusira wrote:
> Hi Ted, Thank a lot for your comprehensive reply.
> 
> The following is a simple piece of code I wrote. According to what you have
> said, this code would make sense, am I right? Please correct me if I'm
> wrong.
> 
> /*respective parameters of the following method are taken from
> getSingularvalues() and getV() methods in SingularValueDecomposition class.
> */
> 
> public HashMap<Double,DenseVector> mapEigenvaluesToEigenVectors(double[]
> singularValues, Matrix eigenVectors) {
> 
>     HashMap<Double,DenseVector> eigenMap = new
> HashMap<>(singularValues.length);
> 
>     for (int i = 0; i < singularValues.length; i++) {
> 
>       // eigenvalue = singular value ^2
> 
>       // eigenvectors = right singular vectors
> 
>       eigenMap.put(singularValues[i] * singularValues[i], (DenseVector)
> eigenVectors.viewRow(i));
> 
>     }
> 
>     return eigenMap;
> 
>   }
> 
> 
> In case my problem is unclear, here's some context,
> 
> I have an input matrix X and I want to find eigenvalues/eigenvectors of the
> covariance matrix XTX. So my workaround is to find singular values and
> right singular vector of X in order to use the following equivalency.
> " Comparison with the eigenvector factorisation of *X*T*X* establishes that
> the right singular vectors *W* of *X* are equivalent to the eigenvectors of
> *X*T*X*, while the singular values *σ*(*k*) of *X* are equal to the square
> roots of the eigenvalues *λ*(*k*) of *X*T*X*. " ~ Wikipedia [1]
> 
> [1]
> http://en.wikipedia.org/wiki/Principal_component_analysis#Singular_value_decomposition
> 
> 
> Regards,
> 
> 
> 
> On Tue, Jan 7, 2014 at 12:27 PM, Ted Dunning <ted.dunning@gmail.com> wrote:
> 
>> The order of the singular values and vectors should tell you.
>>
>> For others who might be curious, the singular value decomposition breaks a
>> matrix A into three factors
>>
>>     A = U S V'
>>
>> Both U and V are orthonormal so that U' U = I and V' V = I.  S is diagonal.
>>
>> An eigenvalue decomposition decomposes a square matrix into two parts, one
>> repeated
>>
>>     A = U S U*
>>
>> If A is symmetric, then these are real matrices and U* = U'.
>>
>> If A is symmetric, we can also decompose it using a Cholesky transformation
>>
>>     A = R' R
>>
>> Where R is upper (right) triangular.  We can then decompose R with SVD.
>>  This gives us:
>>
>>     A = R' R
>>     R = U S V'
>>     R' R = (U S V')' (U S V') = V S U' U S V' = V S^2 V'
>>
>> a nice convenience is that S^2 is also diagonal and contains the elements
>> of S, just squared.
>>
>> So the answer for Tharindu is that the elements of V are not changed or
>> re-ordered and neither are the elements of S.
>>
>>
>> On Mon, Jan 6, 2014 at 10:22 PM, Tharindu Rusira
>> <tharindurusira@gmail.com>wrote:
>>
>>> Hi,
>>> I am currently working with SingularValueDecomposition class and I like
>> to
>>> clarify the following.
>>>
>>> My goal is to find eigenvalues and corresponding eigenvectors of a
>> matrix.
>>> I know how to calculate eigenvalues and eigenvectors using svd but is
>> there
>>> a way to keep track of which eigenvector corresponds to which eigenvalue?
>>>
>>> Thanks,
>>> --
>>> M.P. Tharindu Rusira Kumara
>>>
>>> Department of Computer Science and Engineering,
>>> University of Moratuwa,
>>> Sri Lanka.
>>> +94757033733
>>> www.tharindu-rusira.blogspot.com
>>>
>>
> 
> 
> 


Mime
View raw message