Package org.integratedmodelling.riskwiz.jtree

Examples of org.integratedmodelling.riskwiz.jtree.JTInference


        // +  bnodeSprinkler.getCPF().toString() );
        // System.out.println("r:" + bnodeWetGrass.getName() + ":\n"
        // +  bnodeWetGrass.getCPF().toString() );

    
        JTInference inference = new JTInference();

        try {
            inference.initialize(bn, new JoinTreeCompiler());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        inference.run();

        // System.out.println("Here are the marginal after inference with Belief
        // Elimination");
        // System.out.println("r:"+ bnodeCloudy.getName() + ":\n" +
        // cpf2string(VE.queryMarginal(bnodeCloudy)));
        // System.out.println("r:"+ bnodeSprinkler.getName() + ":\n" +
        // cpf2string(VE.queryMarginal(bnodeSprinkler)));
        // System.out.println("r:"+ bnodeRain.getName() + ":\n" +
        // cpf2string(VE.queryMarginal(bnodeRain)));
        // System.out.println("r:"+ bnodeWetGrass.getName() + ":\n" +
        // cpf2string(VE.queryMarginal(bnodeWetGrass)));
   
        Set<BNNode> nodes1 = bn.vertexSet();

        for (BNNode node : nodes1) {
            System.out.println(
                    node.getName() + ":\n" + node.getMarginal().toString()
                    + "\n");
        }
        //
        System.out.println(
                "Here are the marginal after inference with Belief Elimination");
        System.out.println(
                "r:" + bnodeCloudy.getName() + ":\n"
                + inference.getMarginal(bnodeCloudy));
        System.out.println(
                "r:" + bnodeSprinkler.getName() + ":\n"
                + inference.getMarginal(bnodeSprinkler));
        System.out.println(
                "r:" + bnodeRain.getName() + ":\n"
                + inference.getMarginal(bnodeRain));
        System.out.println(
                "r:" + bnodeWetGrass.getName() + ":\n"
                + inference.getMarginal(bnodeWetGrass));

    }
View Full Code Here


            }
     
            // BeliefNode carbon= network.getBeliefNode("ClimateStability");
            // System.out.println(carbon.getCPF().toString());
     
            JTInference inference = new JTInference();

            // JTCompilerDebugger deb = new JTCompilerDebugger();
            // deb.doAll();
     
            inference.initialize(network, new JoinTreeCompiler());
            inference.run();
      
            Set<BNNode> nodes = network.vertexSet();

            for (BNNode node : nodes) {
        
View Full Code Here

            }

            // BeliefNode carbon= network.getBeliefNode("ClimateStability");
            // System.out.println(carbon.getCPF().toString());

            JTInference inference = new JTInference();

            // JTCompilerDebugger deb = new JTCompilerDebugger();
            // deb.doAll();

            inference.initialize(network, new JoinTreeCompiler());
            inference.run();

            Set<BNNode> nodes = network.vertexSet();

            for (BNNode node : nodes) {
                System.out.println(
View Full Code Here

         
            System.out.println("ciao");
            BeliefNetwork bn = r.load(new FileInputStream("examples/water.xdsl"));
            // BeliefNetwork bn =rb.load(new FileInputStream("examples/sprinkler.xml"));

            JTInference inference = new JTInference();

            inference.initialize(bn, new JoinTreeCompiler());
            // inference.setObservation("Cloudy", "true");
            inference.run();
       
            for (BNNode n : bn.vertexSet()) {
                System.out.println(n.getName() + ": " + n.getMarginal());
            }
       
View Full Code Here

                        node.getName() + ":\n" + node.getFunction().toString()
                        + "\n");
            }
   
            // run inference
            JTInference inference = new JTInference();

            inference.initialize(network, new JoinTreeCompiler());
            inference.run();

            // output inference results
            System.out.println("Marginals of original network\n");
            for (BNNode node : nodes) {
                System.out.println(
                        node.getName() + ":\n" + node.getMarginal().toString()
                        + "\n");
            }
     
            // learning starts here
     
            // create a new learner
            BayesianLearner learner = new BayesianLearner();

            // you need to initialize the link between the learner and network
            // this initialization will clear existing
            // probability tables from the network and set up uniform Dirichlet priors
            learner.initialize(network);
     
            // System.out.println("CPTs Before Learning \n");
            //
            // for (BeliefNode node : nodes) {
            // System.out.println(node.getName() + ":\n"
            // + node.getTable().toString() + "\n");
            // }
     
            // create a new data source for the learner
     
            GraphDataFile graphData = new GraphDataFile();
     
            // now, populate the data source, in this case from file
            graphData.readArff(dataFile);
     
            // you need to connect it too, which will help
            // the instance IGraphData to understand how to
            // format dta so that they fit the network
            // graphData.connect(network);
     
            // finally, learn!
            learner.learnFromTable(graphData);
     
            inference = new JTInference();
            inference.initialize(network, new JoinTreeCompiler());
            inference.run();
            // now, show the probabilities again
            // nodes = network.vertexSet();
            System.out.println("CPTs after learning\n");
            nodes = network.vertexSet();
            for (BNNode node : nodes) {
View Full Code Here

                        node.getName() + ":\n" + node.getFunction().toString()
                        + "\n");
            }
   
            // run inference
            JTInference inference = new JTInference();

            inference.initialize(network, new JoinTreeCompiler());
            inference.run();

            // output inference results
            System.out.println("Marginals of original network\n");
            for (BNNode node : nodes) {
                System.out.println(
                        node.getName() + ":\n" + node.getMarginal().toString()
                        + "\n");
            }
     
            // learning starts here
     
            // create a new learner
            BayesianLearner learner = new BayesianLearner();

            // you need to initialize the link between the learner and network
            // this initialization will clear existing
            // probability tables from the network and set up uniform Dirichlet priors
            learner.initializeWithPriors(network, NofVirtualSamples);
     
            System.out.println("CPTs Before Learning \n");
      
            for (BNNode node : nodes) {
                System.out.println(
                        node.getName() + ":\n" + node.getFunction().toString()
                        + "\n");
            }
     
            // create a new data source for the learner
     
            GraphDataFile graphData = new GraphDataFile();
     
            // now, populate the data source, in this case from file
            graphData.readArff(dataFile);
     
            // you need to connect it too, which will help
            // the instance IGraphData to understand how to
            // format dta so that they fit the network
            graphData.connect(network);
     
            // finally, learn!
            learner.learnFromTable(graphData);
     
            inference = new JTInference();
            inference.initialize(network, new JoinTreeCompiler());
            inference.run();
            // now, show the probabilities again
            // nodes = network.vertexSet();
            System.out.println("CPTs after learning\n");
            nodes = network.vertexSet();
            for (BNNode node : nodes) {
View Full Code Here

            if (network == null) {
                System.out.println("Problems with loading the  network");
                return;
            }
            // run inference
            JTInference inference = new JTInference();
            JTCompilerDebugger deb = new JTCompilerDebugger();

            deb.doAll();
     
            inference.initialize(network, new JoinTreeCompiler(), deb);
            inference.run();

            // output inference results

            Set<BNNode> nodes = network.vertexSet();
View Full Code Here

                    node.getName() + ":\n" + node.getFunction().toString()
                    + "\n");
        }
     
        // run inference
        JTInference inference = new JTInference();
        JTCompilerDebugger deb = new JTCompilerDebugger();

        deb.doAll();
     
        try {
            inference.initialize(network, new JoinTreeCompiler(), deb);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        inference.run();
        // output inference results
        System.out.println("Marginals After IInference  \n");
     
        Set<BNNode> nodes1 = network.vertexSet();
View Full Code Here

        if (network == null) {
            System.out.println("Can't load network");
            return;
        }

        JTInference inference = new JTInference();
        JTCompilerDebugger deb = new JTCompilerDebugger();

        deb.doAll();
     
        try {
            inference.initialize(network, new JoinTreeCompiler(), deb);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Set<BNNode> nodes = network.vertexSet();

        // creating new evidence
        BNNode node1 = network.getBeliefNode("Cloudy");

        inference.setObservation(node1, "false");
        // much better way to do just the same as in last two lines
        // inference.setObservation("Cloudy", "false");
     
     
        inference.run();

        System.out.println("Marginals After IInference  \n");
        for (BNNode node : nodes) {
            System.out.println(
                    node.getName() + ":\n" + node.getMarginal().toString()
View Full Code Here

            if (network == null) {
                System.out.println("Can't load network");
                return;
            }
            JTInference inference = new JTInference();
            JTCompilerDebugger deb = new JTCompilerDebugger();

            deb.doAll();
     
            inference.initialize(network, new JoinTreeCompiler(), deb);
            BNNode node1;

            node1 = network.getBeliefNode("Cloudy");
     
            // alternative way to set observation, it should work for more general
            // situation where evidence is not just observation but a probability distribution
            PT de = TableFactory.createObservation(node1.getDiscretizedDomain(),
                    "false");

            // normally this is better to use   for seting evidence, there is easy way with observations
            inference.setEvidence("Cloudy", de);
            inference.run();
            Set<BNNode> nodes = network.vertexSet();

            for (BNNode node : nodes) {
                System.out.println(
                        node.getName() + ":\n" + node.getMarginal().toString()
                        + "\n");
            }
     
            PT de1 = TableFactory.createObservation(node1.getDiscretizedDomain(),
                    "false");

            // normally this is better to use   for seting evidence, there is easy way with observations
            inference.setEvidence("Cloudy", de1);
            inference.run();
            for (BNNode node : nodes) {
                System.out.println(
                        node.getName() + ":\n" + node.getMarginal().toString()
                        + "\n");
            }
            // here is how we clear evidence, after this the probability for each
            // value
            // is taken from the specified CPF
            inference.retractEvidence("Cloudy");
            inference.run();
            System.out.println("IInference Results after clearing the evidence");
            for (BNNode node : nodes) {
                System.out.println(
                        node.getName() + ":\n" + node.getMarginal().toString()
                        + "\n");
View Full Code Here

TOP

Related Classes of org.integratedmodelling.riskwiz.jtree.JTInference

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.