[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;
/**
*/
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();
}
/**
@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;
}
/**
@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;
}
}
/**
@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 注释少,不能部署还。
你确定runAlgorithm()方法是在单线程环境下执行的吗,你的buildClusters()方法中操作了类变量clustersList,调用了getSize()方法,如果是多线程下是否可以考虑把你的buildClusters()方法加上synchronized试试呢,
把结果贴出来看看,
你的Cluster[]是个数组吗?
我试了几次,没问题啊,都是一样的,我这的Cluster是空类,只是随便写的一个
[code="java"]
Collection a = new ArrayList();
a.add("1");
a.add("1");
a.add("1");
a.add("1");
System.out.println(a.size());
Cluster[] cluster = new Cluster[a.size()];
System.out.println("cluster=="+cluster.length);
String[] str1 = new String[a.size()];
System.out.println(str1.length);
[/code]
建议设置断点,单步跟踪,看一下内存变量值,这个是基本的调试技巧
多贴出点信息,比如两次的输出结果?你的那点信息不能看出什么问题
这个写法是没有问题的,你还是等发布的时候一起调试一下.
可能还是调用的代码有问题
能写出你测试后的结果吗,多输出几个,看下大家能不能帮你分析
你的clustersList是不是没有清空啊!
前面加clustersList.clear()试试.
应该可以解决.