Eigenvalue/vectors order

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

xprimexinverse
Posts: 41
Joined: Fri Sep 18, 2015 11:41 am
Location: Dublin, Ireland
Contact:

Eigenvalue/vectors order

Postby xprimexinverse » Sun May 08, 2016 7:29 am

Hi,

I am using the @eigenvalues() and @eigenvectors() functions and have a question regarding how their outputs are ordered. I am using EViews version 9.5.

Quoting the EViews manpages for @eigenvectors,
"The eigenvalues are arranged in ascending order, and the columns of the eigenvector matrix correspond to the sorted eigenvalues."
I would like, instead, to have the eigenvalues arranged in descending order by absolute value, and the columns of the eigenvector matrix correspond to the newly sorted eigenvalues.

Could a demonstration please be provided? Fundamentally, it's a problem about rearranging the columns of a matrix according to an indexing scheme.

For example, suppose I have a symmetric matrix called sym1.

Code: Select all

' Solve eigenvalue problem vector evals = @eigenvalues(sym1) matrix evecs = @eigenvectors(sym1) ' Sort eigenvalues in descending order by absolute value vector evals2 = @sort(@abs(evals),"d") ' Sort columns of the eigenvector matrix to correspond to the newly order eigenvalues ' Insert code here
My attempt is as follows.

Code: Select all

vector idx = @ranks(evals2, "a", "i") matrix evecs2 = @rapplyranks(evecs,idx)
This nearly completes the task, but I also need to take into account any conversions made by the @asb() function.

For example, if one of the eigenvalues was negative, the @abs() function would, in effect, multiply this by negative one. I require the same transformation to be applied to the corresponding columns of the eigenvector matrix. How do I achieve this?

Graeme

-- Ah! I think I have it, I can just use something like @egt(evals,@zeros(@rows(evals))) and go from there. But, does seem like overkill!?

xprimexinverse
Posts: 41
Joined: Fri Sep 18, 2015 11:41 am
Location: Dublin, Ireland
Contact:

Re: Eigenvalue/vectors order

Postby xprimexinverse » Sun May 08, 2016 8:38 am

I'll answer this myself since I think I figured it out; however, suggestions are welcome.

By the way, the context of this is in programming Johansen's estimator.

Here's my proposed solution.

Code: Select all

' Solve eigenvalue problem vector evals = @eigenvalues(sym1) matrix evecs = @eigenvectors(sym1) ' Create "multiplication" matrix vector pos = @sort(@egt(evals,@zeros(@rows(evals))),"d") for !i = 1 to @rows(pos) if pos(!i) = 0 then pos(!i) = -1 endif next matrix mult = @makediagonal(pos) ' Sort eigenvalues in descending order by absolute value vector evals2 = @sort(@abs(evals),"d") ' Sort columns of the eigenvector matrix to correspond to the newly order eigenvalues vector idx = @ranks(evals2, "a", "i") matrix evecs2 = @rapplyranks(evecs,idx) ' Use "multiplication" matrix to perform the -1 transformations matrix evecs3 = @transpose(mult * @transpose(evecs2))
Graeme


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests