public bool IsTrueFor(double probability, Dictionary <string, bool?> modelBuiltUpSoFar) { Dictionary <string, bool?> conditions = new Dictionary <string, bool?>(); if (this.IsRoot()) { conditions[Variable] = true; } else { for (int i = 0; i < this.Parents.Count; i++) { BayesNetNode parent = this.Parents[i]; conditions[parent.Variable] = modelBuiltUpSoFar[parent.Variable]; } } double trueProbability = this.ProbabilityOf(conditions); if (probability <= trueProbability) { return(true); } return(false); }
public void InfluencedBy(BayesNetNode parent1, BayesNetNode parent2) { this.InfluencedBy(parent1); this.InfluencedBy(parent2); distribution = new ProbabilityDistribution(parent1.Variable, parent2.Variable); }
private void AddChild(BayesNetNode node) { if (!(this.Children.Contains(node))) { this.Children.Add(node); } }
private void AddParent(BayesNetNode node) { if (!(this.Parents.Contains(node))) { this.Parents.Add(node); } }
public bool Equals(BayesNetNode other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.Variable, this.Variable)); }
public double ProbabilityOf(string Y, bool?value, Dictionary <string, bool?> evidence) { BayesNetNode y = this.GetNodeOf(Y); if (y == null) { throw new ApplicationException("Unable to find a node with variable " + Y); } IList <BayesNetNode> parentNodes = y.Parents; if (parentNodes.Count == 0) // root nodes { Dictionary <string, bool?> yTable = new Dictionary <string, bool?>(); yTable[Y] = value; double prob = y.ProbabilityOf(yTable); return(prob); } else // non rootnodes { Dictionary <string, bool?> parentValues = new Dictionary <string, bool?>(); foreach (BayesNetNode parent in parentNodes) { parentValues[parent.Variable] = evidence[parent.Variable]; } double prob = y.ProbabilityOf(parentValues); if (value.Equals(true)) { return(prob); } return(1.0 - prob); } }
private IList <BayesNetNode> MarkovBlanket(BayesNetNode node, IList <BayesNetNode> soFar) { // parents IList <BayesNetNode> parents = node.Parents; foreach (BayesNetNode parent in parents) { if (!soFar.Contains(parent)) { soFar.Add(parent); } } // children IList <BayesNetNode> children = node.Children; foreach (BayesNetNode child in children) { if (!soFar.Contains(child)) { soFar.Add(child); IList <BayesNetNode> childsParents = child.Parents; foreach (BayesNetNode childsParent in childsParents) { ; if ((!soFar.Contains(childsParent)) && (!(childsParent.Equals(node)))) { soFar.Add(childsParent); } } // childsParents } // end Contains child } // end child return(soFar); }
private IList <BayesNetNode> MarkovBlanket(BayesNetNode node) { return(this.MarkovBlanket(node, new List <BayesNetNode>())); }
public BayesNet(BayesNetNode root1, BayesNetNode root2, BayesNetNode root3) : this(root1, root2) { roots.Add(root3); }
public BayesNet(BayesNetNode root1, BayesNetNode root2) : this(root1) { roots.Add(root2); }
public BayesNet(BayesNetNode root) { roots.Add(root); }
public void InfluencedBy(BayesNetNode parent1) { this.AddParent(parent1); parent1.AddChild(this); distribution = new ProbabilityDistribution(parent1.Variable); }