An Example Script for Gaussian Mixtures

names={'ENGY','TIME'}; min_std = [.1 .1]; NMODE=1; gparm1=init_gmix(data1,NMODE,names,min_std);The first line assigns names to the two dimensions. We have chosen to call them "ENGY" and "TIME". The next line assigns the parameters, as discussed in section 13.2.4. The training data samples are stored in the variable

gparm1=gmix_trainscript(gparm1,data1,150);The log likelihood (

Once
`software/gmix_trainscript.m` converges, you should
should see the graph on the left of Figure 13.13.

Marginalization is a simple matter for Gaussian mixtures. Let . To visualize on the plane, for example, we would need to compute

gparm_out = gmix_strip(gparm_in, [2 4]);where the second argument indicates that we want to retain the second and fourth dimensions. Using this method, the marginal distribution of any 2-dimensional plane is easily computed. Stripping is handled automatically by

Press once more and the intensity plot is replaced by
a contour plot of the modes (on the right of Figure 13.13.
The contour plot is obtained by the fourth argument to
`software/gmix_view2.m`.
The complete syntax of
`software/gmix_view2.m` is

[p,xp,yp]=gmix_view2(gparm1,data1,idx1,idx2,[do_ellip],[M],iplot);where

Information about the Gaussian
mixture may be printed by calling
`software/gmix_show.m`.
This information, which includes the mode
weights, means, and determinants,
can be directly compared with Figure 13.13.
The true means are
(2,3) and (.5,.5), and the true determinants are 1.44 and 1.0, respectively.
Generally, if the algorithm results in just 2 modes, the
parameters agree very closely. The inclusion of a third or fourth mode
makes it difficult to see the correspondence. But,
nevertheless, the PDF approximation is good
as evidenced by the intensity plot. You
can run
`software/gmix_example.m` again and each time the
result will be a little different. But always,
the intensity plot and the PDF approximation is excellent.

Press the key once more and Figure 13.14 will be plotted.

This figure shows the 1-dimensional marginals for each dimension displayed along with the histograms. It is the result of calling[pdf,xp,h,xh]=gmix_view1(gparm,data,idx,nbins);If called without any output arguments, the plot will automatically be generated. Input

Press a key once more and Figure 13.15. This figure
demonstrates the function `gmix_cond` (See Section
13.2.6) which
creates conditional PDFs from the original Gaussian mixture.
Rather than using Bayes rule explicitly to compute
the conditional PDF of x given that ,

Press a key once more and Figure
13.16 is shown. This figure plots the original data
again in green and some synthetic data created
by
`software/gmix_makedata.m` in red. This demonstrates a convenient
aspect of GM approximation: generating synthetic data
is simple.

Press a key once more and Figure 13.17 appears.

We now have two data sets. We will now build a classifier using Gaussian mixtures. The first step is to train a second parameter set on the second data set. This time, we will use the
To classify, it is necessary to compute the
log-likelihood of test data. This is done using
`software/lqr_evp.m`. The name of the subroutine
was not thought up logically, but evolved from
(l)og-likelihood (ev)aluation
from the (p)arameters, and the fact that the
(QR) decomposition is involved in the covariance estimates!
The calling syntax is

loglik = lqr_evp(gparm1,data1,0);If the third argument was 1, the routine would return a matrix of log-likelihoods where each column is from one of the mixture modes. The zero forces the modes to be combined with the apropriate weights into the GM approximation. The ROC curve is shown in Figure 13.19. Refer to the listing for details.

Baggenstoss 2017-05-19