Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the MATLAB solution below for the question above. I need to change the code below to something else, but I need the solutions

image text in transcribedimage text in transcribed

Here is the MATLAB solution below for the question above. I need to change the code below to something else, but I need the solutions to match each other. (Also try not to copy answer posted on chegg already)

% % Pb 1.10 % clc; clear all; close all; % reset matlab load mnist_train % load data ns = 500; % nb of images to be used ng = 20; % nb of groups digits = digits(:, 1:ns); % use the first ns images group = randi(ng, 1, ns); % randoml initial group assignment z = []; DJ = 1; J0 = 0; it =0; cvg=[]; eps = 1e-5; ifg = 0; % Initialization while DJ>eps it = it+1; % iteration # % step 2 of k-means algorithm 4.1 for i=1:ng I = find(group == i); M = digits(:,I); z(:,i) = mean(M,2); end %% plot the first 3 results if (ifg 1.10 The k-means algorithm. In this exercise we apply the k-mcans algorithm to the example in $4.4.1 of the textbook Download the file mnist train.mat from the course website and load it in MATLAB or Octave using the command load mnist-train. This creates two variables: a 784 60000 matrix digits and a 1 x 60000 matrix labels. We will not need labels. Each column of digits is a 28 28 grayscale image, stored as a vector of length 282 784 with elements between 0 and 1 (0 denotes a black pixel and 1 a white pixel). Figure 4.6 in the book shows the first 25 images. To display the image in the ith column of digits you can use the commands 6 X - reshape (digits(:,i), 28, 28); imshow (X) ; The first line converts column 1 of digits to a 28 28 matrix. The second command displays the matrix as an image. To speed up the computations we will use only the first 10000 digits: digits digits(:, 1:10000) You are asked to apply the k-means algorithm to this set of N 10000 vectors, with k 20 groups, and starting from a random initial group assignment (as opposed to starting from 20 randomly generated group representatives, as in Algorithm 4.1 (page 72 73) In the following list of MATLAB hints and comments we assume that the 20 group representatives are stored as columns of a 784 20 natrix Z, and that the group assignment is represented by a 1 10000 matrix (i.e., row vector) group. The ith element group(i) is an integer between 1 and 20, with the index of the group that column i of digits is assigned to

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions