Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public void InfluencedBy(BayesNetNode parent1, BayesNetNode parent2)
 {
     this.InfluencedBy(parent1);
     this.InfluencedBy(parent2);
     distribution = new ProbabilityDistribution(parent1.Variable,
                                                parent2.Variable);
 }
Exemplo n.º 3
0
 private void AddChild(BayesNetNode node)
 {
     if (!(this.Children.Contains(node)))
     {
         this.Children.Add(node);
     }
 }
Exemplo n.º 4
0
 private void AddParent(BayesNetNode node)
 {
     if (!(this.Parents.Contains(node)))
     {
         this.Parents.Add(node);
     }
 }
Exemplo n.º 5
0
 public bool Equals(BayesNetNode other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.Variable, this.Variable));
 }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 private IList <BayesNetNode> MarkovBlanket(BayesNetNode node)
 {
     return(this.MarkovBlanket(node, new List <BayesNetNode>()));
 }
Exemplo n.º 9
0
 public BayesNet(BayesNetNode root1, BayesNetNode root2, BayesNetNode root3) : this(root1, root2)
 {
     roots.Add(root3);
 }
Exemplo n.º 10
0
 public BayesNet(BayesNetNode root1, BayesNetNode root2) : this(root1) {
     roots.Add(root2);
 }
Exemplo n.º 11
0
 public BayesNet(BayesNetNode root)
 {
     roots.Add(root);
 }
Exemplo n.º 12
0
 public void InfluencedBy(BayesNetNode parent1)
 {
     this.AddParent(parent1);
     parent1.AddChild(this);
     distribution = new ProbabilityDistribution(parent1.Variable);
 }