Package weka.core

Examples of weka.core.FastVector


      } else {
        inst.setClassIndex(inst.numAttributes() - 1);
        ThresholdCurve tc = new ThresholdCurve();
        EvaluationUtils eu = new EvaluationUtils();
        Classifier classifier = new weka.classifiers.functions.Logistic();
        FastVector predictions = new FastVector();
        for (int i = 0; i < 2; i++) { // Do two runs.
          eu.setSeed(i);
          predictions.appendElements(eu.getCVPredictions(classifier, inst, 10));
          //System.out.println("\n\n\n");
        }
        Instances result = tc.getCurve(predictions);
        System.out.println(result);
      }
View Full Code Here


  protected FastVector m_nEvidence;

  /** standard constructor * */
  public EditableBayesNet() {
    super();
    m_nEvidence = new FastVector(0);
    m_fMarginP = new FastVector(0);
    m_nPositionX = new FastVector();
    m_nPositionY = new FastVector();
    clearUndoStack();
  } // c'tor
View Full Code Here

    for (int iNode = 0; iNode < nNodes; iNode++) {
      m_Distributions[iNode] = new Estimator[1];
      m_Distributions[iNode][0] = new DiscreteEstimatorBayes(getCardinality(iNode), 0.5);
    }

    m_nEvidence = new FastVector(nNodes);
    for (int i = 0; i < nNodes; i++) {
      m_nEvidence.addElement(-1);
    }
    m_fMarginP = new FastVector(nNodes);
    for (int i = 0; i < nNodes; i++) {
      double[] P = new double[getCardinality(i)];
      m_fMarginP.addElement(P);
    }

    m_nPositionX = new FastVector(nNodes);
    m_nPositionY = new FastVector(nNodes);
    for (int iNode = 0; iNode < nNodes; iNode++) {
      m_nPositionX.addElement(iNode%10 * 50);
      m_nPositionY.addElement(((int)(iNode/10)) * 50);
    }

 
View Full Code Here

    m_Instances = other.m_Instances;
    m_ParentSets = other.getParentSets();
    m_Distributions = other.getDistributions();

    int nNodes = getNrOfNodes();
    m_nPositionX = new FastVector(nNodes);
    m_nPositionY = new FastVector(nNodes);
    for (int i = 0; i < nNodes; i++) {
      m_nPositionX.addElement(other.m_nPositionX[i]);
      m_nPositionY.addElement(other.m_nPositionY[i]);
    }
    m_nEvidence = new FastVector(nNodes);
    for (int i = 0; i < nNodes; i++) {
      m_nEvidence.addElement(-1);
    }
    m_fMarginP = new FastVector(nNodes);
    for (int i = 0; i < nNodes; i++) {
      double[] P = new double[getCardinality(i)];
      m_fMarginP.addElement(P);
    }
    clearUndoStack();
View Full Code Here

   * @param bSetInstances
   *            flag indicating whether to initialize instances or not
   */
  public EditableBayesNet(boolean bSetInstances) {
    super();
    m_nEvidence = new FastVector(0);
    m_fMarginP = new FastVector(0);
    m_nPositionX = new FastVector();
    m_nPositionY = new FastVector();
    clearUndoStack();
    if (bSetInstances) {
      m_Instances = new Instances("New Network", new FastVector(0), 0);
    }
  } // c'tor
View Full Code Here

    if (getNode2(sName) >= 0) {
      addNode(sName + "x", nCardinality);
      return ;
    }
    // update instances
    FastVector values = new FastVector(nCardinality);
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      values.addElement("Value" + (iValue + 1));
    }
    Attribute att = new Attribute(sName, values);
    m_Instances.insertAttributeAt(att, m_Instances.numAttributes());
    int nAtts = m_Instances.numAttributes();
    // update parentsets
View Full Code Here

   * @param item XMLNode to select items from
   * @param sElement name of the element to return
   */
  FastVector selectElements(Node item, String sElement) throws Exception {
    NodeList children = item.getChildNodes();
    FastVector nodelist = new FastVector();
    for (int iNode = 0; iNode < children.getLength(); iNode++) {
      Node node = children.item(iNode);
      if ((node.getNodeType() == Node.ELEMENT_NODE) && node.getNodeName().equals(sElement)) {
        nodelist.addElement(node);
      }
    }
    return nodelist;
  } // selectElements
View Full Code Here

   */
  Element getDefinition(Document doc, String sName) throws Exception {
    NodeList nodelist = doc.getElementsByTagName("DEFINITION");
    for (int iNode = 0; iNode < nodelist.getLength(); iNode++) {
      Node node = nodelist.item(iNode);
      FastVector list = selectElements(node, "FOR");
      if (list.size() > 0) {
        Node forNode = (Node) list.elementAt(0);
        if (getContent((Element) forNode).trim().equals(sName)) {
          return (Element) node;
        }
      }
    }
View Full Code Here

    Document doc = factory.newDocumentBuilder().parse(new org.xml.sax.InputSource(new StringReader(sXML)));
    doc.normalize();

    // create nodes first
    NodeList nodelist = doc.getElementsByTagName("VARIABLE");
    FastVector sBaseNames = new FastVector();
    Instances instances = new Instances(m_Instances, 0);
    int nBase = instances.numAttributes();
    for (int iNode = 0; iNode < nodelist.getLength(); iNode++) {
      // Get element
      FastVector valueslist;
      // Get the name of the node
      valueslist = selectElements(nodelist.item(iNode), "OUTCOME");

      int nValues = valueslist.size();
      // generate value strings
      FastVector nomStrings = new FastVector(nValues + 1);
      for (int iValue = 0; iValue < nValues; iValue++) {
        Node node = ((Node) valueslist.elementAt(iValue)).getFirstChild();
        String sValue = ((CharacterData) (node)).getData();
        if (sValue == null) {
          sValue = "Value" + (iValue + 1);
        }
        nomStrings.addElement(sValue);
      }
      FastVector nodelist2;
      // Get the name of the network
      nodelist2 = selectElements(nodelist.item(iNode), "NAME");
      if (nodelist2.size() == 0) {
        throw new Exception("No name specified for variable");
      }
      String sBaseName = ((CharacterData) (((Node) nodelist2.elementAt(0)).getFirstChild())).getData();
      sBaseNames.addElement(sBaseName);
      String sNodeName = sBaseName;
      if (getNode2(sNodeName) >= 0) {
        sNodeName = "Copy of " + sBaseName;
      }
      int iAttempt = 2;
      while (getNode2(sNodeName) >= 0) {
        sNodeName = "Copy (" + iAttempt + ") of " + sBaseName;
        iAttempt++;
      }

      Attribute att = new Attribute(sNodeName, nomStrings);
      instances.insertAttributeAt(att, instances.numAttributes());

      valueslist = selectElements(nodelist.item(iNode), "PROPERTY");
      nValues = valueslist.size();
      // generate value strings
      int nPosX = iAttempt * 10;
      int nPosY = iAttempt * 10;
      for (int iValue = 0; iValue < nValues; iValue++) {
        // parsing for strings of the form "position = (73, 165)"
        Node node = ((Node) valueslist.elementAt(iValue)).getFirstChild();
        String sValue = ((CharacterData) (node)).getData();
        if (sValue.startsWith("position")) {
          int i0 = sValue.indexOf('(');
          int i1 = sValue.indexOf(',');
          int i2 = sValue.indexOf(')');
          String sX = sValue.substring(i0 + 1, i1).trim();
          String sY = sValue.substring(i1 + 1, i2).trim();
          try {
            nPosX = (Integer.parseInt(sX) + iAttempt * 10);
            nPosY = (Integer.parseInt(sY) + iAttempt * 10);
          } catch (NumberFormatException e) {
            System.err.println("Wrong number format in position :(" + sX + "," + sY + ")");
          }
        }
      }
      if (mode == EXECUTE) {
        m_nPositionX.addElement(nPosX);
        m_nPositionY.addElement(nPosY);
      }

    }

    FastVector nodelist2;
    Estimator[][] distributions = new Estimator[nBase + sBaseNames.size()][];
    ParentSet[] parentsets = new ParentSet[nBase + sBaseNames.size()];
    for (int iNode = 0; iNode < nBase; iNode++) {
      distributions[iNode] = m_Distributions[iNode];
      parentsets[iNode] = m_ParentSets[iNode];
    }
    if (mode == EXECUTE) {
      m_Instances = instances;
    }
    // create arrows & create distributions
    for (int iNode = 0; iNode < sBaseNames.size(); iNode++) {
      // find definition that goes with this node
      String sName = (String) sBaseNames.elementAt(iNode);
      Element definition = getDefinition(doc, sName);
      parentsets[nBase + iNode] = new ParentSet();

      // get the parents for this node
      // resolve structure
      nodelist2 = selectElements(definition, "GIVEN");
      for (int iParent = 0; iParent < nodelist2.size(); iParent++) {
        Node parentName = ((Node) nodelist2.elementAt(iParent)).getFirstChild();
        String sParentName = ((CharacterData) (parentName)).getData();
        int nParent = -1;
        for (int iBase = 0; iBase < sBaseNames.size(); iBase++) {
          if (sParentName.equals((String) sBaseNames.elementAt(iBase))) {
            nParent = nBase + iBase;
View Full Code Here

    if (m_bNeedsUndoAction) {
      addUndoAction(new RenameAction(nTargetNode, getNodeName(nTargetNode), sName));
    }
    Attribute att = m_Instances.attribute(nTargetNode);
    int nCardinality = att.numValues();
    FastVector values = new FastVector(nCardinality);
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      values.addElement(att.value(iValue));
    }
    replaceAtt(nTargetNode, sName, values);
  } // setNodeName
View Full Code Here

TOP

Related Classes of weka.core.FastVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.