public String renderInferenceResult(BeliefNetwork bn, Inference Inf) { String result = ""; BeliefNode[] nodes = bn.getNodes(); if (_RENDERHTML) { result += "<table>"; } for (int i = 0; i < nodes.length; i++) { BeliefNode X = nodes[i]; if (_RENDERHTML) { result += "<tr>"; } else { result += X.getName() + ":\n"; } result += renderCPF(Inf.queryMarginal(X)); if (_RENDERHTML) { result += "</tr>"; } else { result += "\n"; } } if (_RENDERHTML) { result += "</table>"; } return result; }
public void print(PrintStream out) { BeliefNode[] nodes = bn.bn.getNodes(); int[] order = bn.getTopologicalOrder(); for (int i = nodes.length - 1; i >= 0; i--) { BeliefNode n = nodes[order[i]]; out.printf("%s: %s\n", n.toString(), bucketMap.get(n)); } }
@Override protected void _initialize() { // detect minimum bound ibound = 1; for (BeliefNode n : nodes) { int l = n.getCPF().getDomainProduct().length; if (l > ibound) ibound = l; } // construct join-graph if (verbose) out.printf("constructing join-graph with i-bound %d...\n", ibound); jg = new JoinGraph(bn, ibound); // jg.writeDOT(new File("jg.dot")); }
public String toString() { StringBuffer sb = new StringBuffer("MF["); sb.append("scope: " + StringTool.join(", ", scope)); sb.append("; CPFs:"); int i = 0; for (BeliefNode n : this.cpts) { if (i++ > 0) sb.append("; "); sb.append(n.getCPF().toString()); } sb.append("; children: "); sb.append(StringTool.join("; ", this.childFunctions)); sb.append("]"); return sb.toString(); }
/*! Change the domain of a CPF * \param cpf - the original cpf * \param bad - the bad node * \param domNew - the new domain * \param map - the mapping for keeping from the old domain to the old domain * \return the new CPF with the domain rearrangement/change */ public static CPF changeDomain(CPF cpf, BeliefNode bad, Domain domNew, int[] map) { Domain Old = bad.getDomain(); bad.setDomain(domNew); BeliefNode[] prod = cpf.getDomainProduct(); CPF newCPF = new CPF(prod); int idx = -1; for (int i = 0; i < prod.length; i++) { if (prod[i] == bad) idx = i; } bad.setDomain(Old); int[] q = cpf.realaddr2addr(0); for (int i = 0; i < cpf.size(); i++) { Value v = cpf.get(i); int dQ = q[idx]; if (map[dQ] >= 0) { q[idx] = map[dQ]; bad.setDomain(domNew); newCPF.put(q, v); bad.setDomain(Old); q[idx] = dQ; } cpf.addOne(q); } bad.setDomain(Old); return newCPF; }
public Cluster getReducedCluster(HashSet<BeliefNode> nodes) throws CloneNotSupportedException { // deletes all functions and arcs in the cluster whose scope // contains the given nodes Cluster redCluster = this.copy(); for (BeliefNode bn : nodes) { HashSet<BeliefNode> foo = (HashSet<BeliefNode>) cpts.clone(); for (BeliefNode n : foo) { BeliefNode[] domProd = n.getCPF().getDomainProduct(); /* * if (bn.equals(n)){ redCluster.cpts.remove(n); } */ for (int i = 0; i < domProd.length; i++) { if (bn.equals(domProd[i])) { redCluster.cpts.remove(n); break; } } } for (MessageFunction m : ((HashSet<MessageFunction>) functions.clone())) { if (m.scope.contains(bn)) redCluster.functions.remove(m); } } return redCluster; }