Visualization of PC1, 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.00000008400919, 0.00000000266929, 0.00000007471587, 
          0.02366036580526, -0.33686300611536, 0.26552985499673, 
          0.71159706670184, -0.09212998990006, 
          0.36788627938139, -0.17975515034398, 
          0.11533949184441, -0.08012944589057, -0.08400704435231, 
          0.21639318461344, 0.11019160921661, 0.01862571406697, 
          0.06522580640565, -0.06849828173244, 
          0.06113098571537, -0.11258963348680, 0.00718397435478, 
          0.07333370285521, 0.04936425010908, 
          0.05899709660051, -0.01263175581008, 0.02704439991530, 
          0.00412472714858, -0.05017168649691, -0.00515722617763, 
          0.00664434011750, 0.01855680523859, 
          0.01712625628000, -0.01929957382938, 0.03470442744668, 
          0.01499603027405, 0.01274059925867, -0.01784702755469, 
          0.00634163489830, -0.01044793067820, 
          0.00564762976611, -0.01762031222549, 0.01825398416081, 
          0.01913996523226, 0.02005075305983, -0.01588916459942, 
          0.00022600366413, -0.01530686550132, 
          0.01193562023254, -0.01420971327829, 0.00821340284740, 
          0.01039235849096, -0.00194398872269, -0.01269901051971, -0.01245671641619, -0.01250278819588, 
          0.00762433198554, -0.00018530608816, 0.00459059247618, 
          0.00480759992932, -0.00790349503492, -0.01119190649501, -0.00904925089367, 0.00343415508336, 0.00383113153417, 
          0.00898523882170, -0.00169608491171, -0.00020245363363, -0.00378829707628, -0.00536364801414, 0.00044508277057, 
          0.00299730290255, -0.00295083322657, 
          0.00309142718734, -0.00595915038040, 
          0.00191863026551, -0.00131476009871, 0.00181570271675, 
          0.00430844017980, 
          0.00275743549949, -0.00530364216871};

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