Re: [eigen] ordering of eigenvalues of EigenSolver |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] ordering of eigenvalues of EigenSolver
- From: Jose Luis Blanco <joseluisblancoc@xxxxxxxxx>
- Date: Tue, 8 Feb 2011 23:05:39 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=r+V7ib1f5xOBWgjc62gMqTQPmLpaq6OxZ4VhdoZPTRA=; b=t0adzVxq6Ykiy43UrwsU0mDO3ZIMZigWIbbqhgtlv5I3bzpOaIBYp7UrV1kylYuxPf 7u5pbkV3Hm7B+5+9ckArUv6MRMRmqfFZ38yM/n7xJ1W2KBAiR0Laau+8KWFPAGEaVWa9 iRexUTQFPDycZUo0KywIyk9VWmREukfTI7tZ0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=lhq2ibyqUBN+r2JOEQxE8gJ4cI/qGWdSrC4OjM8BptvC5D6ZynI/n6h9faPJ167/o2 2rEU6wr9v8HC7QwOqNG2RLuC+sE+fEENg0ikYBoEUptneAeIWrFSF6YUNy6cZjhyVmKA w/A+HKd1SAQBVHMcXdCJrQIu/7EJPskTRPwbw=
Susane,
This is the code I've been using for a while to do the sorting.
In its context it's intended to live as an extension to EigenBase, but
you could easily adapt it to your needs:
Perhaps it could be optimized, but it's tested and works ;-)
template <class Derived>
template <class MATRIX1,class VECTOR1>
EIGEN_STRONG_INLINE void Eigen::MatrixBase<Derived>::eigenVectorsVec(
MATRIX1 & eVecs, VECTOR1 & eVals ) const
{
Eigen::EigenSolver< Derived > es(*this, true);
eVecs = es.eigenvectors().real(); // Keep only the real part of complex matrix
eVals = es.eigenvalues().real(); // Keep only the real part of complex matrix
// Sort by ascending eigenvalues:
std::vector<std::pair<Scalar,Index> > D;
D.reserve(eVals.size());
for (Index i=0;i<eVals.size();i++)
D.push_back(std::make_pair<Scalar,Index>(eVals.coeff(i,0),i));
std::sort(D.begin(),D.end());
MATRIX1 sortedEigs;
sortedEigs.resizeLike(eVecs);
for (int i=0;i<eVals.size();i++)
{
eVals.coeffRef(i,0)=D[i].first;
sortedEigs.col(i)=eVecs.col(D[i].second);
}
eVecs = sortedEigs;
}
Best,
Jose Luis
On Tue, Feb 8, 2011 at 6:08 PM, FMDSPAM <fmdspam@xxxxxxxxx> wrote:
> Am 08.02.2011 17:36, schrieb Milian Wolff:
>>
>> as I was teached: the ordering of eigen values is totally arbitrary and
>> depends on the implemented algorithm. Meaning: You have to sort them to
>> your
>> expectations.
>>
> fair enough.
> What is the most elegant way to do so in eigen(3)?
> --Frank
>
>
>
--
___________________________________________________________
Dr. Jose-Luis Blanco-Claraco
Dpt. Ing. Civil, Mat. y Fabric - Phone: +34 951 952435
E.T.S.I. Industriales - Despacho 2.037
Universidad de Malaga - Campus Universitario de Teatinos
29071 Malaga, Spain
https://sites.google.com/site/jlblancosite/
___________________________________________________________