/** * A <tt>path</tt> between <tt>x1</tt> and <tt>x2</tt> is d-connecting given <tt>evidence</tt> if * every interior node <tt>n</tt> in the path has the property that either * * <ol> * <li><tt>n</tt> is linear or diverging and <tt>n</tt> is not in <tt>evidence</tt>, or * <li><tt>n</tt> is converging, and either <tt>n</tt> or some descendent of <tt>n</tt> is in * <tt>evidence</tt>. * </ol> */ public static boolean is_d_connecting(AbstractVariable[] path, Vector evidence) throws RemoteException { for (int i = 1; i < path.length - 1; i++) { if (is_converging(path[i - 1], path[i], path[i + 1])) { // System.err.println( "PathAnalysis.is_d_connecting: "+path[i].get_name()+" is converging." // ); if (!evidence.contains(path[i]) && !contains_descendent(evidence, path[i])) return false; } else { // System.err.println( "PathAnalysis.is_d_connecting: "+path[i].get_name()+" is linear or // diverging." ); if (evidence.contains(path[i])) return false; } } return true; }
public static boolean contains_descendent(Vector evidence, AbstractVariable a) throws RemoteException { AbstractVariable[] children = a.get_children(); if (children == null) return false; for (int i = 0; i < children.length; i++) { if (evidence.contains(children[i])) return true; else if (contains_descendent(evidence, children[i])) return true; } return false; }