Пример #1
0
  private void backwardsConditioning(List<Node> pc, Node target) {
    for (Node x : new LinkedList<>(pc)) {
      List<Node> _pc = new LinkedList<>(pc);
      _pc.remove(x);
      _pc.remove(target);

      List<Node> minAssoc = minAssoc(x, target, _pc);

      numIndTests++;

      if (independenceTest.isIndependent(x, target, minAssoc)) {
        pc.remove(x);
      }
    }
  }
Пример #2
0
  private List<Node> mmpc(Node t) {
    List<Node> pc = new LinkedList<>();
    boolean pcIncreased = true;

    // First optimization: Don't consider adding again variables that have
    // already been found independent of t.
    List<Node> indepOfT = new LinkedList<>();

    // Phase 1
    while (pcIncreased) {
      pcIncreased = false;

      MaxMinAssocResult ret = maxMinAssoc(t, pc, indepOfT);
      Node f = ret.getNode();
      List<Node> assocSet = ret.getAssocSet();

      if (f == null) {
        break;
      }

      numIndTests++;

      if (!independenceTest.isIndependent(f, t, assocSet)) {
        pcIncreased = true;
        pc.add(f);
      }
    }

    // Phase 2.
    backwardsConditioning(pc, t);

    TetradLogger.getInstance().log("details", "PC(" + t + ") = " + pc);
    //        System.out.println("PC(" + t + ") = " + pc);

    return pc;
  }
Пример #3
0
  private double association(Node x, Node target, List<Node> s) {
    numIndTests++;

    independenceTest.isIndependent(x, target, s);
    return 1.0 - independenceTest.getPValue();
  }
Пример #4
0
  private List<Node> mmmb(Node t) {
    // MB <- {}
    Set<Node> mb = new HashSet<>();

    Set<Node> _pcpc = new HashSet<>();

    for (Node node : getPc(t)) {
      List<Node> f = getPc(node);
      this.pc.put(node, f);
      _pcpc.addAll(f);
    }

    List<Node> pcpc = new LinkedList<>(_pcpc);

    Set<Node> currentMb = new HashSet<>(getPc(t));
    currentMb.addAll(pcpc);
    currentMb.remove(t);

    HashSet<Node> diff = new HashSet<>(currentMb);
    diff.removeAll(getPc(t));
    diff.remove(t);

    // for each x in PCPC \ PC
    for (Node x : diff) {
      List<Node> s = null;

      // Find an S such PC such that x _||_ t | S
      DepthChoiceGenerator generator = new DepthChoiceGenerator(pcpc.size(), depth);
      int[] choice;

      while ((choice = generator.next()) != null) {
        List<Node> _s = new LinkedList<>();

        for (int index : choice) {
          _s.add(pcpc.get(index));
        }

        numIndTests++;
        if (independenceTest.isIndependent(t, x, _s)) {
          s = _s;
          break;
        }
      }

      if (s == null) {
        System.out.println("S not found.");
        //                mb.add(x);
        continue;
      }

      // y_set <- {y in PC(t) : x in PC(y)}
      Set<Node> ySet = new HashSet<>();
      for (Node y : getPc(t)) {
        if (this.pc.get(y).contains(x)) {
          ySet.add(y);
        }
      }

      //  For each y in y_set
      for (Node y : ySet) {
        if (x == y) continue;

        List<Node> _s = new LinkedList<>(s);
        _s.add(y);

        // If x NOT _||_ t | S U {y}
        numIndTests++;
        if (!independenceTest.isIndependent(t, x, _s)) {
          mb.add(x);
          break;
        }
      }
    }

    mb.addAll(getPc(t));
    return new LinkedList<>(mb);
  }