while(dW > 1e-15),
%Choose a sample randomly
i = randperm(L);
phi = train_features(:,i(1));
net_k = W'*phi;
y_star= find(net_k == max(net_k));
y_star= y_star(1);
%Just in case two have the same weights!
oldW = W;
W = W + eta*phi*gamma(win_width*abs(net_k - y_star))';
W = W ./ (ones(D,1)*sqrt(sum(W.^2)));
eta = eta * deta;
dW = sum(sum(abs(oldW-W)));
iter = iter + 1;
if (plot_on == 1),
%Assign each of the features to a center
dist = W'*train_features;
[m, label] = max(dist);
centers = zeros(D,Nmu);
for i = 1:Nmu,
in = find(label == i);
if ~isempty(in)
centers(:,i) = mean(train_features(:,find(label==i))')';
else
centers(:,i) = nan;
end
end
plot_process(centers)
end
if (iter/100 == floor(iter/100)),
disp(['Iteration number ' num2str(iter)])
end
end
%Assign a weight to each feature
label = zeros(1,L);
for i = 1:L,
net_k = W'*train_features(:,i);
label(i) = find(net_k == max(net_k));
end
%Find the target for each weight and the new features
targets = zeros(1,Nmu);
features = zeros(D, Nmu);
for i = 1:Nmu,
in = find(label == i);
if ~isempty(in),
targets(i) = sum(train_targets(in)) / length(in) > .5;
if length(in) == 1,
features(:,i) = train_features(:,in);
else
features(:,i) = mean(train_features(:,in)')';
end
end
end
David G. Stork
Elad Yom-Tov
Computer Manual
in MATLAB
to accompany
Pattern
Classification