Search in sources :

Example 1 with LLE

use of smile.manifold.LLE in project smile by haifengl.

the class LLEDemo method learn.

@Override
public JComponent learn() {
    JPanel pane = new JPanel(new GridLayout(1, 2));
    double[][] data = dataset[datasetIndex].toArray(new double[dataset[datasetIndex].size()][]);
    if (data.length > 1000) {
        double[][] x = new double[1000][];
        for (int i = 0; i < 1000; i++) x[i] = data[i];
        data = x;
    }
    long clock = System.currentTimeMillis();
    LLE lle = new LLE(data, 2, k);
    System.out.format("Learn LLE from %d samples in %dms\n", data.length, System.currentTimeMillis() - clock);
    double[][] y = lle.getCoordinates();
    PlotCanvas plot = new PlotCanvas(Math.colMin(y), Math.colMax(y));
    plot.points(y, 'o', Color.RED);
    int n = y.length;
    Graph graph = lle.getNearestNeighborGraph();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if (graph.hasEdge(i, j)) {
                plot.line(y[i], y[j]);
            }
        }
    }
    plot.setTitle("LLE");
    pane.add(plot);
    return pane;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) Graph(smile.graph.Graph) LLE(smile.manifold.LLE) PlotCanvas(smile.plot.PlotCanvas)

Aggregations

GridLayout (java.awt.GridLayout)1 JPanel (javax.swing.JPanel)1 Graph (smile.graph.Graph)1 LLE (smile.manifold.LLE)1 PlotCanvas (smile.plot.PlotCanvas)1