Local definitions

Random numbers from Gaussian mixture model

Uniform random number in range [0, 1]

RowBox[{RowBox[{RR,  , :=,  , RowBox[{Random, [, RowBox[{Real, ,,  , RowBox[{{, RowBox[{0., ,,  , 1.}], }}]}], ]}]}], ;}]

Random number generation helper functions

TransformProbabilityVector[prob_] := Module[{s = 0, len}, len = Length[prob] - 1 ; Join[Table[s = s + prob[[i]], {i, 1, len}], {1}] ] ;

PickOne[ priors_] := Module[{r}, r = RR ; (Position[(r <= #) & /@ TransformProbabilityVector[priors], True] // Flatten) // First] ;

Random number generation from Gaussian mixture model (1D)

RandomMixtureModelOne1D[{μ_, σ_, priors_}] := Module[{class}, class = PickOn ... ors] ;  {class, Random[NormalDistribution[μ[[class]], σ[[class]]]]} ] ;

RandomMixtureModel1D[{μ_, σ_, priors_}, n_] := Table[RandomMixtureModelOne1D[{μ, σ, priors}], {n}] ;

1D Gaussian mixture modeling

1D Mixture model PDF

mixturepdf1D[{μ_, σ_, priors_}, x_] := Plus @@ Table[PDF[NormalDistribution[μ[[i]], σ[[i]]], x] priors[[i]], {i, 1, Length[μ]}] ;

1D log mixture model PDF

mixturelogpdf1D[{μ_, σ_, priors_}, x_] := Log[mixturepdf1D[{μ, σ, priors}, x]] ;

Find best estimate for μ1 and μ2

likelihoodFunction1D[data_, params_] := Plus @@ (mixturelogpdf1D[params // N, #[[2]]] & /@ data) ;

estimateParams1D[data_, {μ_, σ_, priors_}] := Module[{mlf, μ1, μ2, ... #956;[[2]]}] ;  {{{μ1, μ2} /. sol[[2]] , σ, priors}, -sol[[1]]} ] ;

Special plotting functions

Plot 1D labeled data

PlotDataLabeled1D[data_, c1_, c2_, opts___] := Module[{colors}, colors = {c1,  ...  False}, FrameFalse, AspectRatioAutomatic, PlotRangeAll, opts] ] ;

Plot log-likelihood as a function of μ1 and μ2

PlotLogLikelihoodLocal[data_, {{μ1_, μ2_}, σ_, priors_}, opts___] := Mo ... #62371;ContourPlot[lf, {μ1, -6, 6}, {μ2, -6, 6}, PlotPoints30, opts] ] ;

PlotLogLikelihoodLocal2[data_, {{μ1_, μ2_}, σ_, priors_}, opts___] := M ... 1, g2, yS, PlotRangeAll, opts] ;  {First[est1][[1]], First[est2][[1]]} ] ;

PlotLogLikelihoodLocal3[data_, {{μ1_, μ2_}, σ_, priors_}, opts___] := M ... ) ; Plot3D[lf, {μ1, -6, 6}, {μ2, -6, 6}, PlotPoints30, opts] ] ;

Plot optimization algorithm trajectory

PlotTrajectory[pts_, color_, opts___] := Module[{g1, g2}, g1 = Graphics[{Point ...  color, Point /@ pts}] ; g2 = Graphics[{color, Line[pts]}] ; Show[g1, g2, opts]] ;


Created by Mathematica  (September 8, 2003)