Examples of PotentialTable


Examples of unbbayes.prs.bn.PotentialTable

    screen.getTxtName().setEnabled(true);
    screen.getTxtDescription().setText(node.getDescription());
    screen.getTxtName().setText(node.getName());

    final JTable table;
    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();

      // put the values of the probabilistic table in the jth row and ith
      // column, picking up the values in a double collection in potTab.
      for (int i = 1, k = 0; i < table.getColumnCount(); i++, k += states) {
        for (int j = variables - 1, l = 0; j < table.getRowCount(); j++, l++) {
          table.setValueAt("" + df.format(potTab.getValue(k + l)), j,
              i);
        }
      }

    } else {
      // decision

      // the number of rows in this case is the number of states of the
      // node and the number of columns is always 1.
      // int rows = node.getStatesSize();
      // int columns = 1;

      // there is no potential table and the number of variables is the
      // number of parents this node has.
      potTab = null;
      variables = node.getParents().size();

      table = new JTable(node.getStatesSize(), 1);
      // put the name of each state in the first and only column.
      for (int i = 0; i < node.getStatesSize(); i++) {
        table.setValueAt(node.getStateAt(i), i, 0);
      }

    }

    table.setTableHeader(null);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.getModel().addTableModelListener(new TableModelListener() {
      public void tableChanged(TableModelEvent e) {
        if (e.getLastRow() < variables - 1) {
          return;
        }
        if (e.getColumn() == 0) {
          if (!table.getValueAt(e.getLastRow(), e.getColumn())
              .equals("")) {
            node.setStateAt(table.getValueAt(e.getLastRow(),
                e.getColumn()).toString(), e.getLastRow()
                - (table.getRowCount() - node.getStatesSize()));
          }
        } else {
          String temp = table.getValueAt(e.getLastRow(),
              e.getColumn()).toString().replace(',', '.');
          try {
            float valor = Float.parseFloat(temp);
            potTab.setValue((e.getColumn() - 1) * node.getStatesSize() + e.getLastRow(), valor);
          } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(null,
                resource.getString("error"),
                resource.getString("realNumberError"),
                JOptionPane.ERROR_MESSAGE);
            table.revalidate();
            table.setValueAt(""
                + potTab.getValue((e.getColumn() - 1) * node.getStatesSize() + e.getLastRow()),
                e.getLastRow(), e.getColumn());
          }
        }
      }
    });
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

        String strConbined =  "defineState( Continuous ," + textInputArea2.getText() +");"+ textInputArea1.getText();
        String str = strConbined + " createCPT( "+ node.getName() +" );";
         controller.compileWork(str);
       
        CPS.getInstance().setScript(getProbabilityFunctionOwner(), strConbined );
        PotentialTable auxTab = (PotentialTable) ((IRandomVariable) node).getProbabilityFunction();
        GUIPotentialTable table = new GUIPotentialTable( auxTab );
        table.showTable("CPT");
        
      }
    };     
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

        node.appendState("State3");
        node.appendState("State4");
        node
            .setName("longname-longname-longname-longname-longname-longname-longname-longname");
        node.setDescription(node.getName());
        PotentialTable auxTabProb = (PotentialTable)((IRandomVariable) node)
            .getProbabilityFunction();
        auxTabProb.addVariable(node);
        auxTabProb.setValue(0, 1);

        UShapeProbabilisticNode shape = new UShapeProbabilisticNode(
            m_Canvas, (ProbabilisticNode) node, (int) node
                .getPosition().x
                - node.getWidth() / 2,
            (int) node.getPosition().y - node.getHeight() / 2, node
                .getWidth(), node.getHeight());
        m_Canvas.addShape(shape);
        shape.setShapeType(UShapeProbabilisticNode.STYPE_BAR);

        // Test
        ProbabilisticNode node2 = new ProbabilisticNode();
        node2.setPosition(160, 80);
        node2.appendState("firstStateProbabilisticName");
        node2.setName("123456789abcdefghijklmnopqrstuvwxyz");
        node2.setDescription(node2.getName());
        PotentialTable auxTabProb2 =(PotentialTable) ((IRandomVariable) node2)
            .getProbabilityFunction();
        auxTabProb2.addVariable(node2);
        auxTabProb2.setValue(0, 1);

        UShapeProbabilisticNode shape2 = new UShapeProbabilisticNode(
            m_Canvas, (ProbabilisticNode) node2, (int) node2
                .getPosition().x
                - node2.getWidth() / 2, (int) node2
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

      //create cpt
      CPSCompilerMain.This().createCPT(EDB.This().get("ROOT.NODES."+n.getName()));  
     
      int coord[] = new int[n.getParentNodes().size()+1];
      EDBUnit cpt = EDB.This().get("ROOT.NODES."+n.getName()+".CPT");
      PotentialTable auxTab = (PotentialTable) ((IRandomVariable) n).getProbabilityFunction();
     
      getNewStatesValueToBNNode( n, cpt,  coord, auxTab );
     
      //set script from BN to EDB
      String sc = CPS.getInstance().getScript(n);
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

    // add second and next states      
    AddNewStatesToBNNode( type, cNode, stateIndexMap, c, stateFirst.getNext() );

    /////////////////////////////////////////////////////////////////////////////////////
    //3. fill zero on table
    PotentialTable auxTab = (PotentialTable) ((IRandomVariable) cNode).getProbabilityFunction();
    int curStateSize = cNode.getStatesSize()
   
    for( INode parent : cNode.getParentNodes() )
      curStateSize *= parent.getStatesSize();
   
    for( int i = 0; i < curStateSize; i++ )
      auxTab.addValueAt(i, 0);
   
    auxTab.setTableSize(curStateSize);
 
    /////////////////////////////////////////////////////////////////////////////////////
    //4. add new values in the states of BN
    // EX]
    // CPT[Isa]parent1.state1{parent1.Name}[Isa]parent2.state1{parent2.Name}[Next]cur.state1[Next]cur.state2
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

      uNode.appendState(stateFirst.getName());
      stateIndexMap.put(stateFirst.getName(),  c++);
      AddNewStatesToBNNode(uNode, stateIndexMap, c, stateFirst.getNext());
       
      //initialize Potential Table
      PotentialTable auxTab = (PotentialTable) ((IRandomVariable) uNode).getProbabilityFunction();
      auxTab.addVariable(uNode);
 
    }else
    if( type.equalsIgnoreCase("Continuous") ){
      //create new Continuous uNode
      uNode = new GmmNodePluginStub();
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

      // add second and next states      
      AddNewStatesToBNNode( uNode, stateIndexMap, c, stateFirst.getNext() );
    
      /////////////////////////////////////////////////////////////////////////////////////
      //3. fill zero on table
      PotentialTable auxTab = (PotentialTable) ((IRandomVariable) uNode).getProbabilityFunction();
      int curStateSize = uNode.getStatesSize()
     
      for( INode parent : uNode.getParentNodes() )
        curStateSize *= parent.getStatesSize();
     
      for( int i = 0; i < curStateSize; i++ )
        auxTab.addValueAt(i, 0);
     
      auxTab.setTableSize(curStateSize);
   
      /////////////////////////////////////////////////////////////////////////////////////
      //4. add new values in the states of BN
      // EX]
      // CPT[Isa]parent1.state1{parent1.Name}[Isa]parent2.state1{parent2.Name}[Next]cur.state1[Next]cur.state2
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.