-1
DBSCANClusterer(apache.math3)を使用して、生成してファイルに書き込むポイントのセットをソートしようとしています。この時点で、私はここで立ち往生しています:List <Cluster <DoublePoint>>を設定する<DoublePoint>
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???**
はどのようにして割り当てることができます。List<Cluster<DoublePoint>> clusters
Set<DoublePoint> sorted
に??私はそれが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;
}
}
ありがとうございました!だから、私は順序を保持するためにTreeSet構造を使用する必要があります。うん、ソートされたソートされていない名前は間違っていますが、DBScanを使用して、ファイルから作成、保存、ロードするランダム生成ポイントを処理する必要があります。元の投稿を更新して、すべてのコードを含めるようにしました。 – JesteR
DBSCANであり、すべて大文字であることに注意してください。私はまだあなたが「並べ替える」ことを望んでいない。 DBSCANはソートしません。 –
DBSCANを使用することで、ランダムに生成されたポイントからクラスタを作成したいと考えています。その後、それらを出力ファイルに保存し、それらをGNUPLOTで使用して可視化します。手伝ってくれますか? – JesteR