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; } }
/** * 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; }