iampurse 2008-11-08 10:21 采纳率: 100%
浏览 221
已采纳

一个诡异的问题 -= =~

[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 注释少,不能部署还。

  • 写回答

8条回答 默认 最新

  • iteye_521 2008-11-08 12:28
    关注

    你确定runAlgorithm()方法是在单线程环境下执行的吗,你的buildClusters()方法中操作了类变量clustersList,调用了getSize()方法,如果是多线程下是否可以考虑把你的buildClusters()方法加上synchronized试试呢,

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用