Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Similar matrices->similar eigenvectors?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80401] Re: [mg80371] Similar matrices->similar eigenvectors?
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Tue, 21 Aug 2007 05:06:18 -0400 (EDT)
  • References: <14594541.1187598542998.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

I don't think it's possible to eliminate all discontinuities, but this may  
improve things:

Clear[normalize, eigensystem]
normalize[v : {(0.) ..., x_?Negative, ___}] := -v/Norm[v]
normalize[v_?VectorQ] := v/Norm[v]
normalize[m_?MatrixQ] := normalize /@ m
eigensystem[m_?MatrixQ] := Module[{e, vecs, vals, o},
   {vals, vecs} = Eigensystem[m];
   vecs = normalize@vecs;
   o = Reverse@Ordering@vals;
   {vals[[o]], vecs[[o]]}
   ]
eigensystem[m_?MatrixQ, k_Integer?Positive] :=
  eigensystem[m][[All, ;; k]]

distances2points[d_] := (n = Length[d];
   h = IdentityMatrix[n] - Table[1, {n, n}]/n;
   b = -h.(d*d/2).h;
   {vals, vecs} = eigensystem[b, 2];
   Point[Re[#]] & /@ Transpose[vecs*Sqrt[vals]])
Clear[d1, d2, d3, d4, d5, d6]; limits = {{{d1, 0, "1->2"}, 0,
    1}, {{d2, 0, "1->3"}, 0, 1}, {{d3, 0, "1->4"}, 0,
    1}, {{d4, 0, "2->3"}, 0, 1}, {{d5, 0, "2->4"}, 0,
    1}, {{d6, 0, "3->4"}, 0, 1}};
Manipulate[
  Graphics[distances2points[{{0, d1, d2, d3}, {d1, 0, d4, d5}, {d2, d4,
       0, d6}, {d3, d5, d6, 0}}], PlotRange -> {{-1, 1}, {-1, 1}}],
  Evaluate[Sequence @@ limits], LocalizeVariables -> False]

Replace eigensystem with Eigensystem in "distances2points", to get the  
original behavior.

Bobby

On Mon, 20 Aug 2007 02:38:50 -0500, Yaroslav Bulatov  
<yaroslavvb at gmail.com> wrote:

> In the default implementation of "Eigenvectors", the orientations seem
> arbitrary. Changing the matrix slightly could end up flipping the
> eigenvectors 180 degrees. A simple fix of telling eigenvectors to
> always be on one side of some arbitrary plane doesn't work because it
> will flip eigenvectors that are near-parallel to the plane with small
> changes in the matrix.
>
> I'm trying to make a demo of multi-dimensional scaling, and the result
> is that as I drag the slider, the points flip back and forth
> erratically.
>
> Basically I'd like to get a function g[mat] which returns eigenvectors
> of mat, and is continuous, what is the simplest way of achieving this?
>
> -----------
> distances2points[d_] := (n = Length[d];
>   (*nxn matrix of ones*)j = Table[1, {n, n}];
>   (*centering matrix*)h = IdentityMatrix[n] - j/n;
>   a = -d*d/2;
>   b = h.a.h;
>   (*Eigenvectors are returned with arbitrary orientation,
>   orient them to point in the same halfplane*)
>   orient[v_, orientvec_] := ((*1,1,1,1 halfplane is often ambiguous,
>     use random halfplane*)(*SeedRandom[0];
>     orientvec=RandomReal[{0,1},Length[v]];*)
>     If[Round[v, .1].orientvec > 0, -v, v]);
>   vecs = Eigenvectors[b][[1 ;; 2]];
>   (*vecs=orient[#,b[[1]]]&/@vecs;*)
>   vals = Eigenvalues[b][[1 ;; 2]];
>   Point[Re[#]] & /@ Transpose[vecs*Sqrt[vals]])
> Clear[d1, d2, d3, d4, d5, d6]; limits = {{{d1, 0, "1->2"}, 0,
>    1}, {{d2, 0, "1->3"}, 0, 1}, {{d3, 0, "1->4"}, 0,
>    1}, {{d4, 0, "2->3"}, 0, 1}, {{d5, 0, "2->4"}, 0,
>    1}, {{d6, 0, "3->4"}, 0, 1}};
> Manipulate[
>  Graphics[distances2points[{{0, d1, d2, d3}, {d1, 0, d4, d5}, {d2, d4,
>       0, d6}, {d3, d5, d6, 0}}], PlotRange -> {{-1, 1}, {-1, 1}}],
>  Evaluate[Sequence @@ limits], LocalizeVariables -> False]
>
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Interpolation of data to form a parametric curve
  • Next by Date: Re: Interpolation of data to form a parametric curve
  • Previous by thread: Re: Similar matrices->similar eigenvectors?
  • Next by thread: Re: Similar matrices->similar eigenvectors?