Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f82d12c
commit c91d6ce
Showing
13 changed files
with
1,252 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function [data_matrix_with_lables,dist_matrix] = CS_data_generate(no_of_clusters,odds_matrix,total_no_of_points) | ||
%UNTITLED Summary of this function goes here | ||
% Detailed explanation goes here | ||
|
||
mean_x_matrix=500*randn(1,no_of_clusters); | ||
mean_y_matrix=500*randn(1,no_of_clusters); | ||
var_x_matrix=60*abs(randn(1,no_of_clusters)); | ||
var_y_matrix=60*abs(randn(1,no_of_clusters)); | ||
|
||
data_matrix_with_lables=zeros((ceil(total_no_of_points/sum(odds_matrix)))*sum(odds_matrix),3); | ||
|
||
l=1; | ||
while l<=length(data_matrix_with_lables) | ||
for j=1:no_of_clusters | ||
for k=1:odds_matrix(j) | ||
data_matrix_with_lables(l,:)=[mean_x_matrix(j)+var_x_matrix(j)*randn(1) mean_y_matrix(j)+var_y_matrix(j)*randn(1) j]; | ||
l=l+1; | ||
end | ||
end | ||
end | ||
|
||
random_permutation=randperm(length(data_matrix_with_lables)); | ||
data_matrix_with_lables=data_matrix_with_lables(random_permutation,:); | ||
|
||
% colors=['r.';'b.';'g.';'c.';'m.';'y.';'k.']; | ||
% figure; | ||
% for i=1:no_of_clusters | ||
% cluster_index=find(data_matrix_with_lables(:,3)==i); | ||
% plot(data_matrix_with_lables(cluster_index,1),data_matrix_with_lables(cluster_index,2),colors(i,:)); | ||
% hold on; | ||
% end | ||
% h=gcf; | ||
% saveas(h,'gmm_3_data_plot.bmp','bmp'); | ||
% | ||
% save('gmm_3_data.mat','data_matrix_with_lables'); | ||
|
||
% tic | ||
dist_matrix=zeros(length(data_matrix_with_lables),length(data_matrix_with_lables)); | ||
[len wid]=size(dist_matrix); | ||
|
||
for l=1:len | ||
diff_vector=data_matrix_with_lables(:,1:2)-[data_matrix_with_lables(l,1).*ones(len,1) data_matrix_with_lables(l,2).*ones(len,1)]; | ||
dist_matrix(l,:)=abs(diff_vector(:,1)+1i*diff_vector(:,2)); | ||
end | ||
% toc | ||
|
||
% figure; | ||
% imshow(dist_matrix,[min(min(dist_matrix)) max(max(dist_matrix))]); | ||
% h=gcf; | ||
% saveas(h,'distance_matrix_image.bmp','bmp'); | ||
% | ||
% save('dist_matrix.mat','dist_matrix'); | ||
|
||
end | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
% updated 10.11.2010 | ||
|
||
function [RV,C,I,RI,d]=VAT(R); | ||
% Example function call: [DV,I] = VAT(D); | ||
% | ||
% *** Input Parameters *** | ||
% @param R (n*n double): Dissimilarity data input | ||
% | ||
% *** Output Values *** | ||
% @value RV (n*n double): VAT-reordered dissimilarity data | ||
% @value C (n int): Connection indexes of MST | ||
% @value I (n int): Reordered indexes of R, the input data | ||
|
||
[N,M]=size(R); | ||
|
||
K=1:N; | ||
J=K; | ||
d=zeros(1,N-1); | ||
%P=zeros(1,N); | ||
|
||
%[y,i]=max(R); | ||
%[y,j]=max(y); | ||
I=1; | ||
J(I)=[]; | ||
[y,j]=min(R(I,J)); | ||
d(1)=y; | ||
I=[I J(j)]; | ||
J(J==J(j))=[]; | ||
C(1:2)=1; | ||
|
||
for r=3:N-1, | ||
[y,i]=min(R(I,J)); | ||
[y,j]=min(y); | ||
d(r-1)=y; | ||
I=[I J(j)]; | ||
J(J==J(j))=[]; | ||
C(r)=i(j); | ||
end; | ||
[y,i]=min(R(I,J)); | ||
d(N-1)=y; | ||
I=[I J]; | ||
C(N)=i; | ||
|
||
for r=1:N, | ||
RI(I(r))=r; | ||
end; | ||
|
||
RV=R(I,I); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
% updated 10.11.2010 | ||
|
||
function [RiV]=deciVAT(RV,RiV_old,point_to_remove_index) | ||
% Example function call: [RiV] = iVAT(RV); | ||
% | ||
% *** Input Parameters *** | ||
% @param R (n*n double): dissimilarity data input | ||
% @param VATflag (boolean): TRUE - R is VAT-reordered | ||
% | ||
% *** Output Values *** | ||
% @value RV (n*n double): VAT-reordered dissimilarity data | ||
% @value RiV (n*n double): iVAT-transformed dissimilarity data | ||
|
||
N=length(RV); | ||
|
||
|
||
RiV=zeros(N); | ||
RiV(1:point_to_remove_index-1,1:point_to_remove_index-1)=RiV_old(1:point_to_remove_index-1,1:point_to_remove_index-1); | ||
for r=point_to_remove_index:N, | ||
c=1:r-1; | ||
[y,i]=min(RV(r,1:r-1)); | ||
RiV(r,c)=y; | ||
cnei=c(c~=i); | ||
a=[RiV(r,cnei); RiV(i,cnei)]; | ||
[RiV(r,cnei),j]=max(a,[],1); | ||
RiV(c,r)=RiV(r,c)'; | ||
end; | ||
|
||
end |
152 changes: 152 additions & 0 deletions
152
inc-VAT_inc-iVAT_dec-VAT_dec-iVAT/distinguishable_colors.m
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
function colors = distinguishable_colors(n_colors,bg,func) | ||
% DISTINGUISHABLE_COLORS: pick colors that are maximally perceptually distinct | ||
% | ||
% When plotting a set of lines, you may want to distinguish them by color. | ||
% By default, Matlab chooses a small set of colors and cycles among them, | ||
% and so if you have more than a few lines there will be confusion about | ||
% which line is which. To fix this problem, one would want to be able to | ||
% pick a much larger set of distinct colors, where the number of colors | ||
% equals or exceeds the number of lines you want to plot. Because our | ||
% ability to distinguish among colors has limits, one should choose these | ||
% colors to be "maximally perceptually distinguishable." | ||
% | ||
% This function generates a set of colors which are distinguishable | ||
% by reference to the "Lab" color space, which more closely matches | ||
% human color perception than RGB. Given an initial large list of possible | ||
% colors, it iteratively chooses the entry in the list that is farthest (in | ||
% Lab space) from all previously-chosen entries. While this "greedy" | ||
% algorithm does not yield a global maximum, it is simple and efficient. | ||
% Moreover, the sequence of colors is consistent no matter how many you | ||
% request, which facilitates the users' ability to learn the color order | ||
% and avoids major changes in the appearance of plots when adding or | ||
% removing lines. | ||
% | ||
% Syntax: | ||
% colors = distinguishable_colors(n_colors) | ||
% Specify the number of colors you want as a scalar, n_colors. This will | ||
% generate an n_colors-by-3 matrix, each row representing an RGB | ||
% color triple. If you don't precisely know how many you will need in | ||
% advance, there is no harm (other than execution time) in specifying | ||
% slightly more than you think you will need. | ||
% | ||
% colors = distinguishable_colors(n_colors,bg) | ||
% This syntax allows you to specify the background color, to make sure that | ||
% your colors are also distinguishable from the background. Default value | ||
% is white. bg may be specified as an RGB triple or as one of the standard | ||
% "ColorSpec" strings. You can even specify multiple colors: | ||
% bg = {'w','k'} | ||
% or | ||
% bg = [1 1 1; 0 0 0] | ||
% will only produce colors that are distinguishable from both white and | ||
% black. | ||
% | ||
% colors = distinguishable_colors(n_colors,bg,rgb2labfunc) | ||
% By default, distinguishable_colors uses the image processing toolbox's | ||
% color conversion functions makecform and applycform. Alternatively, you | ||
% can supply your own color conversion function. | ||
% | ||
% Example: | ||
% c = distinguishable_colors(25); | ||
% figure | ||
% image(reshape(c,[1 size(c)])) | ||
% | ||
% Example using the file exchange's 'colorspace': | ||
% func = @(x) colorspace('RGB->Lab',x); | ||
% c = distinguishable_colors(25,'w',func); | ||
|
||
% Copyright 2010-2011 by Timothy E. Holy | ||
|
||
% Parse the inputs | ||
if (nargin < 2) | ||
bg = [1 1 1]; % default white background | ||
else | ||
if iscell(bg) | ||
% User specified a list of colors as a cell aray | ||
bgc = bg; | ||
for i = 1:length(bgc) | ||
bgc{i} = parsecolor(bgc{i}); | ||
end | ||
bg = cat(1,bgc{:}); | ||
else | ||
% User specified a numeric array of colors (n-by-3) | ||
bg = parsecolor(bg); | ||
end | ||
end | ||
|
||
% Generate a sizable number of RGB triples. This represents our space of | ||
% possible choices. By starting in RGB space, we ensure that all of the | ||
% colors can be generated by the monitor. | ||
n_grid = 30; % number of grid divisions along each axis in RGB space | ||
x = linspace(0,1,n_grid); | ||
[R,G,B] = ndgrid(x,x,x); | ||
rgb = [R(:) G(:) B(:)]; | ||
if (n_colors > size(rgb,1)/3) | ||
error('You can''t readily distinguish that many colors'); | ||
end | ||
|
||
% Convert to Lab color space, which more closely represents human | ||
% perception | ||
if (nargin > 2) | ||
lab = func(rgb); | ||
bglab = func(bg); | ||
else | ||
C = makecform('srgb2lab'); | ||
lab = applycform(rgb,C); | ||
bglab = applycform(bg,C); | ||
end | ||
|
||
% If the user specified multiple background colors, compute distances | ||
% from the candidate colors to the background colors | ||
mindist2 = inf(size(rgb,1),1); | ||
for i = 1:size(bglab,1)-1 | ||
dX = bsxfun(@minus,lab,bglab(i,:)); % displacement all colors from bg | ||
dist2 = sum(dX.^2,2); % square distance | ||
mindist2 = min(dist2,mindist2); % dist2 to closest previously-chosen color | ||
end | ||
|
||
% Iteratively pick the color that maximizes the distance to the nearest | ||
% already-picked color | ||
colors = zeros(n_colors,3); | ||
lastlab = bglab(end,:); % initialize by making the "previous" color equal to background | ||
for i = 1:n_colors | ||
dX = bsxfun(@minus,lab,lastlab); % displacement of last from all colors on list | ||
dist2 = sum(dX.^2,2); % square distance | ||
mindist2 = min(dist2,mindist2); % dist2 to closest previously-chosen color | ||
[~,index] = max(mindist2); % find the entry farthest from all previously-chosen colors | ||
colors(i,:) = rgb(index,:); % save for output | ||
lastlab = lab(index,:); % prepare for next iteration | ||
end | ||
end | ||
|
||
function c = parsecolor(s) | ||
if ischar(s) | ||
c = colorstr2rgb(s); | ||
elseif isnumeric(s) && size(s,2) == 3 | ||
c = s; | ||
else | ||
error('MATLAB:InvalidColorSpec','Color specification cannot be parsed.'); | ||
end | ||
end | ||
|
||
function c = colorstr2rgb(c) | ||
% Convert a color string to an RGB value. | ||
% This is cribbed from Matlab's whitebg function. | ||
% Why don't they make this a stand-alone function? | ||
rgbspec = [1 0 0;0 1 0;0 0 1;1 1 1;0 1 1;1 0 1;1 1 0;0 0 0]; | ||
cspec = 'rgbwcmyk'; | ||
k = find(cspec==c(1)); | ||
if isempty(k) | ||
error('MATLAB:InvalidColorString','Unknown color string.'); | ||
end | ||
if k~=3 || length(c)==1, | ||
c = rgbspec(k,:); | ||
elseif length(c)>2, | ||
if strcmpi(c(1:3),'bla') | ||
c = [0 0 0]; | ||
elseif strcmpi(c(1:3),'blu') | ||
c = [0 0 1]; | ||
else | ||
error('MATLAB:UnknownColorString', 'Unknown color string.'); | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function DI=dunns(clusters_number,distM,ind) | ||
%%%Dunn's index for clustering compactness and separation measurement | ||
% dunns(clusters_number,distM,ind) | ||
% clusters_number = Number of clusters | ||
% distM = Dissimilarity matrix | ||
% ind = Indexes for each data point aka cluster to which each data point | ||
% belongs | ||
i=clusters_number; | ||
denominator=[]; | ||
|
||
for i2=1:i | ||
indi=find(ind==i2); | ||
indj=find(ind~=i2); | ||
x=indi; | ||
y=indj; | ||
temp=distM(x,y); | ||
denominator=[denominator;temp(:)]; | ||
end | ||
|
||
num=min(min(denominator)); | ||
neg_obs=zeros(size(distM,1),size(distM,2)); | ||
|
||
for ix=1:i | ||
indxs=find(ind==ix); | ||
neg_obs(indxs,indxs)=1; | ||
end | ||
|
||
dem=neg_obs.*distM; | ||
dem=max(max(dem)); | ||
|
||
DI=num/dem; | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function [dist,edge] = geodesic_distance_1(I,C,d,dat1,dat2) | ||
%UNTITLED Summary of this function goes here | ||
% Detailed explanation goes here | ||
|
||
distance=zeros(length(C),1); | ||
index=zeros(length(C),1); | ||
a1=1; | ||
while(dat1~=dat2) | ||
if(dat1>dat2) | ||
distance(a1) = d(dat1-1); | ||
index(a1) = dat1; | ||
a1=a1+1; | ||
dat1=C(dat1); | ||
else | ||
distance(a1) = d(dat2-1); | ||
index(a1) = dat2; | ||
a1=a1+1; | ||
dat2=C(dat2); | ||
end | ||
end | ||
|
||
[dist,idx]=max(distance); | ||
edge=index(idx); | ||
|
||
end | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
% updated 10.11.2010 | ||
|
||
function [RiV]=iVAT(RV) | ||
% Example function call: [RiV] = iVAT(RV); | ||
% | ||
% *** Input Parameters *** | ||
% @param R (n*n double): dissimilarity data input | ||
% @param VATflag (boolean): TRUE - R is VAT-reordered | ||
% | ||
% *** Output Values *** | ||
% @value RV (n*n double): VAT-reordered dissimilarity data | ||
% @value RiV (n*n double): iVAT-transformed dissimilarity data | ||
|
||
N=length(RV); | ||
|
||
RiV=zeros(N); | ||
for r=2:N, | ||
c=1:r-1; | ||
[y,i]=min(RV(r,1:r-1)); | ||
RiV(r,c)=y; | ||
cnei=c(c~=i); | ||
a=[RiV(r,cnei); RiV(i,cnei)]; | ||
RiV(r,cnei)=max(a,[],1); | ||
RiV(c,r)=RiV(r,c)'; | ||
end; | ||
|
||
end |
Oops, something went wrong.