⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_yf_optimalclusterspidx_1_01.m

📁 模糊C均值聚类的一个参考材料,做模糊聚类是用的一个程序
💻 M
字号:
% ----------------------------------------------------------------------
% Example for testing the optimal number of clusters
% 
% ----------------------------------------------------------------------
% Written By: Mahdi Amiri.
% E-Mail: yashil1@yahoo.com
% Homepage: http://yashil.20m.com/
% June 2003
% ----------------------------------------------------------------------

% ----------------------------------------------------------------------
% Clean up
clc;
clear all;
close all;

% ----------------------------------------------------------------------
% Input data => Xin
Xin = Yf_SampleClusteringDataSets1 (3,100);
%Xin = Yf_SampleClusteringDataSets1 (30);
%Xin = Yf_SampleClusteringDataSets1 (11);
%Xin = Yf_SampleClusteringDataSets1 (12);
%load fcmdata.dat; Xin = fcmdata;

% ----------------------------------------------------------------------
% Plot input feature vectors
figure; plot(Xin(:,1),Xin(:,2),'o')
title ('Input feature vectors');

% ----------------------------------------------------------------------
% Maximum number of clusters => nCMax
nCMax = 8;

% ----------------------------------------------------------------------
% Weighting exponent
m = 2;

n = size (Xin, 1);
Xav = sum(Xin)/n;

% ----------------------------------------------------------------------
% Main loop
for nC = 2:nCMax,

    % ----------------------------------------------------------------------
    % Optional initial cluster centers
    %init_V = Xin(1:nC, :);

    % ----------------------------------------------------------------------
    % Call clustering function
    %[V,U,E] = Yf_FCMC1 (Xin, nC);
    %[V,U,E] = Yf_FCMC1 (Xin, nC, [m; 100; 0.001; 0; 1], init_V);
    [V,U,E] = Yf_FCMC1 (Xin, nC, [m; 100; 0.001; 0; 0]);
    %[V,U,E] = fcm(Xin, nC);
    
    % ----------------------------------------------------------------------
    % Find performance index for optimal clusters
    Pnc(nC) = Yf_OptimalClustersPIdx_1 (Xin, U, V, m, Xav);
    
end

nC = find (Pnc == min(Pnc))
%init_V = Xin(1:nC, :);
%[V,U,E] = Yf_FCMC1 (Xin, nC, [m; 100; 0.001; 0; 1], init_V);
[V,U,E] = Yf_FCMC1 (Xin, nC, [m; 100; 0.001; 0; 0]);

% ----------------------------------------------------------------------
% Plot performance index for optimal clusters
figure;
plot(Pnc);
title ('Performance index for optimal clusters');
xlabel ('Cluster No.');
ylabel ('PI value');

% ----------------------------------------------------------------------
% Plot termination measure values
figure;
plot(E);
title ('Termination measure');
xlabel ('Iteration num.');
ylabel ('Termination measure value');

% ----------------------------------------------------------------------
% Plot clustered feature vectors
figure;
maxU = max(U);

cMarker = ['+' 'o' '*' '.' 'x' 's' 'd' '^' 'v' '>' '<' 'p' 'h'];
cColor =  ['r' 'g' 'b' 'm' 'c' 'y' 'k' 'r' 'g' 'b' 'y' 'm' 'c'];

for c = 1:nC
    index_c = find(U(c, :) == maxU);

    line(Xin(index_c, 1), Xin(index_c, 2), 'linestyle',...
        'none','marker', cMarker(c), 'color', cColor(c));
    
    hold on
    plot(V(c,1),V(c,2),['k' cMarker(c)],'markersize',15,'LineWidth',2)
end
title ('Clustered feature vectors');

% ----------------------------------------------------------------------
% Plot membership functions
figure; hold on;
subplot (nC, 1, 1)
plot (U(1, :), cColor(1))
title ('Membership functions');
for c = 2:nC
    subplot (nC, 1, c)
    plot (U(c, :), cColor(c))
end

figure;
for c = 1:nC
    x1 = Xin(:, 1)';
    y1 = Xin(:, 2)';
    z1 = U(c, :);
    stem3 (x1, y1, z1, cColor(c));
    hold on;
end

% ----------------------------------------------------------------------
% ----------------------------------------------------------------------
% ----------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -