% % Written by: % -- % John L. Weatherwax 2007-07-01 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; clear all; %clc; randn('seed',0); rand('seed',0); addpath('../../../Nabney/Code/NETLAB/'); X = [ 2, 0 ; sqrt(2), sqrt(2) ; 0, 2 ; -sqrt(2), sqrt(2) ; -2, 0 ; -sqrt(2), -sqrt(2) ; 0, -2 ; sqrt(2), -sqrt(2) ]; x1 = X(:,1) + 2; x2 = X(:,2); plot( X(:,1), X(:,2), 'go', 'markersize', 8, 'markerfacecolor', 'g' ); hold on; plot( x1, x2, 'ro', 'markersize', 8, 'markerfacecolor', 'r' ); fn = '../../WriteUp/Graphics/Chapter14/chap_14_prob_5_plot'; %saveas( gcf, fn, 'epsc' ); % the entire data set: X_all = [ X; [ x1, x2 ] ]; n = size(X_all,1); labels = ones(n,1); % initialize the mixture of Gaussians to fit to this data (centers initialized to random values) nin = size(X_all,2); % state dimension ncentres = 2; % two Gaussians nclasses = 1; % only one class mixc = gmm(nin, ncentres, 'full'); % initialize the centers of each cluster using the k-means algo: options = foptions; options(14) = 5; mixc = gmminit(mixc,X_all,options); % Now learn the parameters (mean and covariance) of the data: options(1) = 1; % Print error values options(5) = 1; % Prevent collapse of variances options(14) = 15; % Number of iterations mixc = gmmem(mixc, X_all, options); % display the results: mixc mixc.centres(1,:) mixc.covars(:,:,1) mixc.centres(2,:) mixc.covars(:,:,2)