comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/Zoubin/mfademo.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 echo on;
2
3 clc;
4
5 % This is a very basic demo of the mixture of factor analyzer software
6 % written in Matlab by Zoubin Ghahramani
7 % Dept of Computer Science
8 % University of Toronto
9
10 pause; % Hit any key to continue
11
12 % To demonstrate the software we generate a sample data set
13 % from a mixture of two Gaussians
14
15 pause; % Hit any key to continue
16
17 X1=randn(300,5); % zero mean 5 dim Gaussian data
18 X2=randn(200,5)+2; % 5 dim Gaussian data with mean [1 1 1 1 1]
19 X=[X1;X2]; % total 500 data points from mixture
20
21 % Fitting the model is very easy. For example to fit a mixture of 2
22 % factor analyzers with three factors each...
23
24 pause; % Hit any key to continue
25
26
27 [Lh,Ph,Mu,Pi,LL]=mfa(X,2,3);
28
29 % Lh, Ph, Mu, and Pi are the factor loadings, observervation
30 % variances, observation means for each mixture, and mixing
31 % proportions. LL is the vector of log likelihoods (the learning
32 % curve). For more information type: help mfa
33
34 % to plot the learning curve (log likelihood at each step of EM)...
35
36 pause; % Hit any key to continue
37
38 plot(LL);
39
40 % you get a more informative picture of convergence by looking at the
41 % log of the first difference of the log likelihoods...
42
43 pause; % Hit any key to continue
44
45 semilogy(diff(LL));
46
47 % you can look at some of the parameters of the fitted model...
48
49 pause; % Hit any key to continue
50
51 Mu
52
53 Pi
54
55 % ...to see whether they make any sense given that me know how the
56 % data was generated.
57
58 % you can also evaluate the log likelihood of another data set under
59 % the model we have just fitted using the mfa_cl (for Calculate
60 % Likelihood) function. For example, here we generate a test from the
61 % same distribution.
62
63
64 X1=randn(300,5);
65 X2=randn(200,5)+2;
66 Xtest=[X1; X2];
67
68 pause; % Hit any key to continue
69
70 mfa_cl(Xtest,Lh,Ph,Mu,Pi)
71
72 % we should expect the log likelihood of the test set to be lower than
73 % that of the training set.
74
75 % finally, we can also fit a regular factor analyzer using the ffa
76 % function (Fast Factor Analysis)...
77
78 pause; % Hit any key to continue
79
80 [L,Ph,LL]=ffa(X,3);
81