00001 import java.util.HashSet;
00002 import java.util.Random;
00003
00004 import edu.ksu.cis.bnj.ver3.core.BeliefNode;
00005 import edu.ksu.cis.bnj.ver3.core.Domain;
00006 import edu.tum.cs.bayesnets.core.BeliefNetworkEx;
00007
00008
00013 public class BNrandomEvidence {
00014
00018 public static void main(String[] args) {
00019 try {
00020
00021 if(args.length != 2) {
00022 System.out.println("\n usage: BNrandomEvidence <network> <numEvidence>\n\n");System.exit(1);
00023 }
00024 String networkFile = args[0];
00025 int numEvidence = Integer.parseInt(args[1]);
00026
00027
00028 BeliefNetworkEx bn = new BeliefNetworkEx(networkFile);
00029 BeliefNode[] nodes = bn.bn.getNodes();
00030 HashSet<BeliefNode> handled = new HashSet<BeliefNode>();
00031 Random rand = new Random();
00032 while(handled.size() < numEvidence) {
00033 BeliefNode n = nodes[rand.nextInt(nodes.length)];
00034 if(handled.contains(n))
00035 continue;
00036 handled.add(n);
00037 Domain d = n.getDomain();
00038 System.out.printf("%s = %s\n", n.toString(), d.getName(rand.nextInt(d.getOrder())));
00039 }
00040 }
00041 catch(Exception e) {
00042 e.printStackTrace();
00043 }
00044 }
00045 }