Gaussian modeling definitions

One-dimensional Gaussian modeling

Gaussian PDF

gaussian1D[data_, x_] := PDF[NormalDistribution[Mean[data], StandardDeviation[data]], x] // Simplify ;

Log of Gaussian PDF

logGaussian1D[data_, x_] := Log[gaussian1D[data, x]] // PowerExpand ;

One-dimensional Gaussian

pdf1D[{μ_, σ_}, x_:x] := PDF[NormalDistribution[μ, σ], x] // Simplify ;

Log-likelihood function for two-dimensional Gaussian

logpdf1D[{μ_, σ_}, x_:x] := Log[PDF[NormalDistribution[μ, σ], x] // Simplify] // PowerExpand ;

One-dimenisonal Gaussian visualization

One-dimensional  pdf plot

PlotGaussianPDF1D[pdf_, pr_, x_, opts___] :=  Plot[pdf, {x, pr[[1]], pr[[2]]}, PlotRangeAll, FrameTrue, opts] ;

Plot two one-dimensional pdfs

ShowTwoGaussianPDFs1D[pdf1_, pdf2_, pr_, x_, opts___] := Module[{g1, g2, g3, g4}, > ... df2, pr, x, nS, PlotStyle {Blue, Thickness[.01]}, opts] ; Show[g1, g2] ] ;

Two-dimensional Gaussian modeling

Gaussian PDF

gaussian[data_, {x_, y_}] := PDF[MultinormalDistribution[Mean[data], CovarianceMatrix[data]], {x, y}] // Simplify ;

Log of Gaussian PDF

logGaussian[data_, {x_, y_}] := Log[gaussian[data, {x, y}]] // PowerExpand ;

Equal scalar variances in both dimensions

gaussianScalar[data_, {x_, y_}] := Module[{μ, Σ}, μ = Mean[data ...  * IdentityMatrix[2] ; PDF[MultinormalDistribution[μ, Σ], {x, y}] // Simplify] ;

Log of Gaussian PDF with scalar variance

logGaussianScalar[data_, {x_, y_}] := Log[gaussianScalar[data, {x, y}]] // PowerExpand // Chop ;

Diagonal covariance matrix

gaussianDiagonal[data_, {x_, y_}] := Module[{μ, Σ}, μ = Mean[da ... data])/Length[data]] ; PDF[MultinormalDistribution[μ, Σ], {x, y}] // Simplify] ;

Log of Gaussian PDF with diagonal covariance matrix

logGaussianDiagonal[data_, {x_, y_}] := Log[gaussianDiagonal[data, {x, y}]] // PowerExpand // Chop ;

Log-likelihood function for two-dimensional Gaussian

logpdf[μ_, Σ_, x_:x, y_:y] := Log[PDF[MultinormalDistribution[μ, Σ], {x, y}] // Simplify] // PowerExpand ;

Two-dimenisonal Gaussian visualization

Three-dimensional pdf plot

PlotGaussianPDF[pdf_, pr_, x_, y_, opts___] :=  Plot3D[pdf, {x, pr[[1, 1]], pr[[1, 2]] ... y, pr[[2, 1]], pr[[2, 2]]}, PlotPoints40, MeshFalse, PlotRangeAll, opts] ;

Contour pdf plot

ContourPlotGaussianPDF[pdf_, pr_, x_, y_, opts___] :=  ContourPlot[pdf, {x, pr[[1, 1]], pr[[1, 2]]}, {y, pr[[2, 1]], pr[[2, 2]]}, PlotPoints40, PlotRangeAll, opts] ;

Plot two classes in graphics array

ShowTwoGaussianPDFs[pdf1_, pdf2_, pr_, x_, y_, opts___] := Module[{g1, g2, g3, g4}, &# ...  FrameTicksNone, nS] ; Show[GraphicsArray[{{g1, g3}, {g2, g4}}], opts] ] ;

Plot one classification region for two classes

PlotClassificationRegion[pdf1_, pdf2_, pr_, x_, y_, flag_, color_, opts___] := Module[ ... in, xmax}, {y, ymin, ymax}, PlotRangeplotRange, opts] /. Hue[1/2] color] ;

Plot both classification regions for two classes

PlotTwoClassificationRegions[pdf1_, pdf2_, pr_, x_, y_, colors_, opts___] := Module[{g ... ficationRegion[pdf1, pdf2, pr, x, y, -1, colors[[2]], nS] ; Show[g1, g2, opts] ] ;

Plot classification for two Gaussian pdfs with base graphics overlay

ShowTwoClassificationRegions[pdf1_, pdf2_, pr_, x_, y_, colors_, gbase_, opts___] := M ... nS] ; If[gbase  False, Show[g1, opts],, Show[g1, gbase, opts]] ] ;

Plot classification for two Gaussian pdfs from Gaussian parameters

RowBox[{RowBox[{ShowDecisionBoundary[μ1_, Σ1_, μ2_, Σ2_, pr_, cRegion_, cP ...  PlotRangeplotRange, FrameTrue, AxesFalse, opts]}]}], , ]}]}], ;}]

Three-dimensional decision regions

Log-likelihood (3d)

logpdf3D[μ_, Σ_, x_:x, y_:y, z_:z] := Log[PDF[MultinormalDistribution[μ, Σ], {x, y, z}] // Simplify] // PowerExpand ;

Three-dimensional decision surface

RowBox[{RowBox[{RowBox[{ShowDecisionSurface, [, RowBox[{μ1_, ,,  , Σ1_, ,,  , μ ... gf = Show[g1, yS, PlotRangerange, ImageSize288, AxesFalse]]}], ;}]


Created by Mathematica  (September 8, 2003)