@Test public void testCanComputePosteriors() { NodeCategorical nGender = new NodeCategorical(null, "gender"); nGender.addDomain("male", "female"); nGender.setProbabilities(0.55, "male"); nGender.setProbabilities(0.45, "female"); assertTrue(nGender.isValid()); NodeCategorical nAge = new NodeCategorical(null, "age"); nAge.addParent(nGender); nAge.addDomain("A", "B", "C"); nAge.setProbabilities(1./3, "A", "gender", "male"); nAge.setProbabilities(1./3, "B", "gender", "male"); nAge.setProbabilities(1./3, "C", "gender", "male"); nAge.setProbabilities(1./3, "A", "gender", "female"); nAge.setProbabilities(1./3, "B", "gender", "female"); nAge.setProbabilities(1./3, "C", "gender", "female"); assertTrue("the test node is not valid", nAge.isValid()); nGender.getConditionalProbabilityPosterior("male"); nGender.getConditionalProbabilityPosterior("female"); nAge.getConditionalProbabilityPosterior("A"); nAge.getConditionalProbabilityPosterior("B"); nAge.getConditionalProbabilityPosterior("C"); }
public boolean isValid() { for (N n: nodes) { if (!n.isValid()) return false; } return true; }
BayesianNetwork { public boolean isValid() { for (N n: nodes) { if (!n.isValid()) return false; } return true; } }
BayesianNetwork { public boolean isValid() { for (N n: nodes) { if (!n.isValid()) return false; } return true; } BayesianNetwork(String name); }
BayesianNetwork { public boolean isValid() { for (N n: nodes) { if (!n.isValid()) return false; } return true; } BayesianNetwork(String name); void add(N n); void addAll(Collection<N> nns); boolean containsNode(N n); N getVariable(String id); void notifyNodesChanged(); List<N> enumerateNodes(); Set<N> getNodes(); void saveAsXMLBIF(File f); void saveAsXMLBIF(String filename); boolean isValid(); Map<N,List<String>> collectInvalidProblems(); Set<N> getAllAncestors(N n); Set<N> getAllChildren(N n); Set<N> getParents(AbstractNode<N> n); Set<N> getChildren(AbstractNode<N> n); }
BayesianNetwork { public boolean isValid() { for (N n: nodes) { if (!n.isValid()) return false; } return true; } BayesianNetwork(String name); void add(N n); void addAll(Collection<N> nns); boolean containsNode(N n); N getVariable(String id); void notifyNodesChanged(); List<N> enumerateNodes(); Set<N> getNodes(); void saveAsXMLBIF(File f); void saveAsXMLBIF(String filename); boolean isValid(); Map<N,List<String>> collectInvalidProblems(); Set<N> getAllAncestors(N n); Set<N> getAllChildren(N n); Set<N> getParents(AbstractNode<N> n); Set<N> getChildren(AbstractNode<N> n);  }