Package unbbayes.prs.mebn

Examples of unbbayes.prs.mebn.MultiEntityBayesianNetwork


       
        // load ubf/owl
       
        File mebnFile = new File("resources/mebn/prognos.ubf");
        UbfIO ubf = UbfIO.getInstance();
        MultiEntityBayesianNetwork mebn = ubf.loadMebn(mebnFile);
 
       
        // initialize kb
       
        KnowledgeBase knowledgeBase = PowerLoomKB.getNewInstanceKB();
        knowledgeBase = textModeRunner.createKnowledgeBase(knowledgeBase, mebn);
       
        // load kb
       
  //      File kbFile = new File(getClass().getResource("/mebn/prognos.plm").getFile());
  //      knowledgeBase.loadModule(kbFile, true);
       
        MebnUtil mebnUtil = new MebnUtil(mebn);
       
        mebnUtil.removeAllEntityInstances();
       
        ObjectEntity entity = mebn.getObjectEntityContainer().getObjectEntityByName("Ship");
        mebnUtil.createEntityIntance(entity, "ship1");
        mebnUtil.createEntityIntance(entity, "ship2");
        mebnUtil.createEntityIntance(entity, "ship3");
       
        entity = mebn.getObjectEntityContainer().getObjectEntityByName("Person");
        mebnUtil.createEntityIntance(entity, "person1");
       
        entity = mebn.getObjectEntityContainer().getObjectEntityByName("Organization");
        mebnUtil.createEntityIntance(entity, "org1");
       
        ResidentNode residentNode = mebn.getDomainResidentNode("IsWithinRadarRange");
        ObjectEntityInstance[] arguments = new ObjectEntityInstance[2];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship1");
        arguments[1] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship2");
        Entity state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("UnusualRoute");
        arguments = new ObjectEntityInstance[1];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship1");
        state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("AreMeeting");
        arguments = new ObjectEntityInstance[2];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship1");
        arguments[1] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship3");
        state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("IsMemberOfOrganization");
        arguments = new ObjectEntityInstance[2];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("person1");
        arguments[1] = mebn.getObjectEntityContainer().getEntityInstanceByName("org1");
        state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("IsTerroristOrganization");
        arguments = new ObjectEntityInstance[1];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("org1");
        state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("ResponsiveAIS");
        arguments = new ObjectEntityInstance[1];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship1");
        state = mebn.getBooleanStatesEntityContainer().getFalseStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("ResponsiveRadar");
        arguments = new ObjectEntityInstance[1];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship1");
        state = mebn.getBooleanStatesEntityContainer().getFalseStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("IsCrewMember");
        arguments = new ObjectEntityInstance[2];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("person1");
        arguments[1] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship1");
        state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        residentNode = mebn.getDomainResidentNode("DetectedECM");
        arguments = new ObjectEntityInstance[1];
        arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName("ship2");
        state = mebn.getBooleanStatesEntityContainer().getFalseStateEntity();
        mebnUtil.createRandomVariableFinding(residentNode, arguments, state);
       
        knowledgeBase = textModeRunner.fillFindings(mebn,knowledgeBase);
     
        new PrognosFrame("PROGNOS", mebn);
View Full Code Here


    SSBN ssbn = new SSBN();
    if (!isLogEnabled()) {
      ssbn.setLogManager(null);
    }
   
    MultiEntityBayesianNetwork mebn = null;

    //log
    ISSBNLogManager logManager = ssbn.getLogManager();
    if (logManager != null) {
      logManager.printBox1Bar();
      logManager.printBox1(getResourceForHybridAlgorithm().getString("001_Title"));
      logManager.printBox1("Queries:");
      for(int i = 0; i < queryList.size(); i++){
        logManager.printBox1("    (" + i + ") " + queryList.get(i).toString());
      }
      logManager.printBox1(getResourceForHybridAlgorithm().getString("002_Algorithm") + ": " +
          getResourceForHybridAlgorithm().getString("002_001_LaskeyAlgorithm"));
      logManager.printBox1Bar();
     
      logManager.skipLine();
      logManager.printText(null, false, getResourceForHybridAlgorithm().getString("003_Step1_Initialization"));
      logManager.skipLine();
    }
   
    ssbn.setKnowledgeBase(knowledgeBase);
   
    //We assume that all the queries is referent to the same MEBN
    mebn = queryList.get(0).getMebn();
   
    //Parameters:

    IdentationLevel in = new IdentationLevel(null);
   
    //Add queries to the list of nodes
    IdentationLevel in1 = new IdentationLevel(in);
    if (logManager != null) {
      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;
View Full Code Here

      e.printStackTrace();
    }
    assertNotNull(ubfFileToLoad);
   
    // load mebn
    MultiEntityBayesianNetwork mebn = null;
    try {
      // load file
      mebn = (MultiEntityBayesianNetwork) io.load(ubfFileToLoad);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    assertNotNull(mebn);
   
    // file containing KB
    File plmFileToLoad = null;
    try {
      plmFileToLoad = new File(this.getClass().getClassLoader().getResource("mebn/SimpleContinuousNodeSample.plm").toURI());
    } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    assertNotNull(plmFileToLoad);
   
    // object to facilitate KB manipulation and query (but we are not going to use query)
    TextModeRunner textModeRunner = new TextModeRunner();
   
    // instantiate and setup knowledge base
    KnowledgeBase kb = textModeRunner.createKnowledgeBase(PowerLoomKB.getNewInstanceKB(), mebn);
   
    // load finding data from file and insert to KB
    try {
      // load findings from file
      kb.loadModule(plmFileToLoad, true);
      // fill mebn with findings
      textModeRunner.fillFindings(mebn, kb);
    } catch (UBIOException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
   
    // file to save KB (in the same folder of the loaded file)
    File newPLMFile = new File(plmFileToLoad.getParent(), "SavedContinuousNodeSample.plm");
   
    // save KB to new file
    textModeRunner.saveKnowledgeBase(newPLMFile, kb, mebn);
   
    // file to save MEBN (in the same folder of the loaded file)
    File newUBFFile = new File(ubfFileToLoad.getParent(), "SavedContinuousNodeSample.ubf");
   
    // save mebn to new file
    try {
      textModeRunner.saveMEBN(newUBFFile, io, mebn);
    } catch (IOException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
   
   
    // load new file (so that we can compare)
    MultiEntityBayesianNetwork mebnOfNewFile = null;
    try {
      mebnOfNewFile = (MultiEntityBayesianNetwork) io.load(newUBFFile);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    assertNotNull(mebnOfNewFile);
   
    // fill new mebn with the findings in kb
    textModeRunner.fillFindings(mebnOfNewFile, kb);
   
    // start comparing 2 mebn
    assertEquals(mebn.getName(), mebnOfNewFile.getName());
    assertEquals(mebn.getMFragCount(), mebnOfNewFile.getMFragCount());
    for (MFrag mFrag : mebn.getMFragList()) {
      // compare presence of mfrags
      MFrag mFragOfNewMEBN = mebnOfNewFile.getMFragByName(mFrag.getName());
      assertNotNull(mFrag.getName()+ " is not present.", mFragOfNewMEBN);
     
      // compare total quantity of nodes
      assertEquals(mFrag.getNodeCount(), mFragOfNewMEBN.getNodeCount());
     
View Full Code Here

TOP

Related Classes of unbbayes.prs.mebn.MultiEntityBayesianNetwork

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.