use of smile.vq.NeuralGas in project smile by haifengl.
the class NeuralGasDemo method learn.
@Override
public JComponent learn() {
long clock = System.currentTimeMillis();
NeuralGas gas = new NeuralGas(dataset[datasetIndex], clusterNumber);
System.out.format("Neural Gas clusterings %d samples in %dms\n", dataset[datasetIndex].length, System.currentTimeMillis() - clock);
PlotCanvas plot = ScatterPlot.plot(gas.centroids(), '@');
for (int k = 0; k < clusterNumber; k++) {
if (gas.getClusterSize()[k] > 0) {
double[][] cluster = new double[gas.getClusterSize()[k]][];
for (int i = 0, j = 0; i < dataset[datasetIndex].length; i++) {
if (gas.getClusterLabel()[i] == k) {
cluster[j++] = dataset[datasetIndex][i];
}
}
plot.points(cluster, pointLegend, Palette.COLORS[k % Palette.COLORS.length]);
}
}
plot.points(gas.centroids(), '@');
return plot;
}
Aggregations