use of smile.graph.Graph in project smile by haifengl.
the class IsoMapDemo 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();
IsoMap isomap = new IsoMap(data, 2, k);
System.out.format("Learn IsoMap from %d samples in %dms\n", data.length, System.currentTimeMillis() - clock);
double[][] y = isomap.getCoordinates();
PlotCanvas plot = new PlotCanvas(Math.colMin(y), Math.colMax(y));
plot.points(y, 'o', Color.RED);
int n = y.length;
Graph graph = isomap.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("IsoMap");
pane.add(plot);
return pane;
}
use of smile.graph.Graph 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;
}
use of smile.graph.Graph in project smile by haifengl.
the class LaplacianEigenmapDemo method learn.
@Override
public JComponent learn() {
JPanel pane = new JPanel(new GridLayout(1, 2));
try {
sigma = Double.parseDouble(sigmaField.getText().trim());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Invalid t: " + sigmaField.getText(), "Error", JOptionPane.ERROR_MESSAGE);
return pane;
}
sigmaField.setEnabled(false);
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();
LaplacianEigenmap eigenmap = new LaplacianEigenmap(data, 2, k, sigma);
System.out.format("Learn Laplacian Eigenmap from %d samples in %dms\n", data.length, System.currentTimeMillis() - clock);
double[][] y = eigenmap.getCoordinates();
PlotCanvas plot = new PlotCanvas(Math.colMin(y), Math.colMax(y));
plot.points(y, 'o', Color.RED);
int n = y.length;
Graph graph = eigenmap.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("Laplacian Eigenmap");
pane.add(plot);
sigmaField.setEnabled(true);
return pane;
}
Aggregations