VLFeat offers a hierarchical version of integer k-means, which recusively apply \cmd{ikmeans} to compute finer and finer partitions. We demonstrates this by:
K = 3 ; nleaves = 100 ; data = uint8(rand(2,10000) * 255) ; datat = uint8(rand(2,100000)* 255) ; [tree,A] = hikmeans(data,K,nleaves) ; AT = hikmeanspush(tree,datat) ;
Here nleaves
is the desired number of leaf
clusters. This is obtained by subdividing recursively each cluster in
k sub-clusters. Therefore depth = floor(log(K nleaves))
recursive subdivisons are sufficient and the algorithm terminates with
clusters arranged in a k-tree of of depth
depth
which has at least nleaves
leaves (but
it may have more).
The output tree
is a MATLAB structure representing the tree of
clusters:
> tree tree = K: 3 depth: 5 centers: [2x3 int32] sub: [1x3 struct]
The field centers
is the matrix of the cluster centers at the
root node. If the depth of the tree is larger than 1, then the field
sub
is a structure array with one entry for each cluster. Each
element is in turn a structure such as
> tree.sub ans = 1x3 struct array with fields: centers sub
with the cluster centers for that recusrive parittions and a field erb$sub$ for the recursive children. When there are no childrent, this field is equal to the empty matrix
K>> tree.sub(1).sub(1).sub(1).sub(1) ans = centers: [2x3 int32] sub: []