Visualization of Fisher Linear Discriminant Direction, Full (40 dim subspace), Normals vs. Schizos, for Major Axis Rescaled, Full Population, on raw Data scale,

Documentation

This Mathematica notebook allows visualization of a direction in the feature space, using an animation of shapes at (mean + t*axis), for various values of t around zero.  As input, we require both a mean vector and an axis vector.

To use, simply paste in the mean and axis in the "Input data: mean and axis" section, and evaluate the entire notebook (single left click on the rightmost blue bar, and shift+Enter) (also from the menus, Kernel->Evaluation->Evaluate Notebook).

To adjust the range of the plot, adjust the values for δ and α in the "Plot options" section, and evaluate all cells from there on (click and drag on a blue bar to highlight multiple cells, and press shift+Enter).

A warning: You may need to adjust the scale of perturbations off mean (the range of t values); this is the third argument to the FourierAnim function in the final plot.

Setup subroutines

Read in required libraries

Needs["Graphics`Colors`"];

Needs["Graphics`Animation`"];

Needs["LinearAlgebra`Orthogonalization`"];

plotFourierPt subroutine

Return the {x,y} coord corresponding to s (between 0 and 2Pi), using maxorder coefficients of c.
Assumes c holds at least 4*maxorder real numbers in the order: Re((Subscript[c, 1])),  Im((Subscript[c, 1])),  Re((Subscript[c, -1])),  
      Im((Subscript[c, -1])),  Re((Subscript[c, 2])),   ...

\(\(plotFourierPt[c_List, \ maxorder_, \ 
          s_]\  := \ \((\ 
		cplxPt = \ 
            Sum[\ \((c[\([4  n - 3]\)]\  + \ c[\([4  n - 2]\)] I)\)\ Exp[
                    n\ I\ s]\  + \((c[\([4  n - 1]\)]\  + \ 
                      c[\([4  n]\)] I)\)\ Exp[\(-n\)\ I\ s], \ {n, 1, \ 
                maxorder}\ ]; 
		{Re[cplxPt], \ 
            Im[cplxPt]}\ \ )\);\)\)

The main plotting routines

These functions return a Graphics object; use ShowPlot to actually display them

plotFourier[c_List, maxorder_] := ParametricPlot[Evaluate[plotFourierPt[c, maxorder, s]], {s, 0, 2Pi},
  Evaluate[plotFourierOptions], DisplayFunction->Identity];

plotFourier[c_List] := plotFourier[c, Length[c]/4];

multiplotFourier[c_List, maxorder_] := ParametricPlot[Evaluate[Map[plotFourierPt[#, maxorder, s]&, c]],
  {s, 0, 2Pi}, Evaluate[plotFourierOptions], DisplayFunction->Identity];

This is just a macro to set the right DisplayFunction

ShowPlot[g_Graphics]  :=  
        Show[g,  DisplayFunction -> $DisplayFunction];

Animate along an axis through the mean

FourierAnim[mymean_List,  offset_List,  length_ , numframes_]  :=  
      Table[plotFourier[mymean  +  t offset],  {t,  -length,  
          length,  2 length/numframes}]

Subroutine to convert from matlab format (flat, w00z) to the format plotFourier likes (flat, cplx)

cvtw00z[w_,x_,y_,z_] := { w+z, y-x, w-z, y+x }/2;

Flatw00zToFlatCplx[c_List]  :=  
        Flatten[Apply[cvtw00z,  Partition[c,  4],  {1}]];

Plot options

After modifying plotrange, reevaluate both cells, then reevaluate the plot.

plotrange  =  { {-δ,  δ},  {-α δ,  α δ} } /.  {δ -> 1.5,  α -> 
              1/2};

plotFourierOptions  =  {PlotRange  ->  plotrange,  
          AspectRatio -> Automatic,  PlotPoints  ->  50};

Input data: mean and axis

These come from Part 1 of the file Eigenvector.txt

mean  =  {1.00000000222222, 
          0.00000000074074, -0.00000000333333, -0.15425630925926, 
          0.05169293074074, -0.06879220814815, -0.23349342185185, 
          0.01942750444444, 0.02644838814815, 
          0.03411046925926, -0.00085310333333, -0.08502326592593, 
          0.00445768851852, -0.07443836148148, -0.03757112740741, -0.01314235111111, 0.02496162851852, 
          0.01744490370370, -0.00924242481481, -0.04486334851852, -0.01167827814815, -0.03341475777778, -0.00899276037037, -0.01361780259259, 0.02253759407407, -0.00057942185185, 
          0.00006088370370, -0.00850054296296, -0.00318135962963, 
          0.00169321407407, -0.00084379518519, -0.00596311259259, 
          0.00773305148148, -0.00597819814815, 0.00465755111111, 
          0.00234933962963, 0.00598151148148, 0.00743163703704, 
          0.00069807370370, -0.00276610370370, -0.00389088629630, 
          0.00083397370370, 0.00164261629630, 0.00180199777778, 
          0.00444316000000, 
          0.00138173074074, -0.00039679962963, -0.00024159888889, -0.00377818703704, 0.00526914814815, 0.00065971703704, 
          0.00101677000000, -0.00036303148148, -0.00219449666667, -0.00047574037037, -0.00019208111111, -0.00044444185185, 
          0.00261664407407, 
          0.00049623222222, -0.00022200925926, -0.00208886444444, -0.00130737259259, -0.00071002629630, -0.00066462074074, 
          0.00057646037037, -0.00057751666667, 
          0.00056463481481, -0.00094097407407, -0.00048834740741, 
          0.00000291777778, 0.00016308296296, -0.00028143740741, 
          0.00009326925926, -0.00091410851852, -0.00007459814815, -0.00054200000000, 0.00063818074074, 0.00034150111111, 
          0.00067547740741, -0.00047642111111};

axis  =  {-0.00000407554949, 0.00000127263632, 
          0.00000341973429, 0.07507025737867, -0.19955650914812, 
          0.01390480536036, 
          0.01657951076676, -0.07053699909848, -0.26779214174734, 
          0.26333131918711, 0.09009234990905, 
          0.13402244274608, -0.10007322091237, 0.13346209596251, 
          0.02049473850201, 0.08379012562328, 
          0.11821810735463, -0.06866357769443, 
          0.24758567480288, -0.02661954987771, -0.13486621527270, 
          0.11370590469900, -0.12533732631352, -0.19515927924857, 
          0.01458723035432, 0.22075598081712, 0.22164060671392, 
          0.06678438749465, 0.03036038357309, 0.08599914864447, 
          0.10829151087157, 0.11807676737470, 
          0.07735221727880, -0.04956277104195, 
          0.06056280641974, -0.04705178316792, 0.22042448000070, 
          0.00506856423750, 0.02213678993220, -0.02632999037474, 
          0.10945131056180, -0.10249289845493, 
          0.03863140699425, -0.18955443197197, 0.18252879094841, 
          0.01625844224468, 0.13666474127205, -0.13100040921165, 
          0.05579122287710, -0.01234604257784, -0.17571255153314, 
          0.03885313499097, 0.03150741092074, 0.11243651108269, 
          0.02511711710076, 0.25657825344557, -0.00952558232226, 
          0.16210917758840, -0.02731041393852, 
          0.16864045498512, -0.03706793331623, 
          0.05589957453102, -0.12496980391231, 0.00089510303786, 
          0.00251214936159, -0.04115738530253, -0.04269120422683, 
          0.05725767926231, -0.03929388866886, -0.00006536613112, -0.11616560728366, 0.10161683357152, 
          0.01721573306990, -0.07957901838393, 
          0.06736439133939, -0.07423809303929, 
          0.09678669759553, -0.02653506045251, -0.01813096092838, 
          0.02137394570252};

axis  =  Normalize[axis];

Plot the mean

ShowPlot[plotFourier[Flatw00zToFlatCplx[mean]]]

Animate the axis

The arguments to FourierAnim are the axis along which to move, the distance to move along that axis (+ and -), and the number of frames to generate.

Evaluating this cell generates many frames of output.  To view the animation, double-click on the second blue bar (from the left) in the output; this will shrink all the frames of output to show just the first frame.  Now double-click on the graphic; this should start playing the animation.  Animation controls should appear at the left of the bottom status bar; the second button makes the animation loop "ping-pong" style.

ShowAnimation[
      FourierAnim[Flatw00zToFlatCplx[mean],  Flatw00zToFlatCplx[axis],  
        0.1,  16]]