Search in sources :

Example 31 with ChoiceGenerator

use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.

the class SepsetsConservativeMajority method getSepset.

/**
 * Pick out the sepset from among adj(i) or adj(k) with the highest p value.
 */
public List<Node> getSepset(Node i, Node k) {
    double _p = 0.0;
    List<Node> _v = null;
    if (extraSepsets != null) {
        final List<Node> possibleDsep = extraSepsets.get(i, k);
        if (possibleDsep != null) {
            independenceTest.isIndependent(i, k, possibleDsep);
            _p = independenceTest.getPValue();
            _v = possibleDsep;
        }
    }
    List<Node> adji = graph.getAdjacentNodes(i);
    List<Node> adjk = graph.getAdjacentNodes(k);
    adji.remove(k);
    adjk.remove(i);
    for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
        if (d <= adji.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adji);
                if (getIndependenceTest().isIndependent(i, k, v)) {
                    double pValue = getIndependenceTest().getPValue();
                    if (pValue > _p) {
                        _p = pValue;
                        _v = v;
                    }
                }
            }
        }
        if (d <= adjk.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adjk);
                if (getIndependenceTest().isIndependent(i, k, v)) {
                    double pValue = getIndependenceTest().getPValue();
                    if (pValue > _p) {
                        _p = pValue;
                        _v = v;
                    }
                }
            }
        }
    }
    return _v;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Example 32 with ChoiceGenerator

use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.

the class SepsetsMaxPValue method getMaxSepset.

private List<Node> getMaxSepset(Node i, Node k) {
    double _p = 0.0;
    List<Node> _v = null;
    if (extraSepsets != null) {
        final List<Node> sepset = extraSepsets.get(i, k);
        if (sepset != null) {
            independenceTest.isIndependent(i, k, sepset);
            double p = independenceTest.getPValue();
            if (p > _p) {
                _p = p;
                _v = sepset;
            }
        }
    }
    List<Node> adji = graph.getAdjacentNodes(i);
    List<Node> adjk = graph.getAdjacentNodes(k);
    adji.remove(k);
    adjk.remove(i);
    for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
        if (d <= adji.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adji);
                getIndependenceTest().isIndependent(i, k, v);
                double p = getIndependenceTest().getPValue();
                if (p > _p) {
                    _p = p;
                    _v = v;
                }
            }
        }
        if (d <= adjk.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adjk);
                getIndependenceTest().isIndependent(i, k, v);
                double p = getIndependenceTest().getPValue();
                if (p > _p) {
                    _p = p;
                    _v = v;
                }
            }
        }
    }
    this.p = _p;
    return _v;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Example 33 with ChoiceGenerator

use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.

the class SepsetsConservative method getSepset.

/**
 * Pick out the sepset from among adj(i) or adj(k) with the highest p value.
 */
public List<Node> getSepset(Node i, Node k) {
    double _p = 0.0;
    List<Node> _v = null;
    if (extraSepsets != null) {
        final List<Node> possibleDsep = extraSepsets.get(i, k);
        if (possibleDsep != null) {
            independenceTest.isIndependent(i, k, possibleDsep);
            _p = independenceTest.getPValue();
            _v = possibleDsep;
        }
    }
    List<Node> adji = graph.getAdjacentNodes(i);
    List<Node> adjk = graph.getAdjacentNodes(k);
    adji.remove(k);
    adjk.remove(i);
    for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
        if (d <= adji.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adji);
                if (getIndependenceTest().isIndependent(i, k, v)) {
                    double pValue = getIndependenceTest().getPValue();
                    if (pValue > _p) {
                        _p = pValue;
                        _v = v;
                    }
                }
            }
        }
        if (d <= adjk.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adjk);
                if (getIndependenceTest().isIndependent(i, k, v)) {
                    double pValue = getIndependenceTest().getPValue();
                    if (pValue > _p) {
                        _p = pValue;
                        _v = v;
                    }
                }
            }
        }
    }
    return _v;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Example 34 with ChoiceGenerator

use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.

the class SepsetsConservative method getSepsetsLists.

// The published version.
public List<List<List<Node>>> getSepsetsLists(Node x, Node y, Node z, IndependenceTest test, int depth, boolean verbose) {
    List<List<Node>> sepsetsContainingY = new ArrayList<>();
    List<List<Node>> sepsetsNotContainingY = new ArrayList<>();
    List<Node> _nodes = graph.getAdjacentNodes(x);
    _nodes.remove(z);
    int _depth = depth;
    if (_depth == -1) {
        _depth = 1000;
    }
    _depth = Math.min(_depth, _nodes.size());
    for (int d = 0; d <= _depth; d++) {
        ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d);
        int[] choice;
        while ((choice = cg.next()) != null) {
            List<Node> cond = GraphUtils.asList(choice, _nodes);
            if (test.isIndependent(x, z, cond)) {
                if (verbose) {
                    System.out.println("Indep: " + x + " _||_ " + z + " | " + cond);
                }
                if (cond.contains(y)) {
                    sepsetsContainingY.add(cond);
                } else {
                    sepsetsNotContainingY.add(cond);
                }
            }
        }
    }
    _nodes = graph.getAdjacentNodes(z);
    _nodes.remove(x);
    _depth = depth;
    if (_depth == -1) {
        _depth = 1000;
    }
    _depth = Math.min(_depth, _nodes.size());
    for (int d = 0; d <= _depth; d++) {
        ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d);
        int[] choice;
        while ((choice = cg.next()) != null) {
            List<Node> cond = GraphUtils.asList(choice, _nodes);
            if (test.isIndependent(x, z, cond)) {
                if (cond.contains(y)) {
                    sepsetsContainingY.add(cond);
                } else {
                    sepsetsNotContainingY.add(cond);
                }
            }
        }
    }
    List<List<List<Node>>> ret = new ArrayList<>();
    ret.add(sepsetsContainingY);
    ret.add(sepsetsNotContainingY);
    return ret;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 35 with ChoiceGenerator

use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.

the class SepsetsMinPValue method getMaxSepset.

private List<Node> getMaxSepset(Node i, Node k) {
    double _p = 0.0;
    List<Node> _v = null;
    if (extraSepsets != null) {
        final List<Node> possibleDsep = extraSepsets.get(i, k);
        if (possibleDsep != null) {
            independenceTest.isIndependent(i, k, possibleDsep);
            double p = independenceTest.getPValue();
            if (p < _p) {
                _p = p;
                _v = possibleDsep;
            }
        }
    }
    List<Node> adji = graph.getAdjacentNodes(i);
    List<Node> adjk = graph.getAdjacentNodes(k);
    adji.remove(k);
    adjk.remove(i);
    for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
        if (d <= adji.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adji);
                getIndependenceTest().isIndependent(i, k, v);
                double p = getIndependenceTest().getPValue();
                if (p < _p) {
                    _p = p;
                    _v = v;
                }
            }
        }
        if (d <= adjk.size()) {
            ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
            int[] choice;
            while ((choice = gen.next()) != null) {
                List<Node> v = GraphUtils.asList(choice, adjk);
                getIndependenceTest().isIndependent(i, k, v);
                double p = getIndependenceTest().getPValue();
                if (p < _p) {
                    _p = p;
                    _v = v;
                }
            }
        }
    }
    this.p = _p;
    return _v;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Aggregations

ChoiceGenerator (edu.cmu.tetrad.util.ChoiceGenerator)161 Node (edu.cmu.tetrad.graph.Node)37 ArrayList (java.util.ArrayList)20 DepthChoiceGenerator (edu.cmu.tetrad.util.DepthChoiceGenerator)15 List (java.util.List)11 LinkedList (java.util.LinkedList)10 ExecutorService (java.util.concurrent.ExecutorService)5 NumberFormat (java.text.NumberFormat)2 HashSet (java.util.HashSet)2 StringTokenizer (java.util.StringTokenizer)2 Test (org.junit.Test)2 DataSet (edu.cmu.tetrad.data.DataSet)1 Triple (edu.cmu.tetrad.graph.Triple)1 DeltaSextadTest (edu.cmu.tetrad.search.DeltaSextadTest)1 IndependenceTest (edu.cmu.tetrad.search.IndependenceTest)1 IntSextad (edu.cmu.tetrad.search.IntSextad)1 SemIm (edu.cmu.tetrad.sem.SemIm)1 IndependenceResult (edu.cmu.tetradapp.model.IndependenceResult)1 Iterator (java.util.Iterator)1 SortedSet (java.util.SortedSet)1