コード例 #1
0
ファイル: Clustering.java プロジェクト: JumpYD/samoa
  public Clustering(List<? extends Instance> points) {
    HashMap<Integer, Integer> labelMap = classValues(points);
    int dim = points.get(0).dataset().numAttributes() - 1;

    int numClasses = labelMap.size();
    int noiseLabel;

    Attribute classLabel = points.get(0).dataset().classAttribute();
    int lastLabelIndex = classLabel.numValues() - 1;
    if (classLabel.value(lastLabelIndex) == "noise") {
      noiseLabel = lastLabelIndex;
    } else {
      noiseLabel = -1;
    }

    ArrayList<Instance>[] sorted_points = (ArrayList<Instance>[]) new ArrayList[numClasses];
    for (int i = 0; i < numClasses; i++) {
      sorted_points[i] = new ArrayList<Instance>();
    }
    for (Instance point : points) {
      int clusterid = (int) point.classValue();
      if (clusterid == noiseLabel) continue;
      sorted_points[labelMap.get(clusterid)].add((Instance) point);
    }
    this.clusters = new AutoExpandVector<Cluster>();
    for (int i = 0; i < numClasses; i++) {
      if (sorted_points[i].size() > 0) {
        SphereCluster s = new SphereCluster(sorted_points[i], dim);
        s.setId(sorted_points[i].get(0).classValue());
        s.setGroundTruth(sorted_points[i].get(0).classValue());
        clusters.add(s);
      }
    }
  }