示例#1
0
        //
        // PRIVATE METHODS
        //
        private Factor makeFactor(RandomVariable var, AssignmentProposition[] e,
                                  BayesianNetwork bn)
        {
            Node n = bn.getNode(var);

            if (!(n is FiniteNode))
            {
                throw new IllegalArgumentException(
                          "Elimination-Ask only works with finite Nodes.");
            }
            FiniteNode fn = (FiniteNode)n;
            List <AssignmentProposition> evidence = new List <AssignmentProposition>();

            foreach (AssignmentProposition ap in e)
            {
                if (fn.getCPT().contains(ap.getTermVariable()))
                {
                    evidence.Add(ap);
                }
            }

            return(fn.getCPT().getFactorFor(
                       evidence.ToArray()));
        }
示例#2
0
            public double posteriorForParents(RandomVariable rv)
            {
                Node n = bn.getNode(rv);

                if (!(n is FiniteNode))
                {
                    throw new ArgumentException(
                              "Enumeration-Ask only works with finite Nodes.");
                }
                FiniteNode fn = (FiniteNode)n;

                Object[] vals = new Object[1 + fn.getParents().Count];
                int      idx  = 0;

                foreach (Node pn in n.getParents())
                {
                    vals[idx] = extendedValues[varIdxs.get(pn.getRandomVariable())];
                    idx++;
                }
                vals[idx] = extendedValues[varIdxs.get(rv)];

                return(fn.getCPT().getValue(vals));
            }