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  =  {0.99999999577465, 
          0.00000000042254, -0.00000000140845, -0.15265874436620, 
          0.05051707605634, -0.06959121563380, -0.23566859253521, 
          0.01841770549296, 0.02504751112676, 
          0.03545001084507, -0.00452289971831, -0.08314208704225, 
          0.00545232028169, -0.07516635943662, -0.03967742253521, -0.01263550084507, 0.02432813154930, 
          0.01841314887324, -0.00793547971831, -0.04315542014085, -0.01110062661972, -0.03424806577465, -0.00997004577465, -0.01400951478873, 0.02235066478873, -0.00055634633803, 
          0.00031299535211, -0.00816849971831, -0.00305151535211, 
          0.00108292000000, -0.00114177281690, -0.00645633408451, 
          0.00787526211268, -0.00631870070423, 0.00468007873239, 
          0.00181971619718, 0.00642344676056, 0.00725774338028, 
          0.00033030056338, -0.00271897239437, -0.00346696915493, 
          0.00029988901408, 0.00166032788732, 0.00120431774648, 
          0.00509558619718, 
          0.00156389971831, -0.00014830422535, -0.00034171577465, -0.00357382661972, 0.00491082211268, 0.00050473633803, 0.00110795901408, 
          0.00000952042254, -0.00171832591549, -0.00025740760563, -0.00044140380282, -0.00035070605634, 0.00281390267606, 
          0.00016366535211, 
          0.00014455901408, -0.00195638549296, -0.00106211915493, -0.00056562169014, -0.00060771816901, 
          0.00051153267606, -0.00022239112676, 
          0.00035875732394, -0.00069439746479, -0.00055557535211, 
          0.00008571070423, -0.00018296197183, -0.00020264000000, 
          0.00002939464789, -0.00077437957746, -0.00005848859155, -0.00063389633803, 0.00049846464789, 0.00028082816901, 
          0.00040762183099, -0.00026705014085};

axis  =  {0.00000491000033, -0.00000026580137, -0.00000528620113, 
          0.04584156794971, -0.16897240749752, -0.09752517400355, -0.02037067699823, -0.02903799700939, 0.10191628000031, 
          0.33096625206516, 0.02349969186659, -0.04333836300926, 
          0.12099591811490, 0.04439915672275, 0.05932408842232, 
          0.01638175128019, -0.16344316865461, -0.07589896711497, -0.14719615810992, -0.02168031332263, 0.05761105009255, 
          0.04243190689640, -0.08224217910477, -0.13424966238168, 
          0.07902471321615, 0.04117182039094, 
          0.21877833239323, -0.14567316306495, 0.05901485197812, 
          0.01457203954265, -0.04220779180112, 0.07022328157180, 
          0.07053250766516, 0.03130482296718, -0.04253992185254, 
          0.23063697680764, -0.13750826859381, 
          0.01826463814544, -0.10843260855029, 0.04495681998072, 
          0.10329045729439, -0.19074924288135, 
          0.00556969369942, -0.10765671018051, 
          0.01534429846113, -0.07288319740934, 
          0.15919243931690, -0.24743330948860, -0.01639854747746, -0.19851984867529, 0.06577299075030, 
          0.20612526478687, -0.05303692666888, -0.14030058435502, 
          0.00353852276515, 0.18604131645783, -0.02044945408049, 
          0.04295329841792, 
          0.02582979341321, -0.07408809211037, -0.11959083289004, -0.11600297052587, -0.12302085661116, -0.05544196525135, -0.00299301615127, -0.22257924101469, 0.13143145702067, 
          0.05283092696347, 0.02257671691462, 0.10634478935962, 
          0.12442860368955, -0.14547361258032, 
          0.01999382535797, -0.06406367248037, 0.16622889930196, 
          0.15452488076552, 0.08241740480521, -0.05615229727949, 
          0.03726818795823, 0.12521064055150};

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]]