Bonjour à tous,

J'ai un problème avec mon programme qui affiche:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
??? One or more output arguments not assigned during call to 'F:\essaye\1\simple_kmeans.m (simple_kmeans)'.
 
Error in ==> km_demo at 25
[proto Nproto] = simple_kmeans(X,K,maxerr)
voila le script
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 % Demo for the kmeans algorithm
 
% First, generate sample data
%   We will test with 4 clusters in 3 dimensions,
%   by generating random data with gaussian density, variance 1,
%   with means (0,0,0), (0,0,6), (0,6,0) and (6,0,0)
%   and Ndata  200,       300,   100     and 500
 
K = 4;
dim = 3;
variance = 1;
sdev = sqrt(variance);
 
cluster1 = sdev*randn(200,dim) + kron(ones(200,1),[0,0,0]);
cluster2 = sdev*randn(300,dim) + kron(ones(300,1),[0,0,6]);
cluster3 = sdev*randn(100,dim) + kron(ones(100,1),[0,6,0]);
cluster4 = sdev*randn(500,dim) + kron(ones(500,1),[6,0,0]);
 
% Build data matrix
X = [cluster1 ; cluster2 ; cluster3; cluster4];
 
% Now apply K-means algorithm
% Note that order of results may vary
maxerr = 0;
[proto Nproto] = simple_kmeans(X,K,maxerr)
voila fonct
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 function [means,Nmeans] = simple_kmeans(X,K,maxerr)
 
 function [medias,Nmedias] = simple_kmedias(X,K,maxerr)
 Finds K prototypes representing the samples in data matrix X,
 where each row of X represents a sample. 
%   Iterates until maximum norm difference between
%   prototypes found in successive iterations is < maxerr
%   
%   This script uses square Euclidean distance, 
%   but can be easily modified to use other metrics
%
% Output arguments
%   means: matrix with each row a cluster prototype
%   Nmeans: Number of samples in each cluster
 
 
[Ndata, dims] = size(X);
dist = zeros(1,K);
 
% Initial prototype assignment (arbitrary)
for i=1:K-1
   means(i,:) = X(i,:);
end
means(K,:) = mean(X(K:Ndata,:));
 
cmp = 1 + maxerr;
while (cmp > maxerr)
   % Sums (class) and data counters (Nclass) initialization
   class = zeros(K,dims);
   Nclass = zeros(K,1);
 
   % Groups each elements to the nearest prototype
   for i=1:Ndata
      for j=1:K
         % Euclidean distance from data to each prototype
         dist(j) = norm(X(i,:)-means(j,:))^2;
      end
      % Find indices of minimum distance
      index_min = find(~(dist-min(dist)));
      % If there are multiple min distances, decide randomly
      index_min = index_min(ceil(length(index_min)*rand));
      class(index_min,:) = class(index_min,:) + X(i,:);
      Nclass(index_min) = Nclass(index_min) + 1;
   end
   for i=1:K
      class(i,:) = class(i,:) / Nclass(i);
   end
 
   % Compare results with previous iteration
   cmp = 0;
   for i=1:K
      cmp = norm(class(i,:)-means(i,:)); 
   end
 
   % Prototype update
   means = class;
end
 
Nmeans = Nclass;
Merci d'avance