wolffd@0: echo on; wolffd@0: wolffd@0: clc; wolffd@0: wolffd@0: % This is a very basic demo of the mixture of factor analyzer software wolffd@0: % written in Matlab by Zoubin Ghahramani wolffd@0: % Dept of Computer Science wolffd@0: % University of Toronto wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: % To demonstrate the software we generate a sample data set wolffd@0: % from a mixture of two Gaussians wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: X1=randn(300,5); % zero mean 5 dim Gaussian data wolffd@0: X2=randn(200,5)+2; % 5 dim Gaussian data with mean [1 1 1 1 1] wolffd@0: X=[X1;X2]; % total 500 data points from mixture wolffd@0: wolffd@0: % Fitting the model is very easy. For example to fit a mixture of 2 wolffd@0: % factor analyzers with three factors each... wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: wolffd@0: [Lh,Ph,Mu,Pi,LL]=mfa(X,2,3); wolffd@0: wolffd@0: % Lh, Ph, Mu, and Pi are the factor loadings, observervation wolffd@0: % variances, observation means for each mixture, and mixing wolffd@0: % proportions. LL is the vector of log likelihoods (the learning wolffd@0: % curve). For more information type: help mfa wolffd@0: wolffd@0: % to plot the learning curve (log likelihood at each step of EM)... wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: plot(LL); wolffd@0: wolffd@0: % you get a more informative picture of convergence by looking at the wolffd@0: % log of the first difference of the log likelihoods... wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: semilogy(diff(LL)); wolffd@0: wolffd@0: % you can look at some of the parameters of the fitted model... wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: Mu wolffd@0: wolffd@0: Pi wolffd@0: wolffd@0: % ...to see whether they make any sense given that me know how the wolffd@0: % data was generated. wolffd@0: wolffd@0: % you can also evaluate the log likelihood of another data set under wolffd@0: % the model we have just fitted using the mfa_cl (for Calculate wolffd@0: % Likelihood) function. For example, here we generate a test from the wolffd@0: % same distribution. wolffd@0: wolffd@0: wolffd@0: X1=randn(300,5); wolffd@0: X2=randn(200,5)+2; wolffd@0: Xtest=[X1; X2]; wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: mfa_cl(Xtest,Lh,Ph,Mu,Pi) wolffd@0: wolffd@0: % we should expect the log likelihood of the test set to be lower than wolffd@0: % that of the training set. wolffd@0: wolffd@0: % finally, we can also fit a regular factor analyzer using the ffa wolffd@0: % function (Fast Factor Analysis)... wolffd@0: wolffd@0: pause; % Hit any key to continue wolffd@0: wolffd@0: [L,Ph,LL]=ffa(X,3); wolffd@0: