[code="java"]
private void buildClusters() {
int numOfClusters = clustersList.size();
javax.swing.JOptionPane.showMessageDialog(null, numOfClusters, "Test",
1, null);
Cluster[] clusters = new Cluster[numOfCluster];
javax.swing.JOptionPane.showMessageDialog(null, clusters.length,
"Test", 1, null);
for (int i = 0; i < numOfClusters; i++) {
clusters[i] = clustersList.get(i);
}
this.setClusters(clusters);
}
[/code]
两次输出居然不一样。
后头一次比上一次多1
[b]问题补充:[/b]
大家说的我都懂 - -
我自己也用别的试过勒 是可以的。
而且我现在是没有办法调试的。
给alphaMiner做的一个插件。
整个工程没办法部署,给的源码有问题貌似。
只好把插件写好 导出jar包 然后开alphaMiner调试 - -。
所以事情很复杂 ~
[b]问题补充:[/b]
-
-。 我感觉很清楚勒。
就是两个跳出窗口 。
第一个是1的话 第二个就是2
第一个是2的话 第二个就是3 。如果有人用alphaMiner的话。
我可以把jar包贴上来。
[b]问题补充:[/b]
package org.xmu.plugin.model;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Vector;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Models.Clustering.Cluster;
import com.prudsys.pdm.Models.Clustering.CDBased.CDBasedClusteringAlgorithm;
/**
- the concretion algorithm of DB Scan prepare clusters for Operator and result
- @author Five
-
*/
public class DBScan extends CDBasedClusteringAlgorithm {private int eps;
private int minPts;
private ArrayList clustersList = new ArrayList();;
private boolean[] isClustered;
private int dataLength;
private Stack tempVecs;
private Vector vecs = new Vector();
private boolean beACluster = false;
private static int numOfCluster = 1;/**
-
main process of DB scan
*/
protected void runAlgorithm() throws MiningException {initParamters();
for (int index = 0; index < dataLength; index++) {
if (isClustered[index] == false) { tempVecs.push(index); getACluster(index); }
}
buildClusters();
}
/**
- 构造从一个点出发的簇
- @param index
- 出发点在数据中的位置
-
@throws MiningException
*/
private void getACluster(int index) throws MiningException {int length = 0;
while (!tempVecs.empty()) {int currentIndex = tempVecs.pop(); isClustered[currentIndex] = true; int[] tempIndexs = getPoints(currentIndex); if (tempIndexs == null) length = 0; else length = tempIndexs.length; if (length >= this.getMinPts()) { //只要以当前点为中心半径Eps范围内的点的个数大于最小密度 //以当前点为中心就能形成一个簇 beACluster = true; for (int m = 0; m < length; m++) { if (isClustered[tempIndexs[m]] == false) { tempVecs.push(tempIndexs[m]); isClustered[tempIndexs[m]] = true; vecs.add(miningInputStream.read(tempIndexs[m])); } } } else if(beACluster == true){ //javax.swing.JOptionPane.showMessageDialog(null, "getHere", "Test", 1, null); // If the number of points is less than minPts, // just add the points into vecs. // and not to expand more. for (int m = 0; m < length; m++) { if (isClustered[tempIndexs[m]] == false) { isClustered[tempIndexs[m]] = true; vecs.add(miningInputStream.read(tempIndexs[m])); } } }
}
if (beACluster == true) {
Cluster tempCluster = new Cluster();
tempCluster.setName("cluster" + String.valueOf(numOfCluster));
vecs.add(miningInputStream.read(index));
numOfCluster++;
//tempCluster.setCenterVec(miningInputStream.read(index));
tempCluster.setContainedVectors(vecs);
clustersList.add(tempCluster);
}vecs.clear();
beACluster = false;
}
/**
- 获取到中心节点的距离小于Eps的所有Points的indexs
- @param index
- 中心节点的位置
- @return 符合条件的所有节点的indexs的int[]
-
@throws MiningException
*/
private int[] getPoints(int index) throws MiningException {ArrayList temp = new ArrayList();
//for(int m = index; m < dataLength; m++){
for (int m = 0; m < dataLength; m++) {
if (m != index) {
double Ep = distance.distance(miningInputStream.read(index),
miningInputStream.read(m));if (Ep <= this.getEps()) temp.add(m); }
}
if (temp.size() == 0)
return null;
else {
int[] result = new int[temp.size()];
for (int num = 0; num < temp.size(); num++) {
result[num] = temp.get(num);
}
return result;
}
}
/**
- init the parameters before run the algorithm
-
@throws MiningException
*/
private void initParamters() throws MiningException {dataLength = miningInputStream.getVectorsNumber();
clustersList.clear();
isClustered = new boolean[dataLength];
for (int temp = 0; temp < dataLength; temp++) {
isClustered[temp] = false;
}tempVecs = new Stack();
vecs.clear();
}
private void buildClusters() {
int num = clustersList.size(); clusters = null; clusters = new Cluster[numOfCluster]; javax.swing.JOptionPane.showMessageDialog(null, clusters.length, "Test", 1, null); for (int i = 0; i < num; i++) { clusters[i] = clustersList.get(i); } this.setClusters(clusters);
}
public void verify() throws IllegalArgumentException {
super.verify(); if (eps <= 0) throw new IllegalArgumentException( "numberOfClusters can't be negative"); if (minPts <= 0) throw new IllegalArgumentException( "maxNumberOfIterations can't be negative");
}
public int getEps() {
return eps;
}public void setEps(int eps) {
this.eps = eps;
}public int getMinPts() {
return minPts;
}public void setMinPts(int minPts) {
this.minPts = minPts;
}public ArrayList getClustersList() {
return clustersList;
}public void setClustersList(ArrayList clustersList) {
this.clustersList = clustersList;
} -
}
这个类的所有代码 - -。写的是一个基于密度的DBScan算法。
主要是不能断点调试,
我都郁闷勒,关键还是期末作业。
然后这垃圾alphaMiner 注释少,不能部署还。