Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Use MEBN decision making in other programs

Sethok
2011-07-26
2014-05-26
  • Sethok
    Sethok
    2011-07-26

    Hi,

    I have just started using Unbbayes and would like to know whether its possible
    to create a MEBN using Unbbayes and use the information provided by that to
    make decisions in other programs.

    More specific: I'm using USARsim to simulate the flight of an UAV. I want to
    use a few output parameters from Usarsim as Input for my MEBN and use the
    information gained by that to trigger a specific action in Usarsim (Output
    from Unbbayes to another program).

    So my questions:

    1. Do you understand what I'm trying to ask or should i elaborate further?
    2. Is that possible?
    3. If so, how (Tutorial?)

    Thanks in advance

    Malte

     
  • Hi Malte,

    Great application! If you need to model the decision itself in UnBBayes, then
    you should use the straight Bayes Net API for now. The MEBN plugin does not
    yet support influence diagrams (decision nodes). However, if you like the MEBN
    framework and you will make the decision yourself based on a probability
    calculation, then MEBN should work fine.

    I take it you will be using the API? I don't have enough experience yet to
    provide a detailed HOWTO, but someone else should answer relatively soon.

    -Charles

     
    1. Do you understand what I'm trying to ask or should i elaborate further?
    1. Is that possible?
    2. If so, how (Tutorial?)

    3. Yes, I understand.

    4. Yes, it is possible.

    5. Well, the way to do it is to use the API, as Charles has pointed out. Right now we do not have a specific tutorial on how to use MEBN API, however, you can check the "UnBBayes: a Java Framework for Probabilistic Models in AI" chapter from http://www.iconceptpress.com/site/bk_viewListOfPapers.php?publication_id=BK007A&page_title=. Section 3 talks about the API, but the examples available are only for BN and ID. Nevertheless, if you are familiar with Java programming, you should be able to check the PROGNOS source code. In this project we use UnBBayes MEBN API in order to use PROGNOS data as input to our MEBN model and then we use the result of MEBN reasoning with UnBBayes as output to feed the PROGNOS project.

    The edu.gmu.seor.prognos.simulation.integration.util.MebnUtil class provides a
    better facade to UnBBayes MEBN API. This class will probably become UnBBayes
    API Facade in the near future. You can always copy and paste the source code
    from PROGNOS project. This class was adapted mostly from controllers in
    UnBBayes MEBN code. We also make use of a class called TextModeRunner from
    UnBBayes MEBN, which has some examples also on how to use the MEBN API.

    Here goes an example on how to define a finding (input from PROGNOS project)
    in MEBN using the API. This piece of code and the next were taken from the
    edu.gmu.seor.prognos.simulation.integration.controller.PrognosController
    class.

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

    In this next example you can see how to get the posterior probabilities from
    UnBBayes API (output from UnBBayes).

        private String runQuery(ShipEntity ship) throws Exception {
    
            ResidentNode queryNode = mebn.getDomainResidentNode("isShipOfInterest");
    
            // 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" + ship.getID(), ov.getValueType()));
            ovInstanceList.add(ovInstance);
    
            // Create and run query
            Query query = new Query(queryNode, ovInstanceList);
            List<Query> queryList = new ArrayList<Query>();
            queryList.add(query);
            net = textModeRunner.executeQueryLaskeyAlgorithm(queryList,
                    knowledgeBase, mebn);
    
            // Show query result
            StringBuffer queryResult = new StringBuffer();
            for (Node node : net.getNodes()) {
                queryResult.append(node.getDescription() + "\n");
                for (int i = 0; i < node.getStatesSize(); i++) {
                    queryResult.append(node.getStateAt(i) + " = " + ((ProbabilisticNode)node).getMarginalAt(i));
                    if (i < node.getStatesSize() - 1) {
                        queryResult.append(", ");
                    }
                }
                queryResult.append("\n\n");
            }
            return queryResult.toString();
        }
    

    I hope this helps!

    Best,

    Rommel Carvalho

     
  • GiannisCh
    GiannisCh
    2014-04-24

    Hi Rommel, all

    I am very intrested in the source code of PROGNOS project, so as to start developing using the MEBN API. Can you provide a link with the code?
    Also, is there a tutorial available for this purpose?

    Thank you,

    Giannis

     
    Last edit: GiannisCh 2014-04-24
  • GiannisCh
    GiannisCh
    2014-04-28

    Hi Rommel,
    thank you for your reply.

    I have checked the code that you provided with the links.
    However, it would be more convenient for me to have the entire project. I tried with TortoiseSVN and SVN connector in Eclipse but I couldn't download the code.
    Am I doing something wrong or is it not permissible to download the entire project?

    Giannis

     
    Last edit: GiannisCh 2014-04-28
  • Hi Giannis,

    You should be able to download it even as anonymous with no problem. Did you see this page https://sourceforge.net/p/prognos/code/HEAD/tree/? There is a command there that tells you how to do it.

    Cheers,
    Rommel

     
  • GiannisCh
    GiannisCh
    2014-04-29

    Hi Rommel,

    I have downloaded the project from the link you mentioned. However, there are more than one java projects and none of them can be built. Moreover, some projects do not contain a "main" class.

    So, I tried to make a new project and include the necessary java files, such as MEBNReasoningWS.java and MEBNUtil.java along with the java classes/files that they use. The problem is that When I create a MEBNReasoningWS object (with a ubf file created by me using unbbayes) the following error comes up:

    log4j:WARN No appenders could be found for logger (org.java.plugin.ObjectFactory).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" java.lang.NoClassDefFoundError: edu/stanford/smi/protegex/owl/repository/Repository
    at unbbayes.io.mebn.UbfIO.<init>(UbfIO.java:138)
    at unbbayes.io.mebn.UbfIO.getInstance(UbfIO.java:146)
    at MEBNReasoning.loadMebn(MEBNReasoning.java:83)
    at MEBNReasoning.<init>(MEBNReasoning.java:50)
    at Main.main(Main.java:18)
    Caused by: java.lang.ClassNotFoundException: edu.stanford.smi.protegex.owl.repository.Repository
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

    As you can see, the repository edu/stanford/smi/protegex/owl/repository/Repository is mentioned, for which I have no idea where it can or should be placed.

    If you can help me on that, I would grateful.

    Thank you,

    Giannis

     
  • GiannisCh
    GiannisCh
    2014-04-30

    OK, I have made some progress since my last post.
    As it is evident, the exceptions (such as the above) are due to the lack of the appropriate jar files. I added the needed jar files according to error message of the exception. I am at a point where the following error comes up:

    Exception in thread "main" java.lang.NoSuchMethodError: edu.stanford.smi.protege.model.Cls.setName(Ljava/lang/String;)V

    I couldn't find a jar file in the web nor in the files of unbbayes project in sourceforge that contains the Cls class with this method.

    So, I tried to use maven in order to import the unbbayes project in Eclipse. However there are errors in POM file, i.e., missing artifacts. I have followed the instruction for integration of maven and eclipse carefully. I don't know what else to do. Can you please describe the exact steps of this procedure, in case I am doing something wrong?

    Thanks,

    Giannis

     
    Last edit: GiannisCh 2014-04-30
  • cardialfly
    cardialfly
    2014-05-21

    I'm not exactly sure about which project you are customizing, and what you are actually trying to do (due to lack of information, like the stack trace), but such error in Protege (UnBBayes-MEBN loads protege in background) can also happen if you are trying to open an ontology which is not DL-compliant (for instance, this can also happen if the dependencies --i.e. imports-- of the OWL ontologies are not in same version), or if you are not using compatible versions of all JAR dependencies (e.g. all JARs of Protege and Jena).

    You are using the JARs in the mvn_lib folder, which is supposedly equal to the ones you find in the UnBBayes-MEBN plug-in distribution, right?

    Please, notice that if you are using the "PrognosReasoning" project, it is probably deprecated, so it's likely to be outdated considerably.

    By the way, if your objective is to simply use UnBBayes-MEBN as an API for other projects, my suggestion is to use the jars of UnBBayes-MEBN directly, instead of trying to load advanced features of Prognos (like web services, time-slice simulator, and support for continuous nodes). Therefore, the steps I suggest are:

    1 - Download some UnBBayes core distribution. Pick some new version, but if the newest doesn't work, you may need to pick a slightly older version.

    2 - Extract the zip file, and place all jars (literally everything you find, including the ones in subfolders) to the classpath of your project.

    3 - Download some UnBBayes-MEBN plug-in distribution. Pick some new version, but if the newest doesn't work, you may need to pick an older version.
    Do not pick the one in "PR-OWL 2" folder, because it uses OSGi framework, so it's going to be harder for you to use it if your project do not use OSGi.

    4 - Extract the zip file, and place all jars (literally everything you find, including the ones in subfolders) to the classpath of your project.

    5 - Copy/move the "pr-owl" folder either to the root folder of your project, or to your resource folder (if you have a resource folder), or to both.

    6 - In your program, instantiate an object of "unbbayes.TextModeRunner" (you should be able to find it somewhere in unbbayes.prs.mebn-X.X.X.jar). This is the API for UnBBayes-MEBN, and it wraps most of methods you need in order to make a query in a MEBN model. Prognos is basically using this internally.

    The source code of the JUnit test for TextModeRunner is a simple example on how to use the TextModeRunner. The method "setUp" instantiates all necessary objects (e.g. loads a MTheory and knowledge base from files and instantiates TextModeRunner), and the other methods are examples of single and multiple queries.

    Hope this helps in something...

    My apologies for not being able to reply faster.
    Best regards.

     
  • GiannisCh
    GiannisCh
    2014-05-26

    Hi,
    Thank you for your reply. I finally managed to use TextModeRunner and pose a query using jars in my project from the 3.52 version of unbbayes.
    Moreover, I include the rt.jar file (i.e., the java runtime classes) from the latest java sdk. The same file from the (latest) java runtime environment didn't work, so I hope this helps someone reading this to avoid such a problem.

    By the way, as far as I know, there is still no module in unbbayes for MEBN learning. Will such feature be included in future versions of unbbayes?

    Best regards,
    Giannis