Download and unzip package mnist.zip. Then, type the following:
data_dir = '.'; load_test;After you execute those commands, you have the following variables defined in your environment: test_digits, and test_labels. Variable test_digits contains 10,000 images of handwritten digits. Each image is a 28x28 matrix, whose entries have values between 0 and 255. To define a variable equal to the i-th image, to see the i-th image type, and to see the class label of the i-th image, type
i = 432; %example value for i var = test_digits(:,:,i); imshow(var); test_labels(i);In order to use HMMs to recognize digits, you will need to represent each image of a digit as a sequence. To make life simple, you will convert every image to a sequence of 28 numbers, such that the j-th number is the sum of intensities of all pixels in the j-th row of the image.
Given this representation, you will build an HMM for each of the 10 digit classes. Each HMM will consist of 28 states. Each state will correspond to a row of the image. The observation density for that state has to be appropriate for images of the class that that particular HMM represents. You can use a Gaussian to represent each density, but you can use other types of distributions if you prefer. However, the actual parameters of each distribution (e.g., the mean and variance of each Gaussian) have to be learned from training data. Use the first thousand images of test_digits as training data to learn those distributions.
Then, after you construct your 10 HMMs, you will use them to classify images. Report results on the second thousand images (images 1001-2000) stored in test_digits. Report both the classification error rate, and the confusion matrix (a 10x10 matrix whose (i,j) entry says how many test images of class i were classified as class j).