📄 yf_pcmc1.m
字号:
function [V, T, E] = Yf_PCMC1 (X, c, w, options, init_V)
%Yf_PCMC1: Possibilistic C-Means Clustering.
%
% [V, T, E] = Yf_PCMC1 (X, c, w, options, init_V)
% X: Input data (n by p)
% n: Number of feature vectors
% p: Length of each feature vector
% c: Number of clusters
% w: Weights (lenght = c)
% init_V: Initial cluster centers
% OPTIONS(1): Weighting exponent (m) (default: 2.0)
% OPTIONS(2): Maximum number of iterations (default: 100)
% OPTIONS(3): Termination threshold (default: 1e-3)
% OPTIONS(4): Info display during iteration (default: 1)
% OPTIONS(5): Use provided init_V (default: 0)
%
% V: Cluster centers (c by p)
% T: Typicality (Possibility) values (c by p)
% E: Termination measure values (max_iter by 1)
%
% Reference:
% [BezKKP99] James C. Bezdek, James Keller, Raghu Krishnapuram and
% Nikhil R. Pal, Fuzzy Models and Algorithms for Pattern Recognition
% and Image Processing, Kluwer Academic Publishers, TA 1650.F89 1999.
%
% Mahdi Amiri, June 17, 2003
% http://yashil.20m.com/
if nargin < 3,
error('Too few input arguments!');
end
if nargin > 5,
error('Too many input arguments!');
end
n = size(X, 1);
p = size(X, 2);
% Change the following to set default options
default_options = [2; % weighting exponent (m)
100; % max. number of iteration
1e-3; % termination threshold
1; % info display during iteration
0]; % use provided init_V
if nargin == 2,
options = default_options;
else
% If "options" is not fully specified, pad it with default values.
if length(options) < 5,
tmp = default_options;
tmp(1:length(options)) = options;
options = tmp;
end
% If some entries of "options" are nan's, replace them with defaults.
nan_index = find(isnan(options)==1);
options(nan_index) = default_options(nan_index);
end
m = options(1); % Weighting exponent
max_iter = options(2); % Max. iteration
term_thr = options(3); % Termination threshold
display = options(4); % Display info or not
use_init_V = options(5); % use provided init_V
if m <= 1,
error('The weighting exponent should be greater than 1!');
end
E = zeros(max_iter, 1); % Array for termination measure values
if use_init_V,
V = init_V;
else
V = Yf_PCMC1_InitV (c, p); % Initial cluster centers
end
%T = zeros (c, n);
% Main loop
for i = 1:max_iter,
[V, T, E(i)] = Yf_PCMC1_Step (X, V, w, c, m);
if display,
fprintf('Iteration count = %d, Termination measure value = %f\n', i, E(i));
end
% check termination condition
if E(i) <= term_thr, break; end,
end
iter_n = i; % Actual number of iterations
E(iter_n+1:max_iter) = [];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -