public static double[] ask(Query q, ProbabilityDistribution pd) { double[] probDist = new double[2]; Dictionary<String, bool> h = q.getEvidenceVariables(); // true probability h[q.getQueryVariable()] = true; probDist[0] = pd.probabilityOf(h); // false probability h[q.getQueryVariable()] = false; probDist[1] = pd.probabilityOf(h); return Util.normalize(probDist); }
public static double[] ask(Query q, BayesNet net) { Dictionary<String, bool> evidenceVariables = q.getEvidenceVariables(); double[] probDist = new double[2]; // true probability evidenceVariables[q.getQueryVariable()] = true; probDist[0] = enumerateAll(net, net.getVariables(), evidenceVariables); // false probability evidenceVariables[q.getQueryVariable()] = false; probDist[1] = enumerateAll(net, net.getVariables(), evidenceVariables); // System.Console.WriteLine( probDist[0] + " " + probDist[1]); // return probDist; double[] normalized = Util.normalize(probDist); // System.Console.WriteLine( normalized[0] + " " + normalized[1]); return normalized; }