Search in sources :

Example 1 with DENCLUE

use of smile.clustering.DENCLUE in project smile by haifengl.

the class DENCLUEDemo method learn.

@Override
public JComponent learn() {
    try {
        k = Integer.parseInt(kField.getText().trim());
        if (k < 1) {
            JOptionPane.showMessageDialog(this, "Invalid K: " + k, "Error", JOptionPane.ERROR_MESSAGE);
            return null;
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Invalid K: " + kField.getText(), "Error", JOptionPane.ERROR_MESSAGE);
        return null;
    }
    try {
        sigma = Double.parseDouble(sigmaField.getText().trim());
        if (sigma <= 0) {
            JOptionPane.showMessageDialog(this, "Invalid Sigma: " + sigma, "Error", JOptionPane.ERROR_MESSAGE);
            return null;
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Invalid Sigma: " + sigmaField.getText(), "Error", JOptionPane.ERROR_MESSAGE);
        return null;
    }
    long clock = System.currentTimeMillis();
    DENCLUE denclue = new DENCLUE(dataset[datasetIndex], sigma, k);
    System.out.format("DENCLUE clusterings %d samples in %dms\n", dataset[datasetIndex].length, System.currentTimeMillis() - clock);
    JPanel pane = new JPanel(new GridLayout(1, 2));
    PlotCanvas plot = ScatterPlot.plot(dataset[datasetIndex], pointLegend);
    for (int l = 0; l < denclue.getNumClusters(); l++) {
        double[][] cluster = new double[denclue.getClusterSize()[l]][];
        for (int i = 0, j = 0; i < dataset[datasetIndex].length; i++) {
            if (denclue.getClusterLabel()[i] == l) {
                cluster[j++] = dataset[datasetIndex][i];
            }
        }
        plot.points(cluster, pointLegend, Palette.COLORS[l % Palette.COLORS.length]);
    }
    plot.points(denclue.getDensityAttractors(), '@');
    pane.add(plot);
    return pane;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) DENCLUE(smile.clustering.DENCLUE) PlotCanvas(smile.plot.PlotCanvas)

Aggregations

GridLayout (java.awt.GridLayout)1 JPanel (javax.swing.JPanel)1 DENCLUE (smile.clustering.DENCLUE)1 PlotCanvas (smile.plot.PlotCanvas)1