Пример #1
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);
        }
Пример #2
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;
        }
Пример #3
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;
        }
Пример #4
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]);
        }
Пример #5
0
        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;
        }