用Java中的ColouredScatterPlot创建TSne结果的二维图

时间:2019-12-22 16:56:45

标签: java maven plot dimensionality-reduction

我正在尝试通过此链接提供的TSne java maven项目; Github Repository for TSne Java Maven Project。我创建了一个测试类,以便在给定的文本文件上执行TSne ...

package tsneTest;

import java.io.File;

import com.jujutsu.tsne.TSneConfiguration;
import com.jujutsu.tsne.barneshut.BHTSne;
import com.jujutsu.tsne.barneshut.BarnesHutTSne;
import com.jujutsu.tsne.barneshut.ParallelBHTsne;
import com.jujutsu.utils.MatrixOps;
import com.jujutsu.utils.MatrixUtils;
import com.jujutsu.utils.TSneUtils;

public class TSneTest {
   public static void main(String [] args) {
   int initial_dims = 55;
   double perplexity = 20.0;
   double [][] X = MatrixUtils.simpleRead2DMatrix(new 
    File("src/main/resources/datasets/mnist2500_X.txt"), "   ");
    System.out.println(MatrixOps.doubleArrayToPrintString(X, ", ", 50, 10));
    BarnesHutTSne tsne;
    boolean parallel = false;
    if(parallel) {          
        tsne = new ParallelBHTsne();
    } else {
        tsne = new BHTSne();
    }
        TSneConfiguration config = TSneUtils.buildConfig(X, 2, initial_dims, perplexity, 1000);
    double [][] Y = tsne.tsne(config); 

    // Plot Y or save Y to file and plot with some other tool such as for instance R

} }

这给了我类似下面的输出...

X:Shape after PCA is = 2500 x 55
X:Shape is = 2500 x 55
Using no_dims = 2, perplexity = 20.000000, and theta = 0.500000
Computing input similarities...
Building tree...
 - point 0 of 2500
Done in 0.72 seconds (sparsity = 0.031862)!
Learning embedding...
Iteration 50: error is 90.5165299966631 (50 iterations in 0.59 seconds)
Iteration 100: error is 90.45451592213186 (50 iterations in 0.43 seconds)
Iteration 150: error is 88.47035940749774 (50 iterations in 0.42 seconds)
Iteration 200: error is 84.7920159509203 (50 iterations in 0.42 seconds)
Iteration 250: error is 4.449663962669793 (50 iterations in 0.41 seconds)
Iteration 300: error is 3.882572797356123 (50 iterations in 0.43 seconds)
Iteration 350: error is 2.182975505785501 (50 iterations in 0.39 seconds)
Iteration 400: error is 1.9934158859241446 (50 iterations in 0.40 seconds)
Iteration 450: error is 1.8913732052364878 (50 iterations in 0.36 seconds)
Iteration 500: error is 1.8164764816240278 (50 iterations in 0.36 seconds)
Iteration 550: error is 1.7589605791227325 (50 iterations in 0.36 seconds)
Iteration 600: error is 1.7135885154662989 (50 iterations in 0.36 seconds)
Iteration 650: error is 1.675744701203508 (50 iterations in 0.36 seconds)
Iteration 700: error is 1.6432493055804531 (50 iterations in 0.37 seconds)
Iteration 750: error is 1.6142966457060333 (50 iterations in 0.37 seconds)
Iteration 800: error is 1.5889373900720165 (50 iterations in 0.37 seconds)
Iteration 850: error is 1.5656598326847049 (50 iterations in 0.37 seconds)
Iteration 900: error is 1.5455266661631772 (50 iterations in 0.37 seconds)
Iteration 950: error is 1.5276274003203592 (50 iterations in 0.38 seconds)
Iteration 999: error is 1.5113704586468555 (50 iterations in 0.38 seconds)
Fitting performed in 7.89 seconds.

现在,我正在尝试使用ColouredScatterPlot绘制Y以显示2d视觉效果,这就是我到目前为止所掌握的。但是,它没有显示任何输出(仅在控制台Name of this color brewer: BrBG中显示)...

    Plot2DPanel plot = new Plot2DPanel();
    ColoredScatterPlot coloredScatterPlot = new ColoredScatterPlot("TSne Result", Y, args);
    plot.plotCanvas.addPlot(coloredScatterPlot); 

这是最好的选择,还是Java中的其他任何外部库等都可以做到这一点?任何帮助将不胜感激。

0 个答案:

没有答案