% file: build_euclid.m
%
% this script requires no arguments
%
% this script builds the original data sets, one of which has an elliptical
% shape and a mean of (-2, 2) and the other has a pear shape with a mean
% of (2, -2). after creating the sets, a number of analyses are performed
% on the sets including the calculation of the mean and covariance.
% routine to load and build the plots for hw #2 in the euclidean space. with
% these, a set of four sample points are classified as belonging to one
% of the two sets. the four sample points are:
%    (-1, -1); (0, 0); (1/2, 1/2); (1/2, -1/2)
%

% load the first data set
%
load_set_1;

% load the second data set
%
load_set_2;

% get the means for each set
%
mean_set_1=mean(euclid_set_1);
mean_set_2=mean(euclid_set_2);

% display the means to the user
%
fprintf('Mean of set 1 = [%.4f, %.4f]\n', mean_set_1(1), mean_set_1(2));
fprintf('Mean of set 2 = [%.4f, %.4f]\n', mean_set_2(1), mean_set_2(2));

% build the sample set
%
load_sample_set;

% determine the distance between each set and the sample points and classify
%
for samp_num = 1 : num_sample_points
	
	% compute the distance for each sample point
	%
	sample_distance_set_1 =	dist(mean_set_1, transpose(euclid_sample_set(samp_num,:)));
	sample_distance_set_2 = dist(mean_set_2, transpose(euclid_sample_set(samp_num,:)));

	% display the distances to the user
	%
	fprintf('The distance from sample point %d (%.4f, %.4f) to set 1 is: %.4f\n', samp_num,  euclid_sample_set(samp_num,1), euclid_sample_set(samp_num,2), sample_distance_set_1);
	fprintf('The distance from sample point %d (%.4f, %.4f) to set 2 is: %.4f\n', samp_num,  euclid_sample_set(samp_num,1), euclid_sample_set(samp_num,2), sample_distance_set_2);
	
	% assign the sample vector to a class if distance 2 is less than
	% distance 1 then assign to class 2, otherwise assign to class 1
	%
	if ((sample_distance_set_2 - sample_distance_set_1) < -1E-4) 
		fprintf('Sample point %d (%.4f, %.4f) belongs to set 2\n', samp_num,  euclid_sample_set(samp_num,1), euclid_sample_set(samp_num,2));
	else 
		fprintf('Sample point %d (%.4f, %.4f) belongs to set 1\n', samp_num,  euclid_sample_set(samp_num,1), euclid_sample_set(samp_num,2));
	end

	% print a blank line to separate the samples
	%
	fprintf('\n');
end

% end of script
%


