public ICategoricalDistribution jointDistribution(params IProposition[] propositions)
        {
            ProbabilityTable       d        = null;
            IProposition           conjProp = ProbUtil.constructConjunction(propositions);
            ISet <IRandomVariable> vars     = CollectionFactory.CreateSet <IRandomVariable>(conjProp.getUnboundScope());

            if (vars.Size() > 0)
            {
                IRandomVariable[] distVars = vars.ToArray();

                ProbabilityTable ud     = new ProbabilityTable(distVars);
                object[]         values = new object[vars.Size()];

                ProbabilityTable.ProbabilityTableIterator di = new ProbabilityTableIterator(conjProp, ud, values, vars);

                distribution.iterateOverTable(di);

                d = ud;
            }
            else
            {
                // No Unbound Variables, therefore just return
                // the singular probability related to the proposition.
                d = new ProbabilityTable();
                d.setValue(0, prior(propositions));
            }
            return(d);
        }
Beispiel #2
0
        public virtual ICategoricalDistribution posteriorDistribution(IProposition phi, params IProposition[] evidence)
        {
            IProposition conjEvidence = ProbUtil.constructConjunction(evidence);

            // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
            ICategoricalDistribution dAandB    = jointDistribution(phi, conjEvidence);
            ICategoricalDistribution dEvidence = jointDistribution(conjEvidence);

            ICategoricalDistribution rVal = dAandB.divideBy(dEvidence);
            // Note: Need to ensure normalize() is called
            // in order to handle the case where an approximate
            // algorithm is used (i.e. won't evenly divide
            // as will have calculated on separate approximate
            // runs). However, this should only be done
            // if the all of the evidences scope are bound (if not
            // you are returning in essence a set of conditional
            // distributions, which you do not want normalized).
            bool unboundEvidence = false;

            foreach (IProposition e in evidence)
            {
                if (e.getUnboundScope().Size() > 0)
                {
                    unboundEvidence = true;
                    break;
                }
            }
            if (!unboundEvidence)
            {
                rVal.normalize();
            }

            return(rVal);
        }
Beispiel #3
0
 public CategoricalDistributionIteratorJointDistribution(IProposition conjProp, ISet <IRandomVariable> vars, ProbabilityTable ud, object[] values)
 {
     this.conjProp = conjProp;
     this.vars     = vars;
     this.ud       = ud;
     this.values   = values;
 }
Beispiel #4
0
        public virtual ICategoricalDistribution jointDistribution(params IProposition[] propositions)
        {
            ProbabilityTable       d        = null;
            IProposition           conjProp = ProbUtil.constructConjunction(propositions);
            ISet <IRandomVariable> vars     = CollectionFactory.CreateSet <IRandomVariable>(conjProp.getUnboundScope());

            if (vars.Size() > 0)
            {
                IRandomVariable[] distVars = new IRandomVariable[vars.Size()];
                int i = 0;
                foreach (IRandomVariable rv in vars)
                {
                    distVars[i] = rv;
                    ++i;
                }

                ProbabilityTable ud     = new ProbabilityTable(distVars);
                object[]         values = new object[vars.Size()];

                CategoricalDistributionIterator di = new CategoricalDistributionIteratorJointDistribution(conjProp, vars, ud, values);

                IRandomVariable[] X = conjProp.getScope().ToArray();
                bayesInference.Ask(X, new AssignmentProposition[0], bayesNet).iterateOver(di);

                d = ud;
            }
            else
            {
                // No Unbound Variables, therefore just return
                // the singular probability related to the proposition.
                d = new ProbabilityTable();
                d.setValue(0, prior(propositions));
            }
            return(d);
        }
 public ProbabilityTableIterator(IProposition conjProp, ProbabilityTable ud, object[] values, ISet <IRandomVariable> vars)
 {
     this.conjProp = conjProp;
     this.ud       = ud;
     this.values   = values;
     this.vars     = vars;
 }
    public ExistsFutureProposition(int numStates, IProposition f)
    {
        this.numStates = numStates;
        this.f         = f;

        // EF(f) === E[true U f]
        this.existsUntil = new ExistsUntilProposition(numStates, TrueProposition.Instance, f);
    }
Beispiel #7
0
 public GraphNode(int _currentNode, GraphNode _parentNode, IProposition _type, StreamWriter writer)
 {
     this.currentNode     = _currentNode;
     this.propositionType = _type;
     this.sw         = writer;
     this.parentNode = _parentNode;
     processNode();
 }
Beispiel #8
0
 public CategoricalDistributionIteratorImpl(IFiniteProbabilityModel transitionModel, IMap <IRandomVariable, AssignmentProposition> xtVarAssignMap, ICategoricalDistribution s1, IProposition xtp1, AssignmentProposition[] xt)
 {
     this.transitionModel = transitionModel;
     this.xtVarAssignMap  = xtVarAssignMap;
     this.s1   = s1;
     this.xtp1 = xtp1;
     this.xt   = xt;
 }
        private double probabilityOf(IProposition phi)
        {
            double[] probSum = new double[1];
            ProbabilityTable.ProbabilityTableIterator di = new ProbabilityTableIteratorImpl2(probSum, phi);

            distribution.iterateOverTable(di);

            return(probSum[0]);
        }
Beispiel #10
0
    public AllGlobalProposition(int numStates, IProposition f)
    {
        this.f = f;

        // AG(f) === !EF(!f)
        var notF = new NotProposition(f);

        this.existsFuture = new ExistsFutureProposition(numStates, notF);
    }
Beispiel #11
0
 public CategoricalDistributionIteratorImpl2(IMap <IRandomVariable, AssignmentProposition> x_kp1VarAssignMap, IFiniteProbabilityModel sensorModel, IFiniteProbabilityModel transitionModel, ICategoricalDistribution b_kp1t, IProposition pe_kp1, IProposition xk, IProposition x_kp1)
 {
     this.x_kp1VarAssignMap = x_kp1VarAssignMap;
     this.sensorModel       = sensorModel;
     this.transitionModel   = transitionModel;
     this.b_kp1t            = b_kp1t;
     this.pe_kp1            = pe_kp1;
     this.xk    = xk;
     this.x_kp1 = x_kp1;
 }
        public ICategoricalDistribution posteriorDistribution(IProposition phi,
                                                              params IProposition[] evidence)
        {
            IProposition conjEvidence = ProbUtil.constructConjunction(evidence);

            // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
            ICategoricalDistribution dAandB    = jointDistribution(phi, conjEvidence);
            ICategoricalDistribution dEvidence = jointDistribution(conjEvidence);

            return(dAandB.divideBy(dEvidence));
        }
        public CategoricalDistribution posteriorDistribution(IProposition phi,
                                                             params IProposition[] evidence)
        {

            IProposition conjEvidence = ProbUtil.constructConjunction(evidence);

            // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
            CategoricalDistribution dAandB = jointDistribution(phi, conjEvidence);
            CategoricalDistribution dEvidence = jointDistribution(conjEvidence);

            return dAandB.divideBy(dEvidence);
        }
Beispiel #14
0
        public NotProposition(IProposition prop)
        {
            if (null == prop)
            {
                throw new IllegalArgumentException("Proposition to be negated must be specified.");
            }
            // Track nested scope
            addScope(prop.getScope());
            addUnboundScope(prop.getUnboundScope());

            proposition = prop;
        }
Beispiel #15
0
        //
        // START-ProbabilityModel
        public virtual bool isValid()
        {
            // Handle rounding
            int counter = 0;

            IProposition[] propositionArray = new IProposition[representation.Size()];
            foreach (IProposition prop in representation)
            {
                propositionArray[counter] = prop;
                ++counter;
            }
            return(System.Math.Abs(1 - prior(propositionArray)) <= ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
        }
Beispiel #16
0
        public virtual double posterior(IProposition phi, params IProposition[] evidence)
        {
            IProposition conjEvidence = ProbUtil.constructConjunction(evidence);

            // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
            IProposition aAndB = new ConjunctiveProposition(phi, conjEvidence);
            double       probabilityOfEvidence = prior(conjEvidence);

            if (0 != probabilityOfEvidence)
            {
                return(prior(aAndB) / probabilityOfEvidence);
            }

            return(0);
        }
        public double posterior(IProposition phi, params IProposition[] evidence)
        {

            IProposition conjEvidence = ProbUtil.constructConjunction(evidence);

            // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
            IProposition aAndB = new ConjunctiveProposition(phi, conjEvidence);
            double probabilityOfEvidence = prior(conjEvidence);
            if (0 != probabilityOfEvidence)
            {
                return prior(aAndB)/probabilityOfEvidence;
            }

            return 0;
        }
Beispiel #18
0
        // END-FiniteProbabilityModel
        //

        //
        // PRIVATE METHODS
        //
        private double probabilityOf(IProposition phi)
        {
            double[] probSum = new double[1];
            //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
            //    public void iterate(Map<RandomVariable, Object> possibleWorld,
            //            double probability) {
            //        if (phi.holds(possibleWorld)) {
            //            probSum[0] += probability;
            //        }
            //    }
            //};

            //distribution.iterateOverTable(di);
            // TODO
            return(probSum[0]);
        }
Beispiel #19
0
        public CategoricalDistribution jointDistribution(
            params IProposition[] propositions)
        {
            ProbabilityTable d        = null;
            IProposition     conjProp = ProbUtil
                                        .constructConjunction(propositions);
            LinkedHashSet <RandomVariable> vars = new LinkedHashSet <RandomVariable>(
                conjProp.getUnboundScope());

            if (vars.Count > 0)
            {
                RandomVariable[] distVars = new RandomVariable[vars.Count];
                vars.CopyTo(distVars);

                ProbabilityTable ud     = new ProbabilityTable(distVars);
                Object[]         values = new Object[vars.Count];

                //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {

                //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                //            double probability) {
                //        if (conjProp.holds(possibleWorld)) {
                //            int i = 0;
                //            for (RandomVariable rv : vars) {
                //                values[i] = possibleWorld.get(rv);
                //                i++;
                //            }
                //            int dIdx = ud.getIndex(values);
                //            ud.setValue(dIdx, ud.getValues()[dIdx] + probability);
                //        }
                //    }
                //};

                //distribution.iterateOverTable(di);
                // TODO:
                d = ud;
            }
            else
            {
                // No Unbound Variables, therefore just return
                // the singular probability related to the proposition.
                d = new ProbabilityTable();
                d.setValue(0, prior(propositions));
            }
            return(d);
        }
Beispiel #20
0
        /// <summary>
        /// Gets the best (lowest cost) relevant action node satisfying the given proposition during the FF evaluation.
        /// </summary>
        /// <param name="proposition">Proposition to satisfy.</param>
        /// <param name="actionLayer">Action layer.</param>
        /// <returns>Best relevant action node.</returns>
        private static ActionNode GetBestRelevantActionNodeFF(IProposition proposition, ActionLayer actionLayer)
        {
            ActionNode bestActionNode = null;

            foreach (var actionNode in actionLayer)
            {
                if (actionNode.Successors.Contains(proposition))
                {
                    if (bestActionNode == null || actionNode.Operator.GetCost() < bestActionNode.Operator.GetCost())
                    {
                        bestActionNode = actionNode;
                    }
                }
            }

            return(bestActionNode);
        }
Beispiel #21
0
        public virtual double prior(params IProposition[] phi)
        {
            // Calculating the prior, therefore no relevant evidence
            // just query over the scope of proposition phi in order
            // to get a joint distribution for these
            IProposition conjunct = ProbUtil.constructConjunction(phi);

            IRandomVariable[]        X = conjunct.getScope().ToArray();
            ICategoricalDistribution d = bayesInference.Ask(X, new AssignmentProposition[0], bayesNet);

            // Then calculate the probability of the propositions phi
            // be seeing where they hold.
            double[] probSum = new double[1];
            CategoricalDistributionIterator di = new CategoricalDistributionIteraorPrior(conjunct, probSum);

            d.iterateOver(di);

            return(probSum[0]);
        }
Beispiel #22
0
        public DisjunctiveProposition(IProposition left, IProposition right)
        {
            if (null == left)
            {
                throw new IllegalArgumentException("Left side of disjunction must be specified.");
            }
            if (null == right)
            {
                throw new IllegalArgumentException("Right side of disjunction must be specified.");
            }
            // Track nested scope
            addScope(left.getScope());
            addScope(right.getScope());
            addUnboundScope(left.getUnboundScope());
            addUnboundScope(right.getUnboundScope());

            this.left  = left;
            this.right = right;
        }
Beispiel #23
0
        public ICategoricalDistribution forward(ICategoricalDistribution f1_t, ICollection <AssignmentProposition> e_tp1)
        {
            ICategoricalDistribution s1 = new ProbabilityTable(f1_t.getFor());

            // Set up required working variables
            IProposition[] props = new IProposition[s1.getFor().Size()];
            int            i     = 0;

            foreach (IRandomVariable rv in s1.getFor())
            {
                props[i] = new RandVar(rv.getName(), rv.getDomain());
                ++i;
            }
            IProposition Xtp1 = ProbUtil.constructConjunction(props);

            AssignmentProposition[] xt = new AssignmentProposition[tToTm1StateVarMap.Size()];
            IMap <IRandomVariable, AssignmentProposition> xtVarAssignMap = CollectionFactory.CreateInsertionOrderedMap <IRandomVariable, AssignmentProposition>();

            i = 0;
            foreach (IRandomVariable rv in tToTm1StateVarMap.GetKeys())
            {
                xt[i] = new AssignmentProposition(tToTm1StateVarMap.Get(rv), "<Dummy Value>");
                xtVarAssignMap.Put(rv, xt[i]);
                ++i;
            }

            // Step 1: Calculate the 1 time step prediction
            // &sum;<sub>x<sub>t</sub></sub>
            CategoricalDistributionIterator if1_t = new CategoricalDistributionIteratorImpl(transitionModel,
                                                                                            xtVarAssignMap, s1, Xtp1, xt);

            f1_t.iterateOver(if1_t);

            // Step 2: multiply by the probability of the evidence
            // and normalize
            // <b>P</b>(e<sub>t+1</sub> | X<sub>t+1</sub>)
            ICategoricalDistribution s2 = sensorModel.posteriorDistribution(ProbUtil
                                                                            .constructConjunction(e_tp1.ToArray()), Xtp1);

            return(s2.multiplyBy(s1).normalize());
        }
        public ConjunctiveProposition(IProposition left, IProposition right)
        {
            if (null == left)
            {
                throw new IllegalArgumentException(
                    "Left side of conjunction must be specified.");
            }
            if (null == right)
            {
                throw new IllegalArgumentException(
                    "Right side of conjunction must be specified.");
            }
            // Track nested scope
            addScope(left.getScope());
            addScope(right.getScope());
            addUnboundScope(left.getUnboundScope());
            addUnboundScope(right.getUnboundScope());

            this.left = left;
            this.right = right;
        }
Beispiel #25
0
        public ICategoricalDistribution backward(ICategoricalDistribution b_kp2t, ICollection <AssignmentProposition> e_kp1)
        {
            ICategoricalDistribution b_kp1t = new ProbabilityTable(b_kp2t.getFor());

            // Set up required working variables
            IProposition[] props = new IProposition[b_kp1t.getFor().Size()];
            int            i     = 0;

            foreach (IRandomVariable rv in b_kp1t.getFor())
            {
                IRandomVariable prv = tToTm1StateVarMap.Get(rv);
                props[i] = new RandVar(prv.getName(), prv.getDomain());
                ++i;
            }
            IProposition Xk = ProbUtil.constructConjunction(props);

            AssignmentProposition[] ax_kp1 = new AssignmentProposition[tToTm1StateVarMap.Size()];
            IMap <IRandomVariable, AssignmentProposition> x_kp1VarAssignMap = CollectionFactory.CreateInsertionOrderedMap <IRandomVariable, AssignmentProposition>();

            i = 0;
            foreach (IRandomVariable rv in b_kp1t.getFor())
            {
                ax_kp1[i] = new AssignmentProposition(rv, "<Dummy Value>");
                x_kp1VarAssignMap.Put(rv, ax_kp1[i]);
                ++i;
            }
            IProposition x_kp1 = ProbUtil.constructConjunction(ax_kp1);

            props = e_kp1.ToArray();
            IProposition pe_kp1 = ProbUtil.constructConjunction(props);

            // &sum;<sub>x<sub>k+1</sub></sub>
            CategoricalDistributionIterator ib_kp2t = new CategoricalDistributionIteratorImpl2(x_kp1VarAssignMap,
                                                                                               sensorModel, transitionModel, b_kp1t, pe_kp1, Xk, x_kp1);

            b_kp2t.iterateOver(ib_kp2t);

            return(b_kp1t);
        }
 public SemanticTableux(IProposition ip, int _curNode, List <IProposition> toDraw)
 {
     isClosedNode             = false;
     graphviz                 = "";
     displayThisNode          = new List <string>();
     currentNode              = _curNode;
     toBeProcessedProposition = ip;
     leftProducts             = new List <IProposition>();
     rightProducts            = new List <IProposition>();
     nextNodes.Add(this);
     isSplit = isSplitOrNot();
     displayThisNode.Add(toBeProcessedProposition.GetString());
     if (toDraw != null)
     {
         foreach (IProposition pp in toDraw)
         {
             displayThisNode.Add(pp.GetString());
         }
     }
     DrawThisNode();
     DrawGraph();
 }
Beispiel #27
0
        /**
	 * Unlike unconditional or prior probabilities, most of the time we have
	 * some information, usually called evidence, that has already been
	 * revealed. This is the conditional or posterior probability (or just
	 * "posterior" for short). Mathematically speaking, conditional
	 * probabilities are defined in terms of unconditional probabilities as
	 * follows, for any propositions a and b, we have:<br>
	 * <br>
	 * P(a | b) = P(a AND b)/P(b)<br>
	 * <br>
	 * which holds whenever P(b) > 0. Refer to equation 13.3 page 485 of AIMA3e.
	 * This can be rewritten in a different form called the <b>product rule</b>: <br>
	 * <br>
	 * P(a AND b) = P(a | b)P(b)<br>
	 * <br>
	 * and also as:<br>
	 * <br>
	 * P(a AND b) = P(b | a)P(a)<br>
	 * <br>
	 * whereby, equating the two right-hand sides and dividing by P(a) gives you
	 * Bayes' rule:<br>
	 * <br>
	 * P(b | a) = (P(a | b)P(b))/P(a) - i.e. (likelihood * prior)/evidence
	 * 
	 * @param phi
	 *            the proposition for which a probability value is to be
	 *            returned.
	 * @param evidence
	 *            information we already have.
	 * @return the probability of the proposition &phi; given evidence.
	 */
        protected abstract double posterior(IProposition phi, params IProposition[] evidence);
Beispiel #28
0
 /**
  * Unlike unconditional or prior probabilities, most of the time we have
  * some information, usually called evidence, that has already been
  * revealed. This is the conditional or posterior probability (or just
  * "posterior" for short). Mathematically speaking, conditional
  * probabilities are defined in terms of unconditional probabilities as
  * follows, for any propositions a and b, we have:<br>
  * <br>
  * P(a | b) = P(a AND b)/P(b)<br>
  * <br>
  * which holds whenever P(b) > 0. Refer to equation 13.3 page 485 of AIMA3e.
  * This can be rewritten in a different form called the <b>product rule</b>: <br>
  * <br>
  * P(a AND b) = P(a | b)P(b)<br>
  * <br>
  * and also as:<br>
  * <br>
  * P(a AND b) = P(b | a)P(a)<br>
  * <br>
  * whereby, equating the two right-hand sides and dividing by P(a) gives you
  * Bayes' rule:<br>
  * <br>
  * P(b | a) = (P(a | b)P(b))/P(a) - i.e. (likelihood * prior)/evidence
  *
  * @param phi
  *            the proposition for which a probability value is to be
  *            returned.
  * @param evidence
  *            information we already have.
  * @return the probability of the proposition &phi; given evidence.
  */
 protected abstract double posterior(IProposition phi, params IProposition[] evidence);
Beispiel #29
0
 public AndProposition(IProposition f, IProposition g)
 {
     this.f = f;
     this.g = g;
 }
Beispiel #30
0
        /**
         * Get a conditional distribution. Example:<br>
         * <br>
         * <b>P</b>(X | Y) gives the values of P(X = x<sub>i</sub> | Y =
         * y<sub>j</sub>) for each possible i, j pair.
         *
         * @param phi
         *            the proposition for which a probability distribution is to be
         *            returned.
         * @param evidence
         *            information we already have.
         * @return the conditional distribution for <b>P</b>(&phi; | evidence).
         */

        private CategoricalDistribution posteriorDistribution(IProposition phi,
                                                              params IProposition[] evidence);
Beispiel #31
0
        //
        // PRIVATE METHODS
        //

        private static IProposition constructConjunction(IProposition[] props, int idx)
        {
            if ((idx + 1) == props.Length)
            {
                return props[idx];
            }

            return new ConjunctiveProposition(props[idx], constructConjunction(
                props, idx + 1));
        }
Beispiel #32
0
        /**
         * Convenience method for ensure a conjunction of probabilistic
         * propositions.
         * 
         * @param props
         *            propositions to be combined into a ConjunctiveProposition if
         *            necessary.
         * @return a ConjunctivePropositions if more than 1 proposition in 'props',
         *         otherwise props[0].
         */

        public static IProposition constructConjunction(IProposition[] props)
        {
            return constructConjunction(props, 0);
        }
Beispiel #33
0
 public ExistsUntilProposition(int numStates, IProposition f, IProposition g)
 {
     this.f      = f;
     this.g      = g;
     this.values = new bool[numStates];
 }
        /**
         * Get a conditional distribution. Example:<br>
         * <br>
         * <b>P</b>(X | Y) gives the values of P(X = x<sub>i</sub> | Y =
         * y<sub>j</sub>) for each possible i, j pair.
         * 
         * @param phi
         *            the proposition for which a probability distribution is to be
         *            returned.
         * @param evidence
         *            information we already have.
         * @return the conditional distribution for <b>P</b>(&phi; | evidence).
         */

        private CategoricalDistribution posteriorDistribution(IProposition phi,
                                                              params IProposition[] evidence);
        public bool isSplitOrNot()
        {
            IProposition        propositionOfNotClass  = toBeProcessedProposition.getChildProposition()[0];
            List <IProposition> childPropositionsOfNot = propositionOfNotClass.getChildProposition();

            if (toBeProcessedProposition is NotClass)
            {
                if (propositionOfNotClass is ImplicationClass || propositionOfNotClass is OrClass)
                {
                    if (propositionOfNotClass is ImplicationClass)
                    {
                        leftProducts.Add(childPropositionsOfNot[0]);
                        rightProducts.Add(new NotClass(childPropositionsOfNot[1]));
                    }
                    else
                    {
                        leftProducts.Add(new NotClass(childPropositionsOfNot[0]));
                        rightProducts.Add(new NotClass(childPropositionsOfNot[1]));
                    }
                    ruleOfNode = Rule.Alpha;
                    return(false);
                }
                else if (propositionOfNotClass is NotClass)
                {
                    ruleOfNode = Rule.Alpha;
                    leftProducts.Add(childPropositionsOfNot[0]);
                    return(false);
                }
                else if (propositionOfNotClass is FinalVar)
                {
                    return(false);
                }
                else //andClass
                {
                    ruleOfNode = Rule.Beta;
                    leftProducts.Add(new NotClass(childPropositionsOfNot[0]));
                    rightProducts.Add(new NotClass(childPropositionsOfNot[1]));
                    return(true);
                }
            }
            else
            {
                if (toBeProcessedProposition is AndClass)
                {
                    ruleOfNode = Rule.Alpha;
                    leftProducts.Add(childPropositionsOfNot[0]);
                    rightProducts.Add(childPropositionsOfNot[1]);
                    return(false);
                }
                else if (propositionOfNotClass is FinalVar)
                {
                    return(false);
                }
                else //Orclass
                {
                    ruleOfNode = Rule.Beta;
                    leftProducts.Add(childPropositionsOfNot[0]);
                    rightProducts.Add(childPropositionsOfNot[1]);
                    return(true);
                }
            }
        }
        // END-FiniteProbabilityModel
        //

        //
        // PRIVATE METHODS
        //
        private double probabilityOf(IProposition phi)
        {
            double[] probSum = new double[1];
            //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
            //    public void iterate(Map<RandomVariable, Object> possibleWorld,
            //            double probability) {
            //        if (phi.holds(possibleWorld)) {
            //            probSum[0] += probability;
            //        }
            //    }
            //};

            //distribution.iterateOverTable(di);
            // TODO
            return probSum[0];
        }
Beispiel #37
0
 /// <summary>
 /// Checks whether the state layer has the specified proposition.
 /// </summary>
 /// <param name="proposition">Proposition.</param>
 /// <returns>True if the state layer has the given proposition, false otherwise.</returns>
 public bool HasProposition(IProposition proposition)
 {
     return(State.HasPredicate(((Proposition)proposition).Atom));
 }
Beispiel #38
0
 /// <summary>
 /// Checks whether the state layer has the specified proposition.
 /// </summary>
 /// <param name="proposition">Proposition.</param>
 /// <returns>True if the state layer has the given proposition, false otherwise.</returns>
 public bool HasProposition(IProposition proposition)
 {
     return(State.HasValue(((Proposition)proposition).Assignment));
 }
Beispiel #39
0
 private static int GetGoalValue(IProposition goalProposition)
 {
     Fact relation = goalProposition.Name;
     Term constant = relation.GetTerm(1);
     return int.Parse(constant.ToString());
 }