Comparing the Lloyd max algorithm described in the literature (implemented in C code) to lloyds.m shows that lloyds.m does not calculate the partitions correctly. All literature on this topic says that the partitions are the points in the middle between the codebook entries. In the script below, the for-loop should be left out.
Excerpt from the lloyds.m:
% using the codebook as a fixed value, use the nearest neighbor condition
% to form the nearest neightbor cell.
partition = (codebook(2 : ini_codebook) + codebook(1 : ini_codebook-1)) / 2; for i = 1 : ini_codebook-1 tmp = training_set(find(training_set >= codebook(i))); tmp = tmp(find(tmp <= odebook(i+1))); if isempty(tmp) partition(i) = (codebook(i+1) + codebook(i)) / 2; else partition(i) = mean(tmp); end end
Best Answer