Local definitions

General definitions

Turn off annoying warnings

Off[General :: spell] ; Off[General :: spell1] ;

Load necessary packages

<<Statistics`MultinormalDistribution` ; <<Statistics`MultiDescriptiveStatistics` <<Graphics`Colors` ; <<Graphics`Graphics` ;

<<Statistics`DataManipulation` ;

Principal Component Analysis (PCA) definitions

Extract principal components

PCA[data_] := Module[{μ, d2, s}, μ = Mean[data] ; d2 = (# -  ... #62371;s = Transpose[d2] . (d2)/Length[d2] ;  {μ, Eigenvectors[s], Eigenvalues[s]}] ;

Convert data to n PCA coefficients

PCAConvert[data_, pca_, n_] := Module[{μ, pcs, evs, d2},  {μ, pcs, e ...  = pca ; d2 = (# - μ) & /@ data ;  (Take[pcs, {1, n}] . #) & /@ d2] ;

Plot principal components (2d and 3d)

PCAPlot[pca_, scale_:1, style_: {Black}, opts___] := Module[{μ, pcs, evs, g1, g2, ... Automatic, PlotRangeAll, opts], Show[Graphics3D[{g1, g2}], PlotRangeAll, opts]]] ;

Fisher linear discriminant

Determine Fisher discriminant line

Fisher[data1_, data2_] := Module[{m1, m2, S1, S2, SW, w1}, m1 = Mean[data1] ;  ... + S2)/(Length[data1] + Length[data2]) ; w1 = Inverse[SW] . (m1 - m2) ; w1/Sqrt[w1 . w1]] ;

Project data onto Fisher discriminant line

ProjectFisher[w_, data_] :=  {w . #} &/@data ;

Visualize projections (both Fisher and first principal component)

VisualizeProjections[w_, data1_, data2_, style1_, style2_, scale_: {1, 1}, opts___] :=  ... g4, g5}], AspectRatioAutomatic, FrameTrue, PlotRangeAll, opts] ] ;

Compute 1D pdfs

ComputePDF1D[data_, which_:Red] := Module[{colors, pos, d2}, colors = {Red, Gr ... ;/@data] ; stats = {Mean[d2], StandardDeviation[d2]} ; pdf1D[stats, x] ] ;

One-dimensional decision boundary between Gaussian pdfs

ComputeDecisionBoundary1D[pdf1_, pdf2_, x_:x, range_: {0, 255}] := Module[{sol, lpdf1, ...  ≥range[[1]] && sol[[1]] ≤ range[[2]], sol // First, sol // Last]] ] ;

Error for a discriminant line over training set

RowBox[{RowBox[{ErrorOverTrainingSet[w_, data1_, data2_], :=, , RowBox[{Module, [, Row ... 2513;1, ,, 0., ,, , freqs[[1]]/(Plus @@ freqs) * 100 // N}], ]}]}]}], , ]}]}], ;}]


Created by Mathematica  (October 20, 2003)