Beispiel #1
0
  private static IList<IList<IAgent>> clusteringUsingWeka(
      final IScope scope,
      final Clusterer clusterer,
      final IList<String> attributes,
      final IAddressableContainer<Integer, IAgent, Integer, IAgent> agents)
      throws GamaRuntimeException {
    Instances dataset = convertToInstances(scope, attributes, agents);
    try {
      clusterer.buildClusterer(dataset);

      IList<IList<IAgent>> groupes = GamaListFactory.create(Types.LIST.of(Types.AGENT));

      for (int i = 0; i < clusterer.numberOfClusters(); i++) {
        groupes.add(GamaListFactory.<IAgent>create(Types.AGENT));
      }
      for (int i = 0; i < dataset.numInstances(); i++) {
        Instance inst = dataset.instance(i);
        int clusterIndex = -1;
        clusterIndex = clusterer.clusterInstance(inst);
        IList<IAgent> groupe = groupes.get(clusterIndex);
        groupe.add(agents.get(scope, i));
      }
      return groupes;
    } catch (Exception e) {
      return null;
    }
  }
Beispiel #2
0
  /**
   * Set the clusterer for this wrapper
   *
   * @param c a <code>weka.clusterers.Clusterer</code> value
   */
  public void setClusterer(weka.clusterers.Clusterer c) {
    boolean loadImages = true;
    if (c.getClass().getName().compareTo(m_Clusterer.getClass().getName()) == 0) {
      loadImages = false;
    } else {
      // clusterer has changed so any batch training status is now
      // invalid
      m_trainingSet = null;
    }
    m_Clusterer = c;
    String clustererName = c.getClass().toString();
    clustererName =
        clustererName.substring(clustererName.lastIndexOf('.') + 1, clustererName.length());
    if (loadImages) {
      if (!m_visual.loadIcons(
          BeanVisual.ICON_PATH + clustererName + ".gif",
          BeanVisual.ICON_PATH + clustererName + "_animated.gif")) {
        useDefaultVisual();
      }
    }
    m_visual.setText(clustererName);

    // get global info
    m_globalInfo = KnowledgeFlowApp.getGlobalInfo(m_Clusterer);
  }
Beispiel #3
0
 /** Builds the clusters */
 private void buildClusterer() throws Exception {
   if (m_trainingSet.classIndex() < 0) m_Clusterer.buildClusterer(m_trainingSet);
   else { // class based evaluation if class attribute is set
     Remove removeClass = new Remove();
     removeClass.setAttributeIndices("" + (m_trainingSet.classIndex() + 1));
     removeClass.setInvertSelection(false);
     removeClass.setInputFormat(m_trainingSet);
     Instances clusterTrain = Filter.useFilter(m_trainingSet, removeClass);
     m_Clusterer.buildClusterer(clusterTrain);
   }
 }
Beispiel #4
0
  /**
   * Zwraca tylko te instancje, kt??re nale???? do klastra o podanym numerze.
   *
   * @param numClust Numer klastra
   * @return Instancje nale????ce do podanego klastra.
   */
  public Instances getClusterInstances(int numClust) {
    Instances inst = new Instances(data);
    inst.clear();

    try {
      for (int i = 0; i < data.numInstances(); ++i) {
        if (clusterer.clusterInstance(data.instance(i)) == numClust) {
          inst.add(data.instance(i));
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return inst;
  }
Beispiel #5
0
    @Override
    public List<String> getPredictionLabels() throws DistributedWekaException {

      if (m_predictionLabels == null) {
        m_predictionLabels = new ArrayList<String>();

        try {
          for (int i = 0; i < m_model.numberOfClusters(); i++) {
            m_predictionLabels.add("Cluster_" + i);
          }
        } catch (Exception ex) {
          throw new DistributedWekaException(ex);
        }
      }

      return m_predictionLabels;
    }
Beispiel #6
0
 /**
  * Get the number of clusters from the base clusterer
  *
  * @return the number of clusters
  * @throws Exception if a problem occurs
  */
 public int numberOfClusters() throws Exception {
   return m_model.numberOfClusters();
 }
Beispiel #7
0
 @Override
 public double[] distributionForInstance(Instance inst) throws Exception {
   return m_model.distributionForInstance(inst);
 }