Examples of FastVector


Examples of weka.core.FastVector

   * @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

Examples of weka.core.FastVector

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

Examples of weka.core.FastVector

    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

Examples of weka.core.FastVector

    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

Examples of weka.core.FastVector

    if (m_bNeedsUndoAction) {
      addUndoAction(new RenameValueAction(nTargetNode, sValue, sNewValue));
    }
    Attribute att = m_Instances.attribute(nTargetNode);
    int nCardinality = att.numValues();
    FastVector values = new FastVector(nCardinality);
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      if (att.value(iValue).equals(sValue)) {
        values.addElement(sNewValue);
      } else {
        values.addElement(att.value(iValue));
      }
    }
    replaceAtt(nTargetNode, att.name(), values);
  } // renameNodeValue
View Full Code Here

Examples of weka.core.FastVector

    if (m_bNeedsUndoAction) {
      addUndoAction(new AddValueAction(nTargetNode, sNewValue));
    }
    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));
    }
    values.addElement(sNewValue);
    replaceAtt(nTargetNode, att.name(), values);

    // update distributions of this node
    Estimator[] distributions = m_Distributions[nTargetNode];
    int nNewCard = values.size();
    for (int iParent = 0; iParent < distributions.length; iParent++) {
      DiscreteEstimatorBayes distribution = new DiscreteEstimatorBayes(nNewCard, 0);
      for (int iValue = 0; iValue < nNewCard - 1; iValue++) {
        distribution.addValue(iValue, distributions[iParent].getProbability(iValue));
      }
View Full Code Here

Examples of weka.core.FastVector

    if (m_bNeedsUndoAction) {
      addUndoAction(new DelValueAction(nTargetNode, sValue));
    }
    Attribute att = m_Instances.attribute(nTargetNode);
    int nCardinality = att.numValues();
    FastVector values = new FastVector(nCardinality);
    int nValue = -1;
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      if (att.value(iValue).equals(sValue)) {
        nValue = iValue;
      } else {
        values.addElement(att.value(iValue));
      }
    }
    if (nValue < 0) {
      // could not find value
      throw new Exception("Node " + nTargetNode + " does not have value (" + sValue + ")");
    }
    replaceAtt(nTargetNode, att.name(), values);

    // update distributions
    Estimator[] distributions = m_Distributions[nTargetNode];
    int nCard = values.size();
    for (int iParent = 0; iParent < distributions.length; iParent++) {
      DiscreteEstimatorBayes distribution = new DiscreteEstimatorBayes(nCard, 0);
      double sum = 0;
      for (int iValue = 0; iValue < nCard; iValue++) {
        sum += distributions[iParent].getProbability(iValue);
View Full Code Here

Examples of weka.core.FastVector

  /** return list of children of a node
   * @param nTargetNode index of node of interest
   */
  public FastVector getChildren(int nTargetNode) {
    FastVector children = new FastVector();
    for (int iNode = 0; iNode < getNrOfNodes(); iNode++) {
      if (m_ParentSets[iNode].contains(nTargetNode)) {
        children.addElement(iNode);
      }
    }
    return children;
  } // getChildren
View Full Code Here

Examples of weka.core.FastVector

    m_nCurrentEditAction++;
  } // addUndoAction

  /** remove all actions from the undo stack */
  public void clearUndoStack() {
    m_undoStack = new FastVector();
    //m_sXMLStack = new FastVector();
    m_nCurrentEditAction = -1;
    m_nSavedPointer = -1;
  } // clearUndoStack
View Full Code Here

Examples of weka.core.FastVector

        so = new SerializedObject(m_ParentSets[nTargetNode]);
        m_ParentSet = (ParentSet) so.getObject();
      } catch (Exception e) {
        e.printStackTrace();
      }
      m_deleteArcActions = new FastVector();
      for (int iNode = 0; iNode < getNrOfNodes(); iNode++) {
        if (m_ParentSets[iNode].contains(nTargetNode)) {
          m_deleteArcActions.addElement(new DeleteArcAction(nTargetNode, iNode));
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.