Examples of BNNode


Examples of org.integratedmodelling.riskwiz.bn.BNNode

    public void execute(BeliefNetwork bn) {
        oredredSets = new Vector<Set<BNNode>>();
        oredredDecisionNodes = new Vector< BNNode>();
    
        for (TopologicalOrderIterator it = new TopologicalOrderIterator(bn); it.hasNext();) {
            BNNode node = (BNNode) it.next();

            if (node.isDecision()) {
                Set<BNNode> parents = bn.getParents(node);

                oredredDecisionNodes.add(node);
                oredredSets.add(parents);        
            }
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

   
        while (!marginals.isEmpty()) {
            Vector<DiscreteDomain> domsSet = new Vector<DiscreteDomain>();

            while (!marginals.isEmpty() && marginals.first().isNature()) {
                BNNode first = marginals.first();

                domsSet.add(first.getDiscretizedDomain());
                marginals.remove(first);
            }
            if (!domsSet.isEmpty()) {
        
                FMarginalizationMap mmap = new FMarginalizationMap(
                        currentDomainProduct, domsSet);

                rootMmaps.add(mmap);
                currentDomainProduct.removeAll(domsSet);
            }
            while (!marginals.isEmpty() && marginals.first().isDecision()) {
         
                BNNode first = marginals.first();
       
                rootMmaps.add(first.getDomain());
                currentDomainProduct.remove(first.getDomain());
                marginals.remove(first);
            }
        } 
     
    }
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

    }
 
    public IntervalDomain getDiscretizedDomain(Domain dom,
            BeliefNetwork bn) {
   
        BNNode node = bn.getBeliefNode(dom.getName());

        return (IntervalDomain) node.getDiscretizedDomain();

    }
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

        }
    }

    private void updateMarginals() {
        for (int i = 0; i < orderedNodes.size(); i++) {
            BNNode node = orderedNodes.elementAt(i);

            if (!node.hasEvidence()) {
                PT marginal = new PT(
                        DomainFactory.createDomainProduct(
                                node.getDiscretizedDomain()));
                double[] counter = node.getSamplesCounter();

                for (int j = 0; j < counter.length; j++) {
                    double val = counter[j];

                    marginal.setValue(j, val);
                }
                marginal.normalize();
                node.setMarginal(marginal);
            }
        }
    }
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

        // 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);
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

    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");
        }
        //
        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

Examples of org.integratedmodelling.riskwiz.bn.BNNode

    public static Vector<BNNode> topologicalOrder(BeliefNetwork bn) {
   
        Vector<BNNode> vect = new Vector<BNNode>();

        for (TopologicalOrderIterator it = new TopologicalOrderIterator(bn); it.hasNext();) {
            BNNode node = (BNNode) it.next();

            vect.add(node);
     
        }
        return vect;
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

        }
    }
 
    @Override
  public PT getEvidence(String nodeName) {
        BNNode node = bn.getBeliefNode(nodeName);
    
        return node.getEvidence();
     
    }
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

        return node.getEvidence();
     
    }
 
    public PT getBelief(String nodeName) {
        BNNode node = bn.getBeliefNode(nodeName);

        return getBelief(node);
     
    }
View Full Code Here

Examples of org.integratedmodelling.riskwiz.bn.BNNode

     
    }

    @Override
  public PT getMarginal(String nodeName) {
        BNNode node = bn.getBeliefNode(nodeName);

        return node.getMarginal();
    }
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.