Esempio n. 1
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);
   }
 }
Esempio n. 2
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;
    }
  }