Package unbbayes.prs

Examples of unbbayes.prs.Node


    final JTable table;
    final PotentialTable potTab;

    /* Check if the node represents a numeric attribute */
    if (node.getStatesSize() == 0) {
      Node parent = node.getParents().get(0);
      int numClasses = parent.getStatesSize();
      double[] mean = node.getMean();
      double[] stdDev = node.getStandardDeviation();

      table = new JTable(3, numClasses + 1);
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      table.setTableHeader(null);

      /* First column */
      table.setValueAt(parent.getName(), 0, 0);
      table.setValueAt(resource.getString("mean"), 1, 0);
      table.setValueAt(resource.getString("stdDev"), 2, 0);

      /* Other columns */
      for (int i = 0; i < numClasses; i++) {
        table.setValueAt(parent.getStateAt(i), 0, i + 1);
        table.setValueAt(mean[i], 1, i + 1);
        table.setValueAt(stdDev[i], 2, i + 1);
      }

      return table;
View Full Code Here


    final PotentialTable potTab;
    final int variables;

    /* Check if the node represents a numeric attribute */
    if (node.getStatesSize() == 0) {
      Node parent = node.getParents().get(0);
      int numClasses = parent.getStatesSize();
      double[] mean = node.getMean();
      double[] stdDev = node.getStandardDeviation();

      table = new JTable(3, numClasses + 1);
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      table.setTableHeader(null);

      /* First column */
      table.setValueAt(parent.getName(), 0, 0);
      table.setValueAt(resource.getString("mean"), 1, 0);
      table.setValueAt(resource.getString("stdDev"), 2, 0);

      /* Other columns */
      for (int i = 0; i < numClasses; i++) {
        table.setValueAt(parent.getStateAt(i), 0, i + 1);
        table.setValueAt(mean[i], 1, i + 1);
        table.setValueAt(stdDev[i], 2, i + 1);
      }

      return table;
    }

    if (node instanceof IRandomVariable) {
      potTab = (PotentialTable)((IRandomVariable) node).getProbabilityFunction();

      int states = 1;
      variables = potTab.variableCount();

      // calculate the number of states by multiplying the number of
      // states that each father (variables) has. Where variable 0 is the
      // node itself. That is why it starts at 1.
      /*
       * Ex: states = 2 * 2;
       *
       * |------------------------------------------------------| | Father
       * 2 | State 1 | State 2 |
       * |--------------|-------------------|-------------------| | Father
       * 1 | State 1 | State 2 | State 1 | State 2 |
       * |------------------------------------------------------| | Node
       * State 1 | 1 | 1 | 1 | 1 | | Node State 2 | 0 | 0 | 0 | 0 |
       *
       */
      states = potTab.tableSize() / node.getStatesSize();
      /*
       * for (int count = 1; count < variables; count++) { states *=
       * potTab.getVariableAt(count).getStatesSize(); }
       */

      // the number of rows is the number of states the node has plus the
      // number of fathers (variables - 1, because one of the variables
      // is the node itself).
      int rows = node.getStatesSize() + variables - 1;

      // the number of columns is the number of states that we calculate
      // before plus one that is the column where the fathers names and
      // the states of the node itself will be placed.
      int columns = states + 1;

      table = new JTable(rows, columns);

      // put the name of the states of the node in the first column
      // starting in the (variables - 1)th row (number of fathers). That
      // is because on the rows before that there will be placed the
      // name of the fathers.
      for (int k = variables - 1, l = 0; k < table.getRowCount(); k++, l++) {
        table.setValueAt(node.getStateAt(l), k, 0);
      }

      // put the name of the father and its states' name in the right
      // place.
      for (int k = variables - 1, l = 0; k >= 1; k--, l++) {
        Node variable = (Node)potTab.getVariableAt(k);

        // the number of states is the multiplication of the number of
        // states of the other fathers above this one.
        states /= variable.getStatesSize();

        // put the name of the father in the first column.
        table.setValueAt(variable.getName(), l, 0);

        // put the name of the states of this father in the lth row
        // and ith column, repeating the name if necessary (for each
        // state of the father above).
        for (int i = 0; i < table.getColumnCount() - 1; i++) {
          table.setValueAt(variable.getStateAt((i / states)
              % variable.getStatesSize()), l, i + 1);
        }
      }

      // now states is the number of states that the node has.
      states = node.getStatesSize();
View Full Code Here

        // listener responsible for updating the node's name.
        txtName.addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            Object selected = netWindow.getGraphPane().getSelected();
            if (selected instanceof Node) {
              Node nodeAux = (Node)selected;
              if ((e.getKeyCode() == KeyEvent.VK_ENTER) && (txtName.getText().length()>0)) {
                try {
                    String name = txtName.getText(0,txtName.getText().length());
                    matcher = wordPattern.matcher(name);
                    if (matcher.matches()) {
                      nodeAux.setName(name);
                    //by young3
                      netWindow.getGraphPane().updateSelectedNode();
                    //  repaint();
                    else {
                        JOptionPane.showMessageDialog(netWindow, resource.getString("nameError"), resource.getString("nameException"), JOptionPane.ERROR_MESSAGE);
                        txtName.selectAll();
                    }
                }
                catch (javax.swing.text.BadLocationException ble) {
                  ble.printStackTrace();
                }
              }
            }
          }
        });


        // listener respons�スvel pela atualiza�ス�スo do texo da descri�ス�スo do n�ス
        txtDescription.addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            Object selected = netWindow.getGraphPane().getSelected();
            if (selected instanceof Node)
            {
              Node nodeAux = (Node)selected;
              if ((e.getKeyCode() == KeyEvent.VK_ENTER) && (txtDescription.getText().length()>0)) {
                try {
                    String name = txtDescription.getText(0,txtDescription.getText().length());
                    matcher = descriptionPattern.matcher(name);
                    if (matcher.matches()) {
                      nodeAux.setDescription(name);
                      //by young3
                      netWindow.getGraphPane().updateSelectedNode();
                      repaint();
                    } else {
                        JOptionPane.showMessageDialog(netWindow, resource.getString("descriptionError"), resource.getString("nameException"), JOptionPane.ERROR_MESSAGE);
View Full Code Here

  public JTable makeTable() {
    JTable table;
    int nStates = 1;
    // Number of variables
    int nVariables = potentialTable.variableCount();
    Node node = (Node)potentialTable.getVariableAt(0);
    NumberFormat df = NumberFormat.getInstance(Locale.getDefault());
    df.setMaximumFractionDigits(4);

    // calculate the number of states by multiplying the number of
    // states that each father (variables) has. Where variable 0 is the
    // node itself. That is why we divide the table size by the number
    // of states in the node itself.
    /*
     * Ex: states = 12 / 3;
     *
     * |------------------------------------------------------|
     * | Father 2     |      State 1      |      State 2      |
     * |--------------|-------------------|-------------------|
     * | Father 1     | State 1 | State 2 | State 1 | State 2 |
     * |------------------------------------------------------|
     * | Node State 1 |    1    |    1    |    1    |    1    |
     * | Node State 2 |    0    |    0    |    0    |    0    |
     * | Node State 3 |    0    |    0    |    0    |    0    |
     * |------------------------------------------------------|
     *
     */
    nStates = potentialTable.tableSize() / node.getStatesSize();

    // the number of rows is the number of states the node has.
    int rows = node.getStatesSize();

    // the number of columns is the number of states that we calculated
    // before plus one that is the column where the fathers names and
    // the states of the node itself will be placed.
    int columns = nStates + 1;
   
    // Constructing the data of the data model.
    /*
     * Ex: data[3][4 + 1]
     * |------------------------------------------------------|
     * | Node State 1 |    1    |    1    |    1    |    1    |
     * | Node State 2 |    0    |    0    |    0    |    0    |
     * | Node State 3 |    0    |    0    |    0    |    0    |
     * |------------------------------------------------------|
     */
    String[][] data = new String[rows][columns];

    // Constructing the first header's row
    /*
     * Ex: Following the example above this is the first header's row.
     *
     * |--------------|-------------------|-------------------|
     * | Father 1     | State 1 | State 2 | State 1 | State 2 |
     * |------------------------------------------------------|
     *
     */
    String[] column = new String[data[0].length];
    Node firtHeaderNode;
    // If there is no father, this is going to be the first header's
    // row:
    /*
     * |-----------|---------------|
     * | State     |  Probability  |
     * |---------------------------|
     *
     */
    if (nVariables == 1) {
      column[0] = "State";
      column[1] = "Probability";
    } else {
      firtHeaderNode = (Node)potentialTable.getVariableAt(1);
      /*
       * Ex: Here we get the variable "Father 1" and set its name in
       *     the header.
       *
       * |--------------|
       * | Father 1     |
       * |---------------
       *
       */
      column[0] = firtHeaderNode.getName();
      for (int i = 0; i < data[0].length - 1; i++) {
        if (nVariables > 1) {
          // Reapeats all states in the node until there are cells to
          // fill.
          /*
           * Ex: Following the example above. Here the states go.
           *
           * |-------------------|-------------------|
           * | State 1 | State 2 | State 1 | State 2 |
           * ----------------------------------------|
           *
           */
          column[i + 1] = firtHeaderNode.getStateAt(i % firtHeaderNode.getStatesSize());
        }
      }
    }
   
    // Filling the data of the data model.
    /*
     * Ex: Fill the data[3][5] constructed above.
     * |------------------------------------------------------|
     * | Node State 1 |    1    |    1    |    1    |    1    |
     * | Node State 2 |    0    |    0    |    0    |    0    |
     * | Node State 3 |    0    |    0    |    0    |    0    |
     * |------------------------------------------------------|
     */
    // The values are arranged in the potential table as a vector.
    /*
     * Ex: This would be the vector in the potential table.
     * |-------------------------------------------------------------------|
     * | Vector Position | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
     * | Vector Value    | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0  | 0  |
     * |-------------------------------------------------------------------|
     */
    // So, for each column we jump the number of values corresponding
    // that column, that is, the number of rows.
    for (int c = 1, n = 0; c < columns; c++, n += rows) {
      for (int r = 0; r < rows; r++) {
        // So, data[0][3] = vector[6 + 0] = 1
        data[r][c] = "" + "" + df.format(potentialTable.getValue(n + r));
      }
    }
    // Now that we filled the values, we are going to put this node's
    // states name.
    /*
     * Ex: Fill the data[i][0] constructed above, that is, its states
     *     name.
     * |---------------
     * | Node State 1 |
     * | Node State 2 |
     * | Node State 3 |
     * |---------------
     */
    for (int i = 0; i < rows; i++) {
      data[i][0] = node.getStateAt(i);
    }
   
    // Constructing the table so far.
    /*
     * Ex: The table so far, following the example above.
     *
     * |--------------|-------------------|-------------------|
     * | Father 1     | State 1 | State 2 | State 1 | State 2 |
     * |------------------------------------------------------|
     * | Node State 1 |    1    |    1    |    1    |    1    |
     * | Node State 2 |    0    |    0    |    0    |    0    |
     * | Node State 3 |    0    |    0    |    0    |    0    |
     * |------------------------------------------------------|
     *
     */
    DefaultTableModel model = new DefaultTableModel();
    model.setDataVector(data, column);
    table = new JTable();
   
    // Setup to allow grouping the header.
    table.setColumnModel(new GroupableTableColumnModel());
    table.setTableHeader(new GroupableTableHeader(
        (GroupableTableColumnModel) table.getColumnModel()));
    table.setModel(model);
   
    // Setup Column Groups
    GroupableTableColumnModel cModel = (GroupableTableColumnModel) table
        .getColumnModel();
    ColumnGroup cNodeGroup = null;
    ColumnGroup cNodeTempGroup = null;
    ColumnGroup cGroup = null;
    List<ColumnGroup> cGroupList = new ArrayList<ColumnGroup>();
    List<ColumnGroup> previousCGroupList = new ArrayList<ColumnGroup>();
    int columnIndex;
    boolean firstNode = true;
    int sizeColumn = 1;
    // Sets default color for parents name in first column.
    /*
     * |---------------
     * | Father 2     |
     * |--------------|
     * | Father 1     |
     * |---------------
     *
     */
    cModel.getColumn(0).setHeaderRenderer(new GroupableTableCellRenderer());
    // Sets default color for node's states
    /*
     * |---------------
     * | Node State 1 |
     * | Node State 2 |
     * | Node State 3 |
     * |---------------
     *
     */
    cModel.getColumn(0).setCellRenderer(new GroupableTableCellRenderer(Color.BLACK, Color.YELLOW));
    // Fill all other headers, but the first (that has already been
    // set). It ignores k = 0 (the node itself) and k = 1 (the fist
    // father).
    for (int k = 2; k < nVariables; k++) {
      Node parent = (Node)potentialTable.getVariableAt(k);
      int nPreviousParentStates = potentialTable.getVariableAt(k-1).getStatesSize();
      sizeColumn *= nPreviousParentStates;
      // Set the node name as a header in the first column
      if (!firstNode) {
        cNodeTempGroup = cNodeGroup;
        cNodeGroup = new ColumnGroup(new GroupableTableCellRenderer(), parent.getName());
        cNodeGroup.add(cNodeTempGroup);
      } else {
        cNodeGroup = new ColumnGroup(new GroupableTableCellRenderer(), parent.getName());
        cNodeGroup.add(cModel.getColumn(0));
      }
      columnIndex = 1;
      cGroup = null;
      while (columnIndex <= nStates) {
        for (int i = 0; i < parent.getStatesSize(); i++) {
          cGroup = new ColumnGroup(parent.getStateAt(i));
          if (!firstNode) {
            for (int j = 0; j < nPreviousParentStates; j++) {
              ColumnGroup group = previousCGroupList.get(columnIndex-1);
              cGroup.add(group);
              columnIndex++;
View Full Code Here

        DefaultMutableTreeNode parent =
          (DefaultMutableTreeNode) (((DefaultMutableTreeNode) value)
            .getParent());
        Object obj = objectsMap.get((DefaultMutableTreeNode) parent);
        if (obj != null) {
          Node node = (Node) obj;
          if (node.getInformationType() == Node.DESCRIPTION_TYPE) {
            setIcon(yellowBallIcon);
          } else {
            setIcon(greenBallIcon);
          }
        } else {
          setIcon(yellowBallIcon);
        }
      } else {
        Object obj = objectsMap.get((DefaultMutableTreeNode) value);
        if (obj != null) {
          Node node = (Node) obj;
          if (node.getInformationType() == Node.DESCRIPTION_TYPE) {
            setOpenIcon(folderSmallIcon);
            setClosedIcon(folderSmallIcon);
            setIcon(folderSmallIcon);
          } else {
            setOpenIcon(folderSmallDisabledIcon);
View Full Code Here

   * Conditionants must be parents referenced by this.node 
   * @return if node with name == nodeName is a valid conditionant.
   */
  protected boolean isValidConditionant(MultiEntityBayesianNetwork mebn, ResidentNode node, String conditionantName) {
   
    Node conditionant = mebn.getNode(conditionantName);
   
   
   
    if (conditionant != null) {
     
View Full Code Here

   * Consistency check C09
   * Conditionants must have a consistent possible value
   * @return whether conditionantValue is a valid state for a conditionant with name conditionantName
   */
  protected boolean isValidConditionantValue(MultiEntityBayesianNetwork mebn, String conditionantName, String conditionantValue) {
    Node conditionant = mebn.getNode(conditionantName);
    if (conditionant == null) {
      // Debug.println("No conditionant of name " + conditionantName);
      return false;
    }
    //// Debug.println("Conditionant node found: " + conditionant.getName());
View Full Code Here

     if(lastCPTISA != null && lastCPTISA.map.size() != 0 ){
      for( String str : lastCPTISA.map.keySet() ){
        EDBUnit t = lastCPTISA.map.get(str)
       
        int variableIndex = auxTab.indexOfVariable(t.getData());
        Node n = (Node)auxTab.getVariableAt(variableIndex);
        coord[variableIndex] = getStateIndexFromBN(n, t.getName());
       
        getNewStatesValueToBNNode(cNode, t, coord, auxTab);
      }
    }
View Full Code Here

      for( String str : lastCPTISA.map.keySet() ){
        EDBUnit t = lastCPTISA.map.get(str);
        //t.print("");
        //System.out.println(auxTab);
        int variableIndex = auxTab.indexOfVariable( t.getData() );
        Node n = (Node)auxTab.getVariableAt(variableIndex);
        coord[variableIndex] = getStateIndexFromBN( n, t.getName() );
       
        AddNewStatesValueToBNNode(type, t, coord, stateIndexMap, auxTab);
      }
    }
View Full Code Here

     if(lastCPTISA != null && lastCPTISA.map.size() != 0 ){
      for( String str : lastCPTISA.map.keySet() ){
        EDBUnit t = lastCPTISA.map.get(str)
       
        int variableIndex = auxTab.indexOfVariable( t.getData() );
        Node n = (Node)auxTab.getVariableAt(variableIndex);
        coord[variableIndex] = getStateIndexFromBN( n, t.getName() );
       
        AddNewStatesValueToBNNode( t, coord, stateIndexMap, auxTab);
      }
    }
View Full Code Here

TOP

Related Classes of unbbayes.prs.Node

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.