Example #1
0
  private static Instances convertToInstances(
      final IScope scope,
      final IList<String> attributes,
      final IAddressableContainer<Integer, IAgent, Integer, IAgent> agents)
      throws GamaRuntimeException {
    FastVector attribs = new FastVector();
    for (String att : attributes) {
      attribs.addElement(new Attribute(att));
    }
    Instances dataset =
        new Instances(scope.getAgentScope().getName(), attribs, agents.length(scope));
    for (IAgent ag : agents.iterable(scope)) {

      int nb = attributes.size();
      double vals[] = new double[nb];
      for (int i = 0; i < nb; i++) {
        String attrib = attributes.get(i);
        Double var = Cast.asFloat(scope, ag.getDirectVarValue(scope, attrib));
        vals[i] = var;
      }
      Instance instance = new Instance(1, vals);
      dataset.add(instance);
    }
    return dataset;
  }
  public void buildClusterer(ArrayList<String> seqDB, double[][] sm) {
    seqList = seqDB;

    this.setSimMatrix(sm);

    Attribute seqString = new Attribute("sequence", (FastVector) null);
    FastVector attrInfo = new FastVector();
    attrInfo.addElement(seqString);
    Instances data = new Instances("data", attrInfo, 0);

    for (int i = 0; i < seqList.size(); i++) {
      Instance currentInst = new Instance(1);
      currentInst.setDataset(data);
      currentInst.setValue(0, seqList.get(i));
      data.add(currentInst);
    }

    try {
      buildClusterer(data);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }