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; }
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); }
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; }
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; }
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); }