Exemplo n.º 1
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]);
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
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);
        }