-
Notifications
You must be signed in to change notification settings - Fork 18
Closed
Description
that might be in core, that might be here, I tried to compare Kmeans class def to the PCA class def and I find a lot of differences (no <> on the var for instance, and explicit getter and setters) but 'fixing' those didn't fix the issue.
in all cases, the problem is that changing numClusters doesn't change it:
(
//Make some clumped 2D points and place into a DataSet
~points = (4.collect{
64.collect{(1.sum3rand) + [1,-1].choose}.clump(2)
}).flatten(1) * 0.5;
fork{
~dataSet = FluidDataSet(s);
d = Dictionary.with(
*[\cols -> 2,\data -> Dictionary.newFrom(
~points.collect{|x, i| [i, x]}.flatten)]);
s.sync;
~dataSet.load(d, {~dataSet.print});
}
)
// Create a KMeans instance and a LabelSet for the cluster labels in the server
~clusters = FluidLabelSet(s);
~kmeans = FluidKMeans(s);
// Fit into 4 clusters
(
~kmeans.fitPredict(~dataSet, ~clusters, action: {|c|
"Fitted.\n # Points in each cluster:".postln;
c.do{|x,i|
("Cluster" + i + "->" + x.asInteger + "points").postln;
}
});
)
// change this and run above (not all points are assigned)
~kmeans.numClusters = 2
// change this and run above (classes 5 to 10 are empty)
~kmeans.numClusters = 10
one can watch the assignation this way:
//or faster by sorting the IDs
~clusters.dump{|x|~assignments = x.at("data").atAll(x.at("data").keys.asArray.sort{|a,b|a.asInteger < b.asInteger}).flatten.postln;}
and see that with 2 or 10 there are still 4 classes.