Package unbbayes.prs.mebn

Examples of unbbayes.prs.mebn.ResidentNode


    protected void loadDomainMFrag() throws IOMebnException {

      MFrag domainMFrag;
      OrdinaryVariable oVariable;
      ContextNode contextNode;
      ResidentNode domainResidentNode;
      InputNode generativeInputNode;
      BuiltInRV builtInRV;

      RDFIndividual individualOne;
      RDFIndividual individualTwo;
      OWLNamedClass owlNamedClass;
      OWLObjectProperty objectProperty;

      owlNamedClass = getOwlModel().getOWLNamedClass(DOMAIN_MFRAG);
      Collection instances = owlNamedClass.getInstances(false);

      for (Iterator it = instances.iterator(); it.hasNext();) {
        individualOne = (RDFIndividual) it.next();
        domainMFrag = getMapDomainMFrag().get(individualOne.getBrowserText());
        if (domainMFrag == null) {
          throw new IOMebnException(
              getResource().getString("DomainMFragNotExistsInMTheory"),
              individualOne.getBrowserText());
        }

        Debug.println("DomainMFrag loaded: "
            + individualOne.getBrowserText());

        domainMFrag.setDescription(getDescription(individualOne));

        /* -> hasResidentNode */
        objectProperty = (OWLObjectProperty) getOwlModel()
            .getOWLObjectProperty("hasResidentNode");
        instances = individualOne.getPropertyValues(objectProperty);
        for (Iterator itIn = instances.iterator(); itIn.hasNext();) {
          Object itInNext = itIn.next();
          if (!(itInNext instanceof RDFIndividual)) {
            try {
              System.err.println(itInNext + " != RDFIndividual");
            } catch (Throwable t) {
              t.printStackTrace();
            }
            continue;
          }
          individualTwo = (RDFIndividual) itInNext;

          // remove prefixes from the name
          String name = individualTwo.getBrowserText();
          if (name.startsWith(SaverPrOwlIO.RESIDENT_NAME_PREFIX)) {
            try {
              name = name.substring(SaverPrOwlIO.RESIDENT_NAME_PREFIX
                  .length());
            } catch (Exception e) {
              // ignore, because we can still try the original name
              e.printStackTrace();
            }
          }

          // instanciate a continuous resident node instead of resident node, if individual is assignable to a continuous node
          if (individualTwo.hasRDFType(getOwlModel().getOWLNamedClass(CONTINUOUS_RESIDENT_NODE), true)) {
            domainResidentNode = new ContinuousResidentNode(name, domainMFrag);
//            try {
//              ((ContinuousResidentNode)domainResidentNode).onAddToMFrag(domainMFrag);
//            } catch (MFragDoesNotExistException e) {
//              e.printStackTrace();
//            }
          } else {
            domainResidentNode = new ResidentNode(name, domainMFrag);
          }
          getMebn().getNamesUsed().add(name);

          domainMFrag.addResidentNode(domainResidentNode);

View Full Code Here


          /* hasResidentNode */
          OWLObjectProperty hasResidentNodeProperty = (OWLObjectProperty)getOwlModel().getOWLObjectProperty("hasResidentNode");  
         
          for(Node node: domainMFrag.getNodeList()){
            if (node instanceof ResidentNode) {
              ResidentNode residentNode = (ResidentNode) node;
             
              Debug.println("Domain_Res = " + residentNode.getName())
              // check if individual exists
              OWLIndividual domainResIndividual = getOwlModel().getOWLIndividual(this.RESIDENT_NAME_PREFIX + residentNode.getName());
              if (domainResIndividual == null) {
                // if new, create it
                OWLNamedClass domainResClass = null;
                if (residentNode instanceof ContinuousResidentNode) {
                  // get owl class for continuous nodes
                  domainResClass = getOwlModel().getOWLNamedClass(CONTINUOUS_RESIDENT_NODE);
                  if (domainResClass == null) {
                    // if CONTINUOUS_RESIDENT_NODE does not exist, create it
                    domainResClass = getOwlModel().createOWLNamedSubclass(CONTINUOUS_RESIDENT_NODE, getOwlModel().getOWLNamedClass(DOMAIN_RESIDENT));
                  }
                } else {
                  // get owl class for resident nodes
                  domainResClass = getOwlModel().getOWLNamedClass(DOMAIN_RESIDENT);
                }
               
                domainResIndividual = domainResClass.createOWLIndividual(this.RESIDENT_NAME_PREFIX + residentNode.getName());
              }
              domainMFragIndividual.addPropertyValue(hasResidentNodeProperty, domainResIndividual);  
              getMapDomainResident().put(residentNode, domainResIndividual);
            }
           
View Full Code Here

      }
    }
    Entity condvalue = null;
   
    // search for an entity with a name this.value
    ResidentNode possibleValueHolder = null;
    if (mebnNode instanceof InputNode) {
      possibleValueHolder = ((InputNode) mebnNode).getResidentNodePointer().getResidentNode();
    } else if (mebnNode instanceof ResidentNode) {
      possibleValueHolder = (ResidentNode)mebnNode;
    } else {
      throw new InvalidConditionantException(this.value + " must be either a resident node or an input node.");
    }
    for (Entity possibleValue : possibleValueHolder.getPossibleValueListIncludingEntityInstances()) {
      if (possibleValue.getName().equalsIgnoreCase(this.value)) {
        condvalue = possibleValue;
        break;
      }
    }
View Full Code Here

      // fill cps with something like "if( P1 == true && P2 == true )"
      String cpsIfClause = ""// content of if-clause. If there is no discrete parent, this content is empty
      // fill map at this loop. Note that parents.size, currentIteratorValue.size, and valueCombinationiterators are the same
      for (int j = 0; j < parents.size(); j++) {
        SSBNNode parent = parents.get(j);
        ResidentNode parentResident = parent.getResident();
        // ignore continuous parent
        if (!(parentResident instanceof ContinuousResidentNode)) {
          Entity val = currentIteratorValue.get(j);
          if (cpsIfClause.length() > 0) {
            // there are other boolean expressions. Combine using &&
            cpsIfClause += " && ";
          }
          cpsIfClause += parent.getProbNode().getName() + " == " + val.getName();
          map.get(parentResident.getName()).add(new EntityAndArguments(val,new ArrayList<OVInstance>(parent.getArguments())));
        }
      }
      if (cpsIfClause.length() > 0) {
        // only start if-clause if there are discrete parents
        if (!isItTheFisrtIf) {
View Full Code Here

      List<EvidenceInfo> evidenceList = queryJob.getEvidenceList();
     
      loadEvidence(evidenceList);
      Debug.println(getClass(), "Evidences loaded");
     
      ResidentNode queryNode = mebn.getDomainResidentNode("isShipOfInterest");
     
      // Create query object
      List<Query> queryList = new ArrayList<Query>();
      for (Integer shipID : queryJob.getShipIDs()) {
        // Set up query
        List<OVInstance> ovInstanceList = new ArrayList<OVInstance>(1);
        List<Argument> arglist = queryNode.getArgumentList();
        OrdinaryVariable ov = arglist.get(0).getOVariable();
        OVInstance ovInstance = OVInstance.getInstance(ov,
            LiteralEntityInstance.getInstance("ship" + shipID, ov.getValueType()));
        ovInstanceList.add(ovInstance);
       
View Full Code Here

    }
    return Collections.singletonList(result);
  }

  private void loadEvidence(List<EvidenceInfo> evidenceList) throws Exception {
    ResidentNode residentNode;
    ObjectEntity entity;
    ObjectEntityInstance[] arguments;
    Entity state;
    CategoricalStateEntity categoricalState;
   
View Full Code Here

      }
    }
   
    for(InputNode input : residentNode.getParentInputNodesList()){
      if(input.getInputInstanceOf() instanceof IResidentNode){
        ResidentNode resident = (ResidentNode)input.getInputInstanceOf();
       
        if(resident != null){
          fatherList.add(resident.getName());
         
          for(StateLink state: resident.getPossibleValueLinkList()){
            statesFatherList.add(state.getState().getName());
          }
        }
       
      }else{
View Full Code Here

   */
  public final void testQueryResidentNode() {
    ProbabilisticNetwork net = null;
    try {
     
      ResidentNode continuousResidentNode = mebn.getDomainResidentNode("MTI");
      ObjectEntityInstance[] arguments = new ObjectEntityInstance[2];
      arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("Rpt1");
      arguments[1] = mebn.getObjectEntityContainer().getEntityInstanceByName("T0");
      createRandomVariableFinding((ContinuousResidentNode)continuousResidentNode, arguments, 0f);
     
View Full Code Here

    catch (IOException e){     
      e.printStackTrace();
      fail("ERROR IO!!!!!!!!!");
    }
   
    ResidentNode residentSpeed = (ResidentNode)mebn.getNode("Speed");
    assertNotNull(residentSpeed);
   
    // set up instances of object entities
    // we need only one object
    mebn.getObjectEntityContainer().addEntityInstance(new ObjectEntityInstance("OBJ1", mebn.getObjectEntityContainer().getObjectEntityByName("Object")));

    // add three regions
    mebn.getObjectEntityContainer().addEntityInstance(new ObjectEntityInstance("RGN1", mebn.getObjectEntityContainer().getObjectEntityByName("Region")));
    mebn.getObjectEntityContainer().addEntityInstance(new ObjectEntityInstance("RGN2", mebn.getObjectEntityContainer().getObjectEntityByName("Region")));
    mebn.getObjectEntityContainer().addEntityInstance(new ObjectEntityInstance("RGN3", mebn.getObjectEntityContainer().getObjectEntityByName("Region")));
   
    // add three timesteps
//    mebn.getObjectEntityContainer().addEntityInstance(new ObjectEntityInstance("T0", mebn.getObjectEntityContainer().getObjectEntityByName("TimeStep")));
//    mebn.getObjectEntityContainer().addEntityInstance(new ObjectEntityInstance("T1", mebn.getObjectEntityContainer().getObjectEntityByName("TimeStep")));
    mebn.getObjectEntityContainer().addEntityInstance(new ObjectEntityInstance("T2", mebn.getObjectEntityContainer().getObjectEntityByName("TimeStep")));
   
   
    probabilisticNetwork = new ProbabilisticNetwork(mebn.getName());
    SSBN ssbn = new SSBN();
    ssbn.setNetwork(probabilisticNetwork);
   
    speedOBJ1T2 = new ProbabilisticNode();
    speedOBJ1T2.setName(residentSpeed.getName() + "_OBJ1_T2");
    probabilisticNetwork.addNode(speedOBJ1T2);
    SSBNNode ssbnNodeSpeedOBJ1T2 = SSBNNode.getInstance(probabilisticNetwork, residentSpeed, speedOBJ1T2);
    ssbn.getSsbnNodeList().add(ssbnNodeSpeedOBJ1T2);
    ssbnNodeSpeedOBJ1T2.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("obj"), "OBJ1");
    ssbnNodeSpeedOBJ1T2.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("t"), "T2");
   
    // Speed(OBJ1, T0),
//    ProbabilisticNode speedOBJ1T0 = new ProbabilisticNode();
//    speedOBJ1T0.setName(residentSpeed.getName() + "_OBJ1_T0");
//    probabilisticNetwork.addNode(speedOBJ1T0);
//    SSBNNode ssbnNodeSpeedOBJ1T0 = SSBNNode.getInstance(probabilisticNetwork, residentSpeed, speedOBJ1T0);
//    ssbn.getSsbnNodeList().add(ssbnNodeSpeedOBJ1T0);
//    ssbnNodeSpeedOBJ1T0.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("obj"), "OBJ1");
//    ssbnNodeSpeedOBJ1T0.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("tPrev"), "T0");
//    ssbnNodeSpeedOBJ1T2.addParent(ssbnNodeSpeedOBJ1T0, false);  // this should also add the edge
   
    // Speed(OBJ1, T1),
    ProbabilisticNode speedOBJ1T1 = new ProbabilisticNode();
    speedOBJ1T1.setName(residentSpeed.getName() + "_OBJ1_T1");
    probabilisticNetwork.addNode(speedOBJ1T1);
    SSBNNode ssbnNodeSpeedOBJ1T1 = SSBNNode.getInstance(probabilisticNetwork, residentSpeed, speedOBJ1T1);
    ssbn.getSsbnNodeList().add(ssbnNodeSpeedOBJ1T1);
    ssbnNodeSpeedOBJ1T1.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("obj"), "OBJ1");
    ssbnNodeSpeedOBJ1T1.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("tPrev"), "T1");
    ssbnNodeSpeedOBJ1T2.addParent(ssbnNodeSpeedOBJ1T1, false)// this should also add the edge
   
    // TerrainType(RGN1),
    ResidentNode terrainTypeResident = mebn.getDomainResidentNode("TerrainType");
    ProbabilisticNode terrainTypeRGN1 = new ProbabilisticNode();
    terrainTypeRGN1.setName(terrainTypeResident.getName() + "_RGN1");
    probabilisticNetwork.addNode(terrainTypeRGN1);
    SSBNNode ssbnNodeTerrainTypeRGN1 = SSBNNode.getInstance(probabilisticNetwork, terrainTypeResident, terrainTypeRGN1);
    ssbn.getSsbnNodeList().add(ssbnNodeTerrainTypeRGN1);
    ssbnNodeTerrainTypeRGN1.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("rgn"), "RGN1");
    ssbnNodeSpeedOBJ1T2.addParent(ssbnNodeTerrainTypeRGN1,false)// this should also add the edge
   
    // TerrainType(RGN2),
    ProbabilisticNode terrainTypeRGN2 = new ProbabilisticNode();
    terrainTypeRGN2.setName(terrainTypeResident.getName() + "_RGN2");
    probabilisticNetwork.addNode(terrainTypeRGN2);
    SSBNNode ssbnNodeTerrainTypeRGN2 = SSBNNode.getInstance(probabilisticNetwork, terrainTypeResident, terrainTypeRGN2);
    ssbn.getSsbnNodeList().add(ssbnNodeTerrainTypeRGN2);
    ssbnNodeTerrainTypeRGN2.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("rgn"), "RGN2");
    ssbnNodeSpeedOBJ1T2.addParent(ssbnNodeTerrainTypeRGN2,false)// this should also add the edge
   
    // TerrainType(RGN3),
//    ProbabilisticNode terrainTypeRGN3 = new ProbabilisticNode();
//    terrainTypeRGN3.setName(terrainTypeResident.getName() + "_RGN3");
//    probabilisticNetwork.addNode(terrainTypeRGN3);
//    SSBNNode ssbnNodeTerrainTypeRGN3 = SSBNNode.getInstance(probabilisticNetwork, terrainTypeResident, terrainTypeRGN3);
//    ssbn.getSsbnNodeList().add(ssbnNodeTerrainTypeRGN3);
//    ssbnNodeTerrainTypeRGN3.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("rgn"), "RGN3");
//    ssbnNodeSpeedOBJ1T2.addParent(ssbnNodeTerrainTypeRGN3,false);  // this should also add the edge
   
    // ObjectType(OBJ1)
    ResidentNode objectTypeResident = mebn.getDomainResidentNode("ObjectType");
    ProbabilisticNode objectTypeOBJ1 = new ProbabilisticNode();
    objectTypeOBJ1.setName(objectTypeResident.getName() + "_OBJ1");
    probabilisticNetwork.addNode(objectTypeOBJ1);
    SSBNNode ssbnNodeObjectTypeOBJ1 = SSBNNode.getInstance(probabilisticNetwork, objectTypeResident, objectTypeOBJ1);
    ssbn.getSsbnNodeList().add(ssbnNodeObjectTypeOBJ1);
    ssbnNodeObjectTypeOBJ1.addArgument(residentSpeed.getMFrag().getOrdinaryVariableByName("obj"), "OBJ1");
    ssbnNodeSpeedOBJ1T2.addParent(ssbnNodeObjectTypeOBJ1,false)// this should also add the edge
View Full Code Here

TOP

Related Classes of unbbayes.prs.mebn.ResidentNode

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.