Examples of BeliefNetwork


Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

            }
        }
    }

    public void visitModel(Node parent) {
        graph = new BeliefNetwork();
        NodeList l = parent.getChildNodes();

        if (l == null) {
            throw new RuntimeException("Unexpected end of document!");
        }
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

    public static void main(String[] args) {
        GenieReader r = new GenieReader();
        GenieWriter w = new  GenieWriter();

        try {
            BeliefNetwork bn = r.load(
                    new FileInputStream("examples/CarbonSourceValue.xdsl"));
            
            System.out.println("----------------------------------")
            w.save(System.out, bn);
        } catch (Exception e) {
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

    // how to create a belief network, manipulate its structure and save it into
    // a file
    public void waterNetwork() {
        // creating a network
        BeliefNetwork bn = new BeliefNetwork("MyNetwork");

        // creating a boolean node

        String[] boolDomain = { "true", "false" };

        BNNode bnodeHasRiver = new BNNode("HasRiver", boolDomain);
        // creating more general discrete node
        String[] HMLDomain = { "high", "medium", "low" };
        BNNode bnodeWaterSupply = new BNNode("WaterSupply", HMLDomain);

        // creating another discrete node, note new instance of class Discrete
        // has to be created,
        // though you can reuse the string array boolDomain
        BNNode bnodePolution = new BNNode("WaterSupply", boolDomain);

        // add nodes to the network
        bn.addBeliefNode(bnodeHasRiver);
        bn.addBeliefNode(bnodePolution);
        bn.addBeliefNode(bnodeWaterSupply);

        // connecting nodes
        bn.addEdge(bnodeHasRiver, bnodeWaterSupply);
        bn.addEdge(bnodePolution, bnodeWaterSupply);

        // save the created network
        String filename = "MyNetwork.xml";

        try {
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

    // the directory
    // api_example

    public void sprinklerNetwork() {

        BeliefNetwork bn = new BeliefNetwork();
        String[] boolDomain = { "true", "false" };

        BNNode bnodeCloudy = new BNNode("Cloudy", boolDomain);
        BNNode bnodeRain = new BNNode("Rain", boolDomain);
        BNNode bnodeSprinkler = new BNNode("Sprinkler", boolDomain);
        BNNode bnodeWetGrass = new BNNode("WetGrass", boolDomain);

        bn.addBeliefNode(bnodeRain);
        bn.addBeliefNode(bnodeCloudy);
        bn.addBeliefNode(bnodeWetGrass);
        bn.addBeliefNode(bnodeSprinkler);

        // note the order of execution of connect().
        // domains are added in sequence as parent nodes are connected
        bn.addEdge(bnodeCloudy, bnodeRain);
        bn.addEdge(bnodeCloudy, bnodeSprinkler);
        bn.addEdge(bnodeSprinkler, bnodeWetGrass);
        bn.addEdge(bnodeRain, bnodeWetGrass);

        // this is simple
        TabularCPD table = (TabularCPD) bnodeCloudy.getFunction();

        table.setValue(0, 0.5);
        table.setValue(1, 0.5);

        // see image sprinkler.jpg to make sense out of the order
        // plus mind the rder of execution of connect() above
        table = (TabularCPD) bnodeSprinkler.getFunction();
        table.setValue(0, 0.1);
        table.setValue(1, 0.5);
        table.setValue(2, 0.9);
        table.setValue(3, 0.5);

        // see image sprinkler.jpg to make sense out of the order
        table = (TabularCPD) bnodeRain.getFunction();
        table.setValue(0, 0.8);
        table.setValue(1, 0.2);
        table.setValue(2, 0.2);
        table.setValue(3, 0.8);

        // see image sprinkler.jpg to make sense out of the order
        table = (TabularCPD) bnodeWetGrass.getFunction();
        table.setValue(0, 0.99);
        table.setValue(1, 0.9);
        table.setValue(2, 0.9);
        table.setValue(3, 0.0);
        table.setValue(4, .01);
        table.setValue(5, 0.1);
        table.setValue(6, 0.1);
        table.setValue(7, 1.0);

        // Rain.setEvidence(new DiscreteEvidence((Discrete)Rain.getDomain(),
        // "true"));;
        // WetGrass.setEvidence(new
        // DiscreteEvidence((Discrete)Sprinkler.getDomain(), "true"));;

        // Rain.setEvidence(new PolyEvidence());
        // // WetGrass.setEvidence(new PolyEvidence());
        // System.out.println("Here are the CPFS");
        // System.out.println("r:" + bnodeCloudy.getName() + ":\n"
        // +  bnodeCloudy.getCPF().toString() );
        // System.out.println("r:" + bnodeRain.getName() + ":\n"
        // +  bnodeRain.getCPF().toString() );
        // System.out.println("r:" + bnodeSprinkler.getName() + ":\n"
        // +  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");
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

 
    public static void test(String file) {
        GenieReader gReader = new GenieReader();

        try {
            BeliefNetwork network = gReader.loadFromFile(file);

            if (network == null) {
                System.out.println("Can't load network");
                return;
            }
     
            // 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(
                        node.getName() + ":\n" + node.getMarginal().toString()
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

    public static void main(String[] args) {
        XmlBifReader r = new XmlBifReader();
        XmlBifWriter w = new  XmlBifWriter();

        try {
            BeliefNetwork bn = r.load(
                    new FileInputStream("examples/sprinkler.xml"));
            
            System.out.println("----------------------------------")
            w.save(System.out, bn);
        } catch (Exception e) {
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

    public void test() {
        GenieReader gReader = new GenieReader();

        try {
            BeliefNetwork network = gReader.loadFromFile("examples/carbon3.xdsl");

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

            // 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(
                        node.getName() + ":\n" + node.getMarginal().toString()
                        + "\n");
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

    }

    public void testJoinTree() {
        GenieReader gReader = new GenieReader();

        BeliefNetwork network = null;

        try {
            network = gReader.loadFromFile("examples/carbon3.xdsl");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

            switch (node.getNodeType()) {
            case Node.ELEMENT_NODE:
                String name = node.getNodeName();

                if (name.equals("riskwiz")) {
                    graph = new BeliefNetwork();
                    NamedNodeMap attrs = node.getAttributes();

                    if (attrs != null) {
                        int amax = attrs.getLength();
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BeliefNetwork

            switch (node.getNodeType()) {
            case Node.ELEMENT_NODE:
                String name = node.getNodeName();

                if (name.equals("smile")) {
                    graph = new BeliefNetwork();
                    NamedNodeMap attrs = node.getAttributes();

                    if (attrs != null) {
                        int amax = attrs.getLength();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.