Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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 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);
        }