Examples of PotentialTable


Examples of unbbayes.prs.bn.PotentialTable

    // Define if person communicates with terrorist
    int communicatesWithTerroristsState = 0;
    ProbabilisticNode child = (ProbabilisticNode) pn
        .getNode("communicatesWithTerrorists_person");
    PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
    int[] coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    ProbabilisticNode parent = (ProbabilisticNode) pn
        .getNode("isTerrorist_person");
    coord[table.getVariableIndex(parent)] = isTerroristState;
    if (Math.random() <= table.getValue(coord)) {
      communicatesWithTerroristsState = 0;
      person.setCommunicatesWithTerrorists(true);
    } else {
      communicatesWithTerroristsState = 1;
      person.setCommunicatesWithTerrorists(false);
    }

    // Define if person uses weblog
    child = (ProbabilisticNode) pn.getNode("usesWeblog_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    parent = (ProbabilisticNode) pn.getNode("communicatesWithTerrorists_person");
    coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
    if (Math.random() <= table.getValue(coord)) {
      person.setUsesWeblog(true);
    } else {
      person.setUsesWeblog(false);
    }

    // Define if person uses email
    child = (ProbabilisticNode) pn.getNode("usesEmail_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
    if (Math.random() <= table.getValue(coord)) {
      person.setUsesEmail(true);
    } else {
      person.setUsesEmail(false);
    }
   
    // Define if person uses cellular
    child = (ProbabilisticNode) pn.getNode("usesCellular_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
    if (Math.random() <= table.getValue(coord)) {
      person.setUsesCellular(true);
    } else {
      person.setUsesCellular(false);
    }
   
    // Define if person uses chatroom
    child = (ProbabilisticNode) pn.getNode("usesChatroom_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    coord[table.getVariableIndex(parent)] = communicatesWithTerroristsState;
    if (Math.random() <= table.getValue(coord)) {
      person.setUsesChatroom(true);
    } else {
      person.setUsesChatroom(false);
    }
  }
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

    // Define if person has terrorist beliefs
    int hasTerroristBeliefsState = 0;
    ProbabilisticNode child = (ProbabilisticNode) pn
        .getNode("hasTerroristBeliefs_person");
    PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
    int[] coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    ProbabilisticNode parent = (ProbabilisticNode) pn
        .getNode("isTerrorist_person");
    coord[table.getVariableIndex(parent)] = isTerroristState;
    if (Math.random() <= table.getValue(coord)) {
      hasTerroristBeliefsState = 0;
      person.setCommunicatesWithTerrorists(true);
    } else {
      hasTerroristBeliefsState = 1;
      person.setCommunicatesWithTerrorists(false);
    }

    // Define if person has kinship to terrorist (none, few, or many)
    child = (ProbabilisticNode) pn.getNode("hasKinshipToTerrorist_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    parent = (ProbabilisticNode) pn.getNode("hasTerroristBeliefs_person");
    coord[table.getVariableIndex(parent)] = hasTerroristBeliefsState;
    float noneUpperBound = table.getValue(coord);
    coord[0] = 1;
    float fewUpperBound = noneUpperBound + table.getValue(coord);
    float randomProbability = (float) Math.random();
    if (randomProbability <= noneUpperBound) {
      person.setHasKinshipToTerrorist(Quantity.None);
    } else if (randomProbability <= fewUpperBound) {
      person.setHasKinshipToTerrorist(Quantity.Few);
    } else {
      person.setHasKinshipToTerrorist(Quantity.Many);
    }

    // Define if person has friendship with terrorist (none, few, or many)
    child = (ProbabilisticNode) pn.getNode("hasFriendshipWithTerrorist_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    parent = (ProbabilisticNode) pn.getNode("hasTerroristBeliefs_person");
    coord[table.getVariableIndex(parent)] = hasTerroristBeliefsState;
    noneUpperBound = table.getValue(coord);
    coord[0] = 1;
    fewUpperBound = noneUpperBound + table.getValue(coord);
    randomProbability = (float) Math.random();
    if (randomProbability <= noneUpperBound) {
      person.setHasFriendshipWithTerrorist(Quantity.None);
    } else if (randomProbability <= fewUpperBound) {
      person.setHasFriendshipWithTerrorist(Quantity.Few);
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

    // Define the cluster partition of a person (CentralStaff, SoutheastAsia,
    // MaghrebArab, CoreArab, or Other)
    int hasClusterPartitionState = 0;
    ProbabilisticNode child = (ProbabilisticNode) pn
        .getNode("hasClusterPartition_person");
    PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
    int[] coord = new int[child.getParents().size() + 1];
    ProbabilisticNode parent = (ProbabilisticNode) pn
        .getNode("isTerrorist_person");
    coord[table.getVariableIndex(parent)] = isTerroristState;
    coord[0] = 0;
    float centralStaffUpperBound = table.getValue(coord);
    coord[0] = 1;
    float southeastAsiaUpperBound = centralStaffUpperBound + table.getValue(coord);
    coord[0] = 2;
    float maghrebArabUpperBound = southeastAsiaUpperBound + table.getValue(coord);
    coord[0] = 3;
    float coreArabUpperBound = maghrebArabUpperBound + table.getValue(coord);
    float randomProbability = (float) Math.random();
    if (randomProbability <= centralStaffUpperBound) {
      hasClusterPartitionState = 0;
      person.setHasClusterPartition(ClusterPartition.CentralStaff);
    } else if (randomProbability <= southeastAsiaUpperBound) {
      hasClusterPartitionState = 1;
      person.setHasClusterPartition(ClusterPartition.SoutheastAsia);
    } else if (randomProbability <= maghrebArabUpperBound) {
      hasClusterPartitionState = 2;
      person.setHasClusterPartition(ClusterPartition.MaghrebArab);
    } else if (randomProbability <= coreArabUpperBound) {
      hasClusterPartitionState = 3;
      person.setHasClusterPartition(ClusterPartition.CoreArab);
    } else {
      hasClusterPartitionState = 4;
      person.setHasClusterPartition(ClusterPartition.Other);
    }

    // Define the person nationality (Egypt, SaudiArabia, etc)
    child = (ProbabilisticNode) pn.getNode("hasNationality_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
    coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
    coord[0] = 0;
    float egyptUpperBound = table.getValue(coord);
    coord[0] = 1;
    float saudiArabiaUpperBound = egyptUpperBound + table.getValue(coord);
    coord[0] = 2;
    float kuwaitUpperBound = saudiArabiaUpperBound + table.getValue(coord);
    coord[0] = 3;
    float jordanUpperBound = kuwaitUpperBound + table.getValue(coord);
    coord[0] = 4;
    float iraqUpperBound = jordanUpperBound + table.getValue(coord);
    coord[0] = 5;
    float sudanUpperBound = iraqUpperBound + table.getValue(coord);
    coord[0] = 6;
    float libyaUpperBound = sudanUpperBound + table.getValue(coord);
    coord[0] = 7;
    float lebannonUpperBound = libyaUpperBound + table.getValue(coord);
    coord[0] = 8;
    float indonesiaUpperBound = lebannonUpperBound + table.getValue(coord);
    coord[0] = 9;
    float malaysiaUpperBound = indonesiaUpperBound + table.getValue(coord);
    coord[0] = 10;
    float singaporeUpperBound = malaysiaUpperBound + table.getValue(coord);
    coord[0] = 11;
    float pakistanUpperBound = singaporeUpperBound + table.getValue(coord);
    coord[0] = 12;
    float philippinesUpperBound = pakistanUpperBound + table.getValue(coord);
    coord[0] = 13;
    float franceUpperBound = philippinesUpperBound + table.getValue(coord);
    coord[0] = 14;
    float algeriaUpperBound = franceUpperBound + table.getValue(coord);
    coord[0] = 15;
    float moroccoUpperBound = algeriaUpperBound + table.getValue(coord);
    coord[0] = 16;
    float syriaUpperBound = moroccoUpperBound + table.getValue(coord);
    coord[0] = 17;
    float tunisiaUpperBound = syriaUpperBound + table.getValue(coord);
    coord[0] = 18;
    float uaeUpperBound = tunisiaUpperBound + table.getValue(coord);
    coord[0] = 19;
    float yemenUpperBound = uaeUpperBound + table.getValue(coord);
    randomProbability = (float) Math.random();
    if (randomProbability <= egyptUpperBound) {
      person.setHasNationality(Nationality.Egypt);
    } else if (randomProbability <= saudiArabiaUpperBound) {
      person.setHasNationality(Nationality.SaudiArabia);
    } else if (randomProbability <= kuwaitUpperBound) {
      person.setHasNationality(Nationality.Kuwait);
    } else if (randomProbability <= jordanUpperBound) {
      person.setHasNationality(Nationality.Jordan);
    } else if (randomProbability <= iraqUpperBound) {
      person.setHasNationality(Nationality.Iraq);
    } else if (randomProbability <= sudanUpperBound) {
      person.setHasNationality(Nationality.Sudan);
    } else if (randomProbability <= libyaUpperBound) {
      person.setHasNationality(Nationality.Libya);
    } else if (randomProbability <= lebannonUpperBound) {
      person.setHasNationality(Nationality.Lebannon);
    } else if (randomProbability <= indonesiaUpperBound) {
      person.setHasNationality(Nationality.Indonesia);
    } else if (randomProbability <= malaysiaUpperBound) {
      person.setHasNationality(Nationality.Malaysia);
    } else if (randomProbability <= singaporeUpperBound) {
      person.setHasNationality(Nationality.Singapore);
    } else if (randomProbability <= pakistanUpperBound) {
      person.setHasNationality(Nationality.Pakistan);
    } else if (randomProbability <= philippinesUpperBound) {
      person.setHasNationality(Nationality.Philippines);
    } else if (randomProbability <= franceUpperBound) {
      person.setHasNationality(Nationality.France);
    } else if (randomProbability <= algeriaUpperBound) {
      person.setHasNationality(Nationality.Algeria);
    } else if (randomProbability <= moroccoUpperBound) {
      person.setHasNationality(Nationality.Morocco);
    } else if (randomProbability <= syriaUpperBound) {
      person.setHasNationality(Nationality.Syria);
    } else if (randomProbability <= tunisiaUpperBound) {
      person.setHasNationality(Nationality.Tunisia);
    } else if (randomProbability <= uaeUpperBound) {
      person.setHasNationality(Nationality.UAE);
    } else if (randomProbability <= yemenUpperBound) {
      person.setHasNationality(Nationality.Yemen);
    } else {
      person.setHasNationality(Nationality.Other);
    }

    // Define the person economic standing (UpperClass, MiddleClass, or
    // LowerClass)
    child = (ProbabilisticNode) pn.getNode("hasEconomicStanding_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
    coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
    coord[0] = 0;
    float upperClassUpperBound = table.getValue(coord);
    coord[0] = 1;
    float middleClassUpperBound = upperClassUpperBound + table.getValue(coord);
    randomProbability = (float) Math.random();
    if (randomProbability <= upperClassUpperBound) {
      person.setHasEconomicStanding(EconomicStanding.UpperClass);
    } else if (randomProbability <= middleClassUpperBound) {
      person.setHasEconomicStanding(EconomicStanding.MiddleClass);
    } else {
      person.setHasEconomicStanding(EconomicStanding.LowerClass);
    }
   
    // Define the person education level (MiddleSchool, HighSchool, College,
    // BA_BS, MA_MS, or PhD)
    child = (ProbabilisticNode) pn.getNode("hasEducationLevel_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
    coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
    coord[0] = 0;
    float middleSchoolUpperBound = table.getValue(coord);
    coord[0] = 1;
    float highSchoolUpperBound = middleSchoolUpperBound + table.getValue(coord);
    coord[0] = 2;
    float collegeUpperBound = highSchoolUpperBound + table.getValue(coord);
    coord[0] = 3;
    float baBsUpperBound = collegeUpperBound + table.getValue(coord);
    coord[0] = 4;
    float maMsUpperBound = baBsUpperBound + table.getValue(coord);
    randomProbability = (float) Math.random();
    if (randomProbability <= middleSchoolUpperBound) {
      person.setHasEducationLevel(EducationLevel.MiddleSchool);
    } else if (randomProbability <= highSchoolUpperBound) {
      person.setHasEducationLevel(EducationLevel.HighSchool);
    } else if (randomProbability <= collegeUpperBound) {
      person.setHasEducationLevel(EducationLevel.College);
    } else if (randomProbability <= baBsUpperBound) {
      person.setHasEducationLevel(EducationLevel.BA_BS);
    } else if (randomProbability <= maMsUpperBound) {
      person.setHasEducationLevel(EducationLevel.MA_MS);
    } else {
      person.setHasEducationLevel(EducationLevel.PhD);
    }
   
    // Define the person occupation (Professional, SemiSkilled, or UnSkilled)
    child = (ProbabilisticNode) pn.getNode("hasOccupation_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    parent = (ProbabilisticNode) pn.getNode("hasClusterPartition_person");
    coord[table.getVariableIndex(parent)] = hasClusterPartitionState;
    coord[0] = 0;
    float professionalUpperBound = table.getValue(coord);
    coord[0] = 1;
    float semiSkilledUpperBound = professionalUpperBound + table.getValue(coord);
    randomProbability = (float) Math.random();
    if (randomProbability <= professionalUpperBound) {
      person.setHasOccupation(Occupation.Professional);
    } else if (randomProbability <= semiSkilledUpperBound) {
      person.setHasOccupation(Occupation.SemiSkilled);
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

    // Define if person has influence partition
    int hasInfluencePartitionState = 0;
    ProbabilisticNode child = (ProbabilisticNode) pn
        .getNode("hasInfluencePartition_person");
    PotentialTable table = ((PotentialTable) child.getProbabilityFunction());
    int[] coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    ProbabilisticNode parent = (ProbabilisticNode) pn
        .getNode("isTerrorist_person");
    coord[table.getVariableIndex(parent)] = isTerroristState;
    if (Math.random() <= table.getValue(coord)) {
      hasInfluencePartitionState = 0;
      person.setHasInfluencePartition(true);
    } else {
      hasInfluencePartitionState = 1;
      person.setHasInfluencePartition(false);
    }
   
    // Define the person family status
    child = (ProbabilisticNode) pn
        .getNode("hasFamilyStatus_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    parent = (ProbabilisticNode) pn
        .getNode("hasInfluencePartition_person");
    coord[table.getVariableIndex(parent)] = hasInfluencePartitionState;
    if (Math.random() <= table.getValue(coord)) {
      person.setHasFamilyStatus(FamilyStatus.Married);
    } else {
      person.setHasFamilyStatus(FamilyStatus.Single);
    }
   
    // Define if person has OIF or OEF influence
    int hasOIForOEFInfluenceState = 0;
    child = (ProbabilisticNode) pn
        .getNode("hasOIForOEFInfluence_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    parent = (ProbabilisticNode) pn
        .getNode("hasInfluencePartition_person");
    coord[table.getVariableIndex(parent)] = hasInfluencePartitionState;
    if (Math.random() <= table.getValue(coord)) {
      hasOIForOEFInfluenceState = 0;
      person.setHasOIForOEFInfluence(true);
    } else {
      hasOIForOEFInfluenceState = 1;
      person.setHasOIForOEFInfluence(false);
    }

    // Define if person someone kileld in OIF or OEF (none, few, or many)
    child = (ProbabilisticNode) pn.getNode("knowsPersonKilledInOIForOEF_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    parent = (ProbabilisticNode) pn.getNode("hasOIForOEFInfluence_person");
    coord[table.getVariableIndex(parent)] = hasOIForOEFInfluenceState;
    float noneUpperBound = table.getValue(coord);
    coord[0] = 1;
    float fewUpperBound = noneUpperBound + table.getValue(coord);
    float randomProbability = (float) Math.random();
    if (randomProbability <= noneUpperBound) {
      person.setKnowsPersonKilledinOIForOEF(Quantity.None);
    } else if (randomProbability <= fewUpperBound) {
      person.setKnowsPersonKilledinOIForOEF(Quantity.Few);
    } else {
      person.setKnowsPersonKilledinOIForOEF(Quantity.Many);
    }

    // Define if person someone imprisioned in OIF or OEF (none, few, or many)
    child = (ProbabilisticNode) pn.getNode("knowsPersonImprisionedInOIForOEF_person");
    table = ((PotentialTable) child.getProbabilityFunction());
    coord = new int[child.getParents().size() + 1];
    coord[0] = 0;
    parent = (ProbabilisticNode) pn.getNode("hasOIForOEFInfluence_person");
    coord[table.getVariableIndex(parent)] = hasOIForOEFInfluenceState;
    noneUpperBound = table.getValue(coord);
    coord[0] = 1;
    fewUpperBound = noneUpperBound + table.getValue(coord);
    randomProbability = (float) Math.random();
    if (randomProbability <= noneUpperBound) {
      person.setKnowsPersonImprisionedInOIForOEF(Quantity.None);
    } else if (randomProbability <= fewUpperBound) {
      person.setKnowsPersonImprisionedInOIForOEF(Quantity.Few);
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

      // Simulate organization data
      for (OrganizationEntity org : db.getOrganizations()) {
        ProbabilisticNode child = (ProbabilisticNode) pn
            .getNode("isTerroristOrganization_org");
        PotentialTable table = ((PotentialTable) child
            .getProbabilityFunction());
        int[] coord = new int[child.getParents().size() + 1];
        coord[0] = 0;
        ProbabilisticNode parent = (ProbabilisticNode) pn
            .getNode("isTerrorist_person");
        // True if at least one member is a terrorist
        coord[table.getVariableIndex(parent)] = (org.isRelatedToTerrorist()) ? 0
            : 1;
        parent = (ProbabilisticNode) pn
            .getNode("isMemberOfOrganization_person_org");
        // Always true, since we are dealing with members of the organization
        coord[table.getVariableIndex(parent)] = 0;
        if (Math.random() <= table.getValue(coord)) {
          org.setTerroristOrganisation(true);
        } else
          org.setTerroristOrganisation(false);
      }
    }
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

  public void createStates(EDBUnit SNodes, Node UNode){
    EDBUnit SNode = SNodes.get( UNode.getName() );
   
     if( UNode instanceof ProbabilisticNode){
       ProbabilisticNode aux = (ProbabilisticNode) UNode;
      PotentialTable auxTab = aux.getProbabilityFunction();
     
      for( int i = 0; i < UNode.getStatesSize(); i++ ){     
        Float fStateVaule = auxTab.getValue(i);  
        createSTATE(SNode, UNode.getStateAt(i), fStateVaule.toString());
      }
    }
  }
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

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

Examples of unbbayes.prs.bn.PotentialTable

    //create new state of current SNode 
    EDBUnit newLast = lastCPT.createNext(nextNode.getName());  

    //add state value from Unode
    ProbabilisticNode aux = (ProbabilisticNode) UNode;
    PotentialTable auxTab = aux.getProbabilityFunction();  
    coord[0] = getStateIndexFromBN(UNode, newLast.getName());
    
    Float fStateVaule = auxTab.getValue(coord);
    newLast.setData(fStateVaule.toString());
   
    return CreateNextState(lastCPT, nextNode.getNext(), UNode, coord);
  }
View Full Code Here

Examples of unbbayes.prs.bn.PotentialTable

    node.setPosition(x, y);
    node.appendState(resource.getString("firstStateProbabilisticName"));
    node.setName(resource.getString("probabilisticNodeName")
        + singleEntityNetwork.getNodeCount());
    node.setDescription(node.getName());
    PotentialTable auxTabProb = (PotentialTable)(node)
        .getProbabilityFunction();
    auxTabProb.addVariable(node);
    auxTabProb.setValue(0, 1);
    singleEntityNetwork.addNode(node);
   
    return node;
  }
View Full Code Here

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;

    /* 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();

      table = new GUIPotentialTable(potTab).makeTable();

    } 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;

      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.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      table.setTableHeader(null);

    }
    // TODO MIGRATE TO A DIFFERENT CLASS - GUI.TABLE.PROBABILISTICTABLEMODEL
    table.getModel().addTableModelListener(new TableModelListener() {
      public void tableChanged(TableModelEvent e) {
        // Change state name or reset to its previous value.
        if (e.getColumn() == 0) {
          if (!table.getValueAt(e.getLastRow(), e.getColumn()).toString().trim().equals("")) {
            node.setStateAt(table.getValueAt(e.getLastRow(),
                e.getColumn()).toString(), e.getLastRow()
                - (table.getRowCount() - node.getStatesSize()));
          } else {
            table.revalidate();
            table.setValueAt(node.getStateAt(e.getLastRow()
                - (table.getRowCount() - node.getStatesSize())), e.getLastRow(),
                e.getColumn());
          }
        // Change the CPT cell or reset to its previous value.
        } else if (potTab != null) {
          String valueText = table.getValueAt(e.getLastRow(),
              e.getColumn()).toString().replace(',', '.');
          try {
            float value = Float.parseFloat(valueText);
            potTab.setValue((e.getColumn() - 1) * node.getStatesSize() + e.getLastRow(), value);
          } catch (NumberFormatException nfe) {
            // Just shows the error message if the value is not empty.
            if (!valueText.trim().equals("")) {
              JOptionPane.showMessageDialog(null,
                  resource.getString("numberFormatError"),
                  resource.getString("error"),
                  JOptionPane.ERROR_MESSAGE);
            }
            table.revalidate();
            table.setValueAt(""
                + potTab.getValue((e.getColumn() - 1) * node.getStatesSize() + e.getLastRow()),
                e.getLastRow(), e.getColumn());
          }
        }
      }
    });
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.