Package unbbayes.prs.mebn.ssbn

Examples of unbbayes.prs.mebn.ssbn.SimpleSSBNNode


        //Special case: the recursivity.
        if (logManager != null) {
          logManager.printText(level4, false, " Recursivity treatment: " + resident);
        }
       
        SimpleSSBNNode newNode = createRecursiveParents(node, ovFilledArray,
            entityFilledArray, inputNodeParent);
       
        if(newNode != null){
          evaluateNodeInMFragInstance(mFragInstance, newNode);
        }
View Full Code Here


     *                                   
     *  Then childOfChain is going to store the last child in the chain.
     *  We store the last child, because the child is always created before the parents in the chain
     *  (in the above example, E is created before X, which is created before Y)
     */
    SimpleSSBNNode childOfChain = node; 
   
    //Create the new node... We pass by each combination for the ov fault list.
    //Note that if we don't have any ov fault, we should have one stub element
    //in the possibleCombinationsForOvFaultList for pass for this loop one time.
    Iterator<String[]> iterator = possibleCombinationsForOvFaultList.iterator();
    while (iterator.hasNext()) { 
      // using iterator instead of for(T obj : iterable), because there is a place where we need to call iterator.hasNext() inside the loop
      String[] possibleCombination = iterator.next();
     
//      Debug.println("Combination=" + possibleCombination);
     
      SimpleSSBNNode newNode = SimpleSSBNNode.getInstance(
          nodeParent.getResidentNode());
     
      //1. Add the ovInstances of the children that the father also have
      for(int i = 0; i < node.getOvArray().length; i++){
       
        //For a input node IX1 that references the resident node RX1, we
        //should recover the ordinary variable of the RX1's HomeMFrag that
        //correspond to the OV of the IX1's MFrag and then set it to the
        //SSBNNode.
        OrdinaryVariable correspondentOV =
          nodeParent.getCorrespondentOrdinaryVariable(node.getOvArray()[i]);
       
        if(correspondentOV != null){
          newNode.setEntityForOv(
              correspondentOV,
              node.getEntityArray()[i]);
        }
      }
     
      //2. Create the new OVInstances for the combination
      for(int index = 0; index < ovFaultForNewNodeList.size(); index++){
       
        OrdinaryVariable correspondentOV =
          nodeParent.getCorrespondentOrdinaryVariable(ovFaultForNewNodeList.get(index));
       
        newNode.setEntityForOv(
            correspondentOV,
            LiteralEntityInstance.getInstance(possibleCombination[index],
                ovFaultForNewNodeList.get(index).getValueType()));
      }
     
View Full Code Here

   * @return : node X in the above example if childOfChain is the node E of above example. If childOfChain
   * is the node X, then this method returns the node Y of the example.
   * @throws SSBNNodeGeneralException : when the quantity of nodes created by this object exceeds {@link #maxNumberNodes}
   */
  protected SimpleSSBNNode createNodeInAChain(SimpleSSBNNode childOfChain, SimpleSSBNNode newParent) throws SSBNNodeGeneralException {
    SimpleSSBNNode newNode = SimpleSSBNNode.getInstance(childOfChain.getResidentNode());
   
    // add one level to the childOfChain (if childOfChain was not a "virtual" node in a chain, it is going to set to 1).
    newNode.setStepsForChainNodeToReachMainNode(childOfChain.getStepsForChainNodeToReachMainNode() + 1);
   
    // copy some default values from original node
    newNode.setMFragInstance(childOfChain.getMFragInstance());
    newNode.setEvaluatedForHomeMFrag(childOfChain.isEvaluatedForHomeMFrag());
    newNode.setDefaultDistribution(childOfChain.isDefaultDistribution());
   
    // mark it as finished, so that it is not re-evaluated
    // (we do not want chain nodes to have parents other than the ones inherent from the main node)
    newNode.setFinished(true);
   
    // fill OVs with instances
   
    for(int i = 0; i < childOfChain.getOvArray().length; i++){
      // supposedly, new node contains the same OVs of  childOfChain
      if ( (childOfChain.getOvArray()[i] != null) && (childOfChain.getEntityArray().length > i) ) {
        newNode.setEntityForOv(childOfChain.getOvArray()[i], childOfChain.getEntityArray()[i]);
      } else {
        Debug.println(getClass(), "Could not extract OV and its instances of node " + childOfChain + " for index " + i);
      }
    }
   
View Full Code Here

       * Consideramos que o nó pai e o nó filho possuem os mesmos argumentos com
       * excessão do argumento recursivo. Isto mantém a compatibilidade com as
       * considerações feitas no algoritmo anterior. 
       */

      SimpleSSBNNode newNode = SimpleSSBNNode.getInstance(residentNode);
      for(int i = 0; i < node.getOvArray().length; i++){
        if(node.getOvArray()[i].equals(ovOrdereable)){
          newNode.setEntityForOv(node.getOvArray()[i], ovOrdereablePreviusValue);
        }else{
          newNode.setEntityForOv(node.getOvArray()[i], node.getEntityArray()[i]);
        }
      }

      if(numberNodes > maxNumberNodes){
        //TODO define exception
View Full Code Here

   * @return       the new node
   */
  private SimpleSSBNNode addNodeToMFragInstance(SimpleSSBNNode child,
      SimpleSSBNNode parent) {
   
    SimpleSSBNNode testNode = parent;
   
    parent = ssbn.addSSBNNodeIfItDontAdded(testNode);
   
    if(parent == testNode){
      numberNodes++;
View Full Code Here

  public void buildLocalDistribution(SSBN ssbn) throws MEBNException,
      SSBNNodeGeneralException {

   
    ProbabilisticNetwork pn;
    SimpleSSBNNode nodeOfQuery;
   
   
    ISSBNLogManager logManager = ssbn.getLogManager();
    try {
      // we do not need to create multiple networks anymore, because disconnected networks are behaving as separate BNs in the new core.
View Full Code Here

      logManager.printText(in1, true,
        getResourceForHybridAlgorithm().getString("011_BuildingSSBNForQueries"));
    }
   
    for(Query query: queryList){
      SimpleSSBNNode ssbnNode = SimpleSSBNNode.getInstance(query.getResidentNode());
      query.setSSBNNode(ssbnNode);
     
      for(OVInstance argument : query.getArguments()){
        ssbnNode.setEntityForOv(argument.getOv(), argument.getEntity());  
      }
     
      ssbnNode.setFinished(false);
      ssbn.addSSBNNodeIfItDontAdded(ssbnNode);
      ssbn.addQueryToTheQueryList(query);
     
      if (logManager != null) {
        logManager.printText(in1, false, " - " + ssbnNode);
      }
                                                                         
    }
   
    if (logManager != null) {
      logManager.skipLine();
    }
   
    //Add findings to the list of nodes
   
    in1 = new IdentationLevel(in);
    if (logManager != null) {
      logManager.printText(in1, true,
        getResourceForHybridAlgorithm().getString("012_BuildingSSBNForFindings"));
    }
   
    for(MFrag mFrag: mebn.getMFragList()){
      for(ResidentNode residentNode: mFrag.getResidentNodeList()){
        for(RandomVariableFinding finding: residentNode.getRandomVariableFindingList()){
         
          if (logManager != null) {
            logManager.printText(in1, false, " - " + finding);
          }
         
          ObjectEntityInstance arguments[] = finding.getArguments();
          List<OVInstance> ovInstanceList = new ArrayList<OVInstance>();
          for(int i = 0; i < arguments.length ; i++){
            OrdinaryVariable ov = residentNode.getArgumentNumber(i + 1).getOVariable();
            LiteralEntityInstance lei = LiteralEntityInstance.getInstance(arguments[i].getName() , ov.getValueType());
            ovInstanceList.add(OVInstance.getInstance(ov, lei));
          }
         
          SimpleSSBNNode ssbnNode = SimpleSSBNNode.getInstance(residentNode);
         
          for(OVInstance argument : ovInstanceList){
            ssbnNode.setEntityForOv(argument.getOv(), argument.getEntity());  
          }
          ssbnNode = ssbn.addSSBNNodeIfItDontAdded(ssbnNode);
         
          ssbnNode.setState(finding.getState());
          ssbnNode.setFinished(false);
         
          ssbn.addFindingToTheFindingList(ssbnNode);
        }
      }
    }
   
    if (logManager != null) {
      logManager.skipLine();
      logManager.printText(null, false, getResourceForHybridAlgorithm().getString("010_StepFinished"));
      logManager.skipLine();
      logManager.printSectionSeparation();
    }
   
    // add continuous nodes to the list of initial nodes
    if (isToAddAllContinuousNodes()) {
      for(MFrag mfrag: mebn.getMFragList()){
        // we are creating one continuous SSBN node per each possible combination of arguments in a continuous resident node
        for (Node node : mfrag.getNodes()) {
          if (node instanceof ContinuousResidentNode) {
           
            ContinuousResidentNode continuousResidentNode = (ContinuousResidentNode) node;
            if (continuousResidentNode.getOrdinaryVariableList() == null
                || continuousResidentNode.getOrdinaryVariableList().isEmpty()) {
              continue// go to next node
            }
           
            // prepare all possible combinations of arguments. The ovs are synchronized by index
            boolean hasAtLeastOneCombination = true// true if all Lists in combinator were filled
            List<List<LiteralEntityInstance>> combinator = new ArrayList<List<LiteralEntityInstance>>();
            for (OrdinaryVariable ov : continuousResidentNode.getOrdinaryVariableList()) {
              List<LiteralEntityInstance> contentOfCombinator = new ArrayList<LiteralEntityInstance>();
              // get all values for ov
              List<String> ovValues = knowledgeBase.getEntityByType(ov.getValueType().getName());
              if (ovValues.isEmpty()) {
                // this iterator cannot be filled, because ov has no possible values
                hasAtLeastOneCombination = false;
                break;
              }
              // add all possible values for ov
              for (String ovValue : ovValues) {
                contentOfCombinator.add(LiteralEntityInstance.getInstance(ovValue, ov.getValueType()));
              }
              combinator.add(contentOfCombinator);
            }
           
            // do not add node if there is some ov with no possible value (that means, no combination can be created)
            if (!hasAtLeastOneCombination) {
              continue// go to next continuous node
            }
           
            // list of indexes of combinator
            List<Integer> indexes = new ArrayList<Integer>(combinator.size());
            for (int i = 0; i < combinator.size(); i++) {
              // Note that at this point, each list in combinator has at least 1 element, because hasAtLeastOneCombination == true (so, 0 is a valid index)
              indexes.add(0);
            }
           
            /*
             * iterate on combinator using indexes.
             * E.g.:  combinator = {{a,b},{1,2}};
             *       then indexes must iterate like:
             *       {0,0}  (means (a,1));
             *       {1,0}  (means (b,1));
             *       {0,1}  (means (a,2));
             *       {1,1}  (means (b,2));
             *  
             */
            while (hasAtLeastOneCombination) {
             
              // create a continuous ssbn node for each possible combination of combinator
              SimpleSSBNNode ssbnNode = SimpleSSBNNode.getInstance(continuousResidentNode);
              ssbnNode.setFinished(false);
             
              // fill arguments of ssbnNode
              for (int i = 0; i < continuousResidentNode.getOrdinaryVariableList().size(); i++) {
                ssbnNode.setEntityForOv(
                    continuousResidentNode.getOrdinaryVariableList().get(i),
                    combinator.get(i).get(indexes.get(i))
                );
              }
             
View Full Code Here

TOP

Related Classes of unbbayes.prs.mebn.ssbn.SimpleSSBNNode

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.