Last active
December 26, 2018 15:10
-
-
Save prerakmody/9072cf287838f081f745d38c66021f4d to your computer and use it in GitHub Desktop.
PRTOOLS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Loading data points | |
data = hall; | |
scatterd(hall); % 14 clusers || 3 clusters | |
o2c = interactclust(data,'a'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = gendats([20, 20], 2, 6); % gendats(N, D, M) --> N=length, D=dimensionality, M=distance between means | |
disp(size(data)); | |
scatterd(data); | |
i = 10; disp(+data(i,:)); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Saving NIST dataset | |
clc; | |
m = prnist([0],[1:40:1000]); % get the dataset | |
a = im_box(m,0,1); | |
a = im_resize(a,[28 28]); | |
tmp = reshape(getdata(a{1}), [28 28]); % get a single digit | |
disp(size(tmp)) | |
figure; imshow(tmp) | |
imwrite(tmp,'image.png'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Using the PR Dataset %% | |
% Verift the libraries are in path | |
>> help prdata | |
>> help prdatasets | |
>> help prdatafiles | |
% random sample dataset | |
clc | |
X = rand(10,2); | |
Y = randi([0,1], 10,1); | |
data = prdataset(X,Y); | |
>> getsize(data) | |
>> struct(data) | |
>> scatterd(data, 'legend') | |
clc | |
data = kimia_images; | |
>> methodsview(data) % gives the methods of an Matlab Object. In this situation the prdataset class | |
>> getlablist(data) % gives you the unique set of labels | |
>> getsize(data) % gives you (num_rows, num_cols, num_classes_unique) | |
>> show(data(100,:)) % gives you a plot of the 100th object | |
>> clc | |
>> x = im_features(data, data, {’Area’,’Perimeter’,’Eccentricity’}); | |
>> getsize(x) % gives you N objects with 3 features | |
>> scatterd(x(1:100,:), 'legend') % scatter plot of first 100 objects and Area wrt Perimeter | |
>> scatterd(x(1:100, [2,3]), 'legend') % scatter plot of first 100 objects and Perimeter wrt Eccentricity | |
>> x_sub = seldat(x, [3,16]) % gives you classses - 3 and 16 from the feature set | |
>> data_tmp = seldat(data, [3,16] | |
>> getsize(data_tmp) | |
>> show(data_tmp) | |
>> struct(data_tmp) | |
>> data_tmp_image = data2im(data_tmp, 15); % select the 15th object from data_tmp and convert to a square matrix | |
>> figure; imagesc(data_tmp_image); % plot that single image | |
% Image manipulations | |
>> data_tmp = seldat(data, [3:3:18]) | |
>> getsize(data_tmp) | |
>> data_tmp_images = im_box(data_tmp, 0, 1) % did not quite understand this | |
>> figure(1); show(data_tmp_images); | |
>> data_tmp_images_rotate = im_rotate(data_tmp_images) % Execution is postponed until data is needed | |
>> figure(2); show(data_tmp_images_rotate); | |
>> data_tmp_image_resize = im_resize(data_tmp_image); % Execution is postponed until data is needed | |
>> figure(3); show(data_tmp_image_resize); | |
>> showfigs; | |
>> preproc = im_box([],0,1)*im_rotate*im_resize([],[20 20])*im_box([],1,0); | |
>> data_tmp_manipulations = ddata_tmp * preproc; | |
>> figure; show(data_tmp_manipulations); | |
% Centres of gravity | |
>> data_tmp_2 = seldat(data_tmp, 2) | |
>> getsize(data_tmp_2) | |
>> data_tmp_2_manipulations = data_tmp_2 * preproc | |
>> getsize(data_tmp_2_manipulations) | |
>> figure; show(data_tmp_2_manipulations(1,:)); % just check what the images look like now | |
>> data_tmp_2_mani_mean = im_mean(data_tmp_2_manipulations) | |
>> data_tmp_2_mani_mean_vals = double(data_tmp_2_mani_mean) % apply the conversions above | |
>> scatterd(data_tmp_2_mani_mean_vals) | |
>> figure(1); histogram(data_tmp_2_mani_mean_vals(:,1), 10); | |
>> figure(2); histogram(data_tmp_2_mani_mean_vals(:,2), 10); | |
>> showfigs; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X = rand(10,2) | |
Y = randi([0,1], 10,1) | |
data = dataset(X,Y) | |
>> methodsview(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Study the histogram | |
>> clc | |
>> hist help | |
>> hist(rand(100),10); | |
>> hist(randi([-5,5],100),-5:5); | |
% Study PRTOOLS - Gauss | |
>> a = gauss(100, 0, 1); % 100 objects of mean=0 and variance=1 | |
>> +a | |
>> a = gauss(10, 0); +a | |
>> plot(+gauss(1000,5)') | |
>> y = pdf('Normal', +gauss(1000,0,1)', 0, 1); | |
>> plot(y) %line plot and hence does not make sense | |
>> scatter([1:length(y)], y); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim Documents/MATLAB/startup.m | |
%% Startup file to add packages | |
% PRtools | |
addpath('/home/__/Pattern/Code/packages/prtools') | |
% PRDatasets | |
addpath('/home/__/Pattern/Code/packages/prdatasets') | |
addpath('/home/__/Pattern/Code/packages/kimia') | |
addpath('/home/__/Pattern/Code/packages/coursedata') | |
% General | |
addpath(genpath('/home/__/Pattern/Code/packages/prtools')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Data | |
clc; | |
data = gendats([250, 250], 2, 2); | |
[trn,tst] = gendat(data,0.1); % 50 training points | |
fprintf('\nSize of train : %d,%d || Size of test : %d,%d', size(trn), size(tst)); | |
%% 7.1 a) | |
for i=1:12 | |
for j=1:50 | |
data = gendats([250, 250], 2, 2); % make sure the datasets aren't too far away | |
[trn,tst] = gendat(data,0.1); % 50 training points | |
classifier = treec(trn, 'infcrit', i); | |
[e,c] = testc(tst, classifier); | |
fprintf('\nPruning : %d || Error : %f || Incorrect Objects : %d,%d',i, e, c); | |
end | |
end | |
for i=1:12 | |
for j=1:1 | |
data = gendats([250, 250], 2, 2); % make sure the datasets aren't too far away | |
% data = gendatb([250, 250]); % banana dataset | |
% data = gendatd([250, 250], 2, 0.5); % difficult dataset | |
[trn,tst] = gendat(data,0.1); % 50 training points | |
classifier = treec(trn, 'infcrit', i); | |
[e,c] = testc(tst, classifier); | |
fprintf('\nPruning : %d || Error : %f || Incorrect Objects : %d,%d',i, e, c); | |
figure; | |
scatterd(tst); | |
plotc(classifier); | |
title(['Prune : ',num2str(i)]); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment