Exemple #1
0
 /**
  * Tests if the database contains the dataObject_Query
  *
  * @param dataObject_Query The query-object
  * @return true if the database contains dataObject_Query, else false
  */
 public boolean contains(DataObject dataObject_Query) {
   Iterator iterator = dataObjectIterator();
   while (iterator.hasNext()) {
     DataObject dataObject = (DataObject) iterator.next();
     if (dataObject.equals(dataObject_Query)) return true;
   }
   return false;
 }
Exemple #2
0
  /**
   * Emits the k next-neighbours and performs an epsilon-range-query at the parallel. The returned
   * list contains two elements: At index=0 --> list with all k next-neighbours; At index=1 --> list
   * with all dataObjects within epsilon;
   *
   * @param k number of next neighbours
   * @param epsilon Specifies the range for the query
   * @param dataObject the start object
   * @return list with the k-next neighbours (PriorityQueueElements) and a list with candidates from
   *     the epsilon-range-query (EpsilonRange_ListElements)
   */
  public List k_nextNeighbourQuery(int k, double epsilon, DataObject dataObject) {
    Iterator iterator = dataObjectIterator();

    List return_List = new ArrayList();
    List nextNeighbours_List = new ArrayList();
    List epsilonRange_List = new ArrayList();

    PriorityQueue priorityQueue = new PriorityQueue();

    while (iterator.hasNext()) {
      DataObject next_dataObject = (DataObject) iterator.next();
      double dist = dataObject.distance(next_dataObject);

      if (dist <= epsilon)
        epsilonRange_List.add(new EpsilonRange_ListElement(dist, next_dataObject));

      if (priorityQueue.size() < k) {
        priorityQueue.add(dist, next_dataObject);
      } else {
        if (dist < priorityQueue.getPriority(0)) {
          priorityQueue.next(); // removes the highest distance
          priorityQueue.add(dist, next_dataObject);
        }
      }
    }

    while (priorityQueue.hasNext()) {
      nextNeighbours_List.add(0, priorityQueue.next());
    }

    return_List.add(nextNeighbours_List);
    return_List.add(epsilonRange_List);
    return return_List;
  }
Exemple #3
0
  /**
   * Sets the minimum and maximum values for each attribute in different arrays by walking through
   * every DataObject of the database
   */
  public void setMinMaxValues() {
    attributeMinValues = new double[getInstances().numAttributes()];
    attributeMaxValues = new double[getInstances().numAttributes()];

    // Init
    for (int i = 0; i < getInstances().numAttributes(); i++) {
      attributeMinValues[i] = attributeMaxValues[i] = Double.NaN;
    }

    Iterator iterator = dataObjectIterator();
    while (iterator.hasNext()) {
      DataObject dataObject = (DataObject) iterator.next();
      for (int j = 0; j < getInstances().numAttributes(); j++) {
        if (Double.isNaN(attributeMinValues[j])) {
          attributeMinValues[j] = dataObject.getInstance().value(j);
          attributeMaxValues[j] = dataObject.getInstance().value(j);
        } else {
          if (dataObject.getInstance().value(j) < attributeMinValues[j])
            attributeMinValues[j] = dataObject.getInstance().value(j);
          if (dataObject.getInstance().value(j) > attributeMaxValues[j])
            attributeMaxValues[j] = dataObject.getInstance().value(j);
        }
      }
    }
  }
Exemple #4
0
  /**
   * Performs an epsilon range query for this dataObject
   *
   * @param epsilon Specifies the range for the query
   * @param queryDataObject The dataObject that is used as query-object for epsilon range query
   * @return List with all the DataObjects that are within the specified range
   */
  public List epsilonRangeQuery(double epsilon, DataObject queryDataObject) {
    ArrayList epsilonRange_List = new ArrayList();
    Iterator iterator = dataObjectIterator();
    while (iterator.hasNext()) {
      DataObject dataObject = (DataObject) iterator.next();
      double distance = queryDataObject.distance(dataObject);
      if (distance < epsilon) {
        epsilonRange_List.add(dataObject);
      }
    }

    return epsilonRange_List;
  }
  /**
   * @param args
   * @throws Exception
   */
  void analyseResult(DBScan algo, Instances data) throws Exception {
    FileWriter fw = new FileWriter(new File("topictrackresult"));
    BufferedWriter bw = new BufferedWriter(fw);
    StringBuilder sb = new StringBuilder();
    FastVector resultset = new FastVector();
    for (int i = 0; i < algo.numberOfClusters(); i++) {
      ArrayList<String> oneCluster = new ArrayList<String>();
      resultset.addElement(oneCluster);
    }

    for (int i = 0; i < algo.database.size(); i++) {
      DataObject dataObject = algo.database.getDataObject(Integer.toString(i));
      int IDraw = Integer.parseInt(dataObject.getKey());
      int ID = (int) data.instance(IDraw).value(0);
      String title = findFileNameWithID(ID);
      if (DataObject.NOISE != dataObject.getClusterLabel()) {
        int label = dataObject.getClusterLabel();
        ArrayList<String> filenamelib = (ArrayList<String>) resultset.elementAt(label);
        filenamelib.add(title);
      }
    }

    sb.append("The generated Clusters are:\n");
    for (int i = 0; i < algo.numberOfClusters(); i++) {
      sb.append("\r\n cluster" + i + "\n");
      ArrayList<String> filenamelib = (ArrayList<String>) resultset.elementAt(i);
      Iterator iter = filenamelib.iterator();
      while (iter.hasNext()) {
        String title = (String) iter.next();
        sb.append(title + "\n");
      }
    }

    bw.write(sb.toString());
    bw.close();
    fw.close();
  }
Exemple #6
0
 /**
  * Inserts a new dataObject into the database
  *
  * @param dataObject
  */
 public void insert(DataObject dataObject) {
   treeMap.put(dataObject.getKey(), dataObject);
 }