Java 列表<;集群<;DoublePoint>&燃气轮机;设置<;DoublePoint>;

Java 列表<;集群<;DoublePoint>&燃气轮机;设置<;DoublePoint>;,java,data-conversion,dbscan,Java,Data Conversion,Dbscan,我试图使用DBSCANClusterer(apache.math3)对我生成的一组点进行排序并将其写入文件。在这一点上,我被困在这里: public Set<DoublePoint> DBSCAN(Set<DoublePoint> set2) { Set<DoublePoint> points = new Set<DoublePoint>(); DBSCANClusterer<DoublePoint>

我试图使用DBSCANClusterer(apache.math3)对我生成的一组点进行排序并将其写入文件。在这一点上,我被困在这里:

public Set<DoublePoint> DBSCAN(Set<DoublePoint> set2) { 
        Set<DoublePoint> points = new Set<DoublePoint>();
        DBSCANClusterer<DoublePoint> dbscan = new DBSCANClusterer<DoublePoint>(1, 15);
        //run dbscan on set of points
        List<Cluster<DoublePoint>> clusters = dbscan.cluster(set2);
        **sorted = clusters???**
publicsetdbscan(setset2){
设置点=新设置();
DBSCANClusterer dbscan=新的DBSCANClusterer(1,15);
//在一组点上运行dbscan
List clusters=dbscan.cluster(set2);
**排序=簇**
如何将:
列表簇
分配给
设置排序
?我想应该是2D->1D

下面是我剩下的代码:

    import java.awt.Point;
    import java.io.*;
    import java.util.*;
    import org.apache.commons.math3.ml.clustering.Cluster;
    import org.apache.commons.math3.ml.clustering.DBSCANClusterer;
    import org.apache.commons.math3.ml.clustering.DoublePoint;
    import java.util.HashSet;
    import java.util.Random;
    import java.util.Set;


public class Main {

    public static void main(final String[] args) throws Exception {
        new Main().run(); 
    }

    public void run() {
        Set<DoublePoint> set = generateSetPoints();
        try {
            writeToFile(set, "points");
        } catch(IOException ex) {
            System.out.println("IO Exception while writing to file");
        }

        Set<DoublePoint> set_by_dbscan = dbScan(set);//
        try {
            writeToFile(set_by_dbscan, "by_dbscan");
        } catch(IOException ex) {
            System.out.println("IO Exception while writing to file"); 
        }

    }

    public Set<DoublePoint> generateSetPoints() { 
        int xx=100;
        int yy=100;
        Set<DoublePoint> set = new HashSet<>(); 
        Random rnd = new Random(); 
        int number=100;
        do{
            int tmp[] = new int[2];

            tmp[0] =   rnd.nextInt(xx); 
            tmp[1] =   rnd.nextInt(yy); 
            DoublePoint rndpoint    =   new DoublePoint(tmp);
            set.add(rndpoint);
        }
        while (set.size()<number);
        return set;
    }

    public void writeToFile(Set<DoublePoint> set, String filename) throws IOException { 
        File fout = new File( filename + ".txt");
        FileOutputStream fos = new FileOutputStream(fout);

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

        for (DoublePoint p: set) {
            bw.write(p.getPoint()[0] + "," + p.getPoint()[1]);
            bw.newLine();
        }

        bw.close();
    }

    public Set<DoublePoint> dbScan(Set<DoublePoint> set2) { 
        Set<DoublePoint> points = new Set<DoublePoint>();
        DBSCANClusterer dbscan = new DBSCANClusterer(1, 15);
        List<Cluster<DoublePoint>> clusters = dbscan.cluster(set2);
        return clusters;
    }
}
导入java.awt.Point;
导入java.io.*;
导入java.util.*;
导入org.apache.commons.math3.ml.clustering.Cluster;
导入org.apache.commons.math3.ml.clustering.DBSCANClusterer;
导入org.apache.commons.math3.ml.clustering.DoublePoint;
导入java.util.HashSet;
导入java.util.Random;
导入java.util.Set;
公共班机{
公共静态void main(最终字符串[]args)引发异常{
新建Main().run();
}
公开募捐{
Set=generateSetPoints();
试一试{
写入文件(设置“点”);
}捕获(IOEX异常){
System.out.println(“写入文件时的IO异常”);
}
Set Set_by_dbscan=dbscan(Set)//
试一试{
writeToFile(由数据库扫描设置,“由数据库扫描设置”);
}捕获(IOEX异常){
System.out.println(“写入文件时的IO异常”);
}
}
公共集generateSetPoints(){
int xx=100;
int yy=100;
Set=newhashset();
随机rnd=新随机();
整数=100;
做{
int tmp[]=新的int[2];
tmp[0]=rnd.nextInt(xx);
tmp[1]=第二个月(年);
双点rndpoint=新双点(tmp);
set.add(rndpoint);
}
而(set.size()哈希集是未排序的数据结构

如果您希望排序
,请使用保留顺序的东西

sorted=nes HashSet()
是一个真正的WTF


另外,DBSCAN不是用来排序的。请使用光学聚类来代替。

谢谢你的回答!因此,我应该使用树集结构来保持顺序。是的,排序后的未排序名称是错误的,但我应该使用DBSCAN来处理我创建、保存和加载的随机生成点。我更新了原始帖子,以包含ude我所有的代码..有什么建议吗?请注意,这是DBSCAN,全大写。我仍然没有得到您想要的“排序”。DBSCAN不排序。通过使用DBSCAN,我想从随机生成的点创建群集。然后将它们保存在输出文件中,并在GNUPLOT中使用它们来可视化它们。您能帮助吗?排序从何而来?我不能为您编写代码。我不使用Apache,ELKI版本要好得多。它有数据生成器和可视化功能,因此您可能不需要编写任何进一步的代码。如果您选中,请不要介意排序。我在提供的代码中更新了我的变量名称。我需要的帮助是将列表转换为集合。