Search in sources :

Example 91 with ChoiceGenerator

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

the class Purify method countCrossConstructPValues.

private List<Double> countCrossConstructPValues(List<int[]> partition, boolean[] eliminated, double cutoff) {
    List<Double> allPValues = new ArrayList<>();
    for (int p1 = 0; p1 < partition.size(); p1++) {
        for (int p2 = p1 + 1; p2 < partition.size(); p2++) {
            int[] cluster1 = partition.get(p1);
            int[] cluster2 = partition.get(p2);
            if (cluster1.length >= 3 && cluster2.length >= 1) {
                ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.length, 3);
                ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.length, 1);
                int[] choice1, choice2;
                while ((choice1 = gen1.next()) != null) {
                    while ((choice2 = gen2.next()) != null) {
                        List<Integer> crossCluster = new ArrayList<>();
                        for (int i : choice1) crossCluster.add(cluster1[i]);
                        for (int i : choice2) crossCluster.add(cluster2[i]);
                        allPValues.addAll(listPValues(crossCluster, eliminated, cutoff));
                    }
                }
            }
            if (cluster1.length >= 2 && cluster2.length >= 2) {
                ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.length, 2);
                ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.length, 2);
                int[] choice1, choice2;
                while ((choice1 = gen1.next()) != null) {
                    while ((choice2 = gen2.next()) != null) {
                        List<Integer> crossCluster = new ArrayList<>();
                        for (int i : choice1) crossCluster.add(cluster1[i]);
                        for (int i : choice2) crossCluster.add(cluster2[i]);
                        allPValues.addAll(listPValues(crossCluster, eliminated, cutoff));
                    }
                }
            }
        }
    }
    return allPValues;
}
Also used : ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Example 92 with ChoiceGenerator

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

the class PurifySextadBased method listCrossConstructSextads.

private Set<IntSextad> listCrossConstructSextads(List<List<Integer>> clustering, Set<Integer> eliminated, double cutoff) {
    Set<IntSextad> allSextads = new HashSet<>();
    boolean countable = false;
    for (int p1 = 0; p1 < clustering.size(); p1++) {
        for (int p2 = p1 + 1; p2 < clustering.size(); p2++) {
            List<Integer> cluster1 = clustering.get(p1);
            List<Integer> cluster2 = clustering.get(p2);
            if (cluster1.size() >= 5 && cluster2.size() >= 1) {
                ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 5);
                int[] choice1;
                while ((choice1 = gen1.next()) != null) {
                    ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 1);
                    int[] choice2;
                    while ((choice2 = gen2.next()) != null) {
                        List<Integer> crossCluster = new ArrayList<>();
                        for (int i : choice1) crossCluster.add(cluster1.get(i));
                        for (int i : choice2) crossCluster.add(cluster2.get(i));
                        Set<IntSextad> Sextads = listSextads(crossCluster, eliminated, cutoff);
                        if (Sextads != null) {
                            countable = true;
                            allSextads.addAll(Sextads);
                        }
                    }
                }
            }
            if (cluster2.size() >= 5 && cluster1.size() >= 1) {
                ChoiceGenerator gen1 = new ChoiceGenerator(cluster2.size(), 5);
                int[] choice1;
                while ((choice1 = gen1.next()) != null) {
                    ChoiceGenerator gen2 = new ChoiceGenerator(cluster1.size(), 1);
                    int[] choice2;
                    while ((choice2 = gen2.next()) != null) {
                        List<Integer> crossCluster = new ArrayList<>();
                        for (int i : choice1) crossCluster.add(cluster2.get(i));
                        for (int i : choice2) crossCluster.add(cluster1.get(i));
                        Set<IntSextad> Sextads = listSextads(crossCluster, eliminated, cutoff);
                        if (Sextads != null) {
                            countable = true;
                            allSextads.addAll(Sextads);
                        }
                    }
                }
            }
        // if (cluster1.size() >= 2 && cluster2.size() >= 2) {
        // ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 2);
        // int[] choice1;
        // 
        // while ((choice1 = gen1.next()) != null) {
        // ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 2);
        // int[] choice2;
        // 
        // while ((choice2 = gen2.next()) != null) {
        // List<Integer> crossCluster = new ArrayList<Integer>();
        // for (int i : choice1) crossCluster.add(cluster1.get(i));
        // for (int i : choice2) crossCluster.add(cluster2.get(i));
        // 
        // Set<IntSextad> Sextads = listSextads2By2(crossCluster, eliminated, cutoff);
        // 
        // if (Sextads != null) {
        // countable = true;
        // allSextads.addAll(Sextads);
        // }
        // }
        // }
        // }
        }
    }
    return countable ? allSextads : null;
}
Also used : ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Example 93 with ChoiceGenerator

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

the class PurifySextadBased method listSextads.

private Set<IntSextad> listSextads(List<Integer> cluster, Set<Integer> eliminated, double cutoff) {
    if (cluster.size() < 6)
        return null;
    cluster = new ArrayList<>(cluster);
    boolean countable = false;
    Set<IntSextad> Sextads = new HashSet<>();
    ChoiceGenerator gen = new ChoiceGenerator(cluster.size(), 6);
    int[] choice;
    while ((choice = gen.next()) != null) {
        int _i = choice[0];
        int _j = choice[1];
        int _k = choice[2];
        int _l = choice[3];
        int _m = choice[4];
        int _n = choice[5];
        int m1 = cluster.get(_i);
        int m2 = cluster.get(_j);
        int m3 = cluster.get(_k);
        int m4 = cluster.get(_l);
        int m5 = cluster.get(_m);
        int m6 = cluster.get(_n);
        if (eliminated.contains(m1) || eliminated.contains(m2) || eliminated.contains(m3) || eliminated.contains(m4) || eliminated.contains(m5) || eliminated.contains(m6)) {
            continue;
        }
        countable = true;
        double p1, p2, p3, p4, p5, p6, p7, p8, p9, p10;
        IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6);
        IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6);
        IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6);
        IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5);
        IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6);
        IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6);
        IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5);
        IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6);
        IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5);
        IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4);
        p1 = sextadTest.getPValue(t1);
        p2 = sextadTest.getPValue(t2);
        p3 = sextadTest.getPValue(t3);
        p4 = sextadTest.getPValue(t4);
        p5 = sextadTest.getPValue(t5);
        p6 = sextadTest.getPValue(t6);
        p7 = sextadTest.getPValue(t7);
        p8 = sextadTest.getPValue(t8);
        p9 = sextadTest.getPValue(t9);
        p10 = sextadTest.getPValue(t10);
        if (p1 < cutoff) {
            Sextads.add(t1);
        }
        if (p2 < cutoff) {
            Sextads.add(t2);
        }
        if (p3 < cutoff) {
            Sextads.add(t3);
        }
        if (p4 < cutoff) {
            Sextads.add(t4);
        }
        if (p5 < cutoff) {
            Sextads.add(t5);
        }
        if (p6 < cutoff) {
            Sextads.add(t6);
        }
        if (p7 < cutoff) {
            Sextads.add(t7);
        }
        if (p8 < cutoff) {
            Sextads.add(t8);
        }
        if (p9 < cutoff) {
            Sextads.add(t9);
        }
        if (p10 < cutoff) {
            Sextads.add(t10);
        }
    }
    return countable ? Sextads : null;
}
Also used : ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Example 94 with ChoiceGenerator

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

the class PurifyTetradBased2 method listCrossConstructTetrads.

private Set<Tetrad> listCrossConstructTetrads(List<List<Node>> clustering, Set<Node> eliminated, double cutoff) {
    Set<Tetrad> allTetrads = new HashSet<>();
    boolean countable = false;
    for (int p1 = 0; p1 < clustering.size(); p1++) {
        for (int p2 = p1 + 1; p2 < clustering.size(); p2++) {
            List<Node> cluster1 = clustering.get(p1);
            List<Node> cluster2 = clustering.get(p2);
            if (cluster1.size() >= 3 && cluster2.size() >= 1) {
                ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 3);
                int[] choice1;
                while ((choice1 = gen1.next()) != null) {
                    ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 1);
                    int[] choice2;
                    while ((choice2 = gen2.next()) != null) {
                        List<Node> crossCluster = new ArrayList<>();
                        for (int i : choice1) crossCluster.add(cluster1.get(i));
                        for (int i : choice2) crossCluster.add(cluster2.get(i));
                        Set<Tetrad> tetrads = listTetrads(crossCluster, eliminated, cutoff);
                        if (tetrads != null) {
                            countable = true;
                            allTetrads.addAll(tetrads);
                        }
                    }
                }
            }
            if (cluster2.size() >= 3 && cluster1.size() >= 1) {
                ChoiceGenerator gen1 = new ChoiceGenerator(cluster2.size(), 3);
                int[] choice1;
                while ((choice1 = gen1.next()) != null) {
                    ChoiceGenerator gen2 = new ChoiceGenerator(cluster1.size(), 1);
                    int[] choice2;
                    while ((choice2 = gen2.next()) != null) {
                        List<Node> crossCluster = new ArrayList<>();
                        for (int i : choice1) crossCluster.add(cluster2.get(i));
                        for (int i : choice2) crossCluster.add(cluster1.get(i));
                        Set<Tetrad> tetrads = listTetrads(crossCluster, eliminated, cutoff);
                        if (tetrads != null) {
                            countable = true;
                            allTetrads.addAll(tetrads);
                        }
                    }
                }
            }
            if (cluster1.size() >= 2 && cluster2.size() >= 2) {
                ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 2);
                int[] choice1;
                while ((choice1 = gen1.next()) != null) {
                    ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 2);
                    int[] choice2;
                    while ((choice2 = gen2.next()) != null) {
                        List<Node> crossCluster = new ArrayList<>();
                        for (int i : choice1) crossCluster.add(cluster1.get(i));
                        for (int i : choice2) crossCluster.add(cluster2.get(i));
                        Set<Tetrad> tetrads = listTetrads2By2(crossCluster, eliminated, cutoff);
                        if (tetrads != null) {
                            countable = true;
                            allTetrads.addAll(tetrads);
                        }
                    }
                }
            }
        }
    }
    return countable ? allTetrads : null;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator)

Example 95 with ChoiceGenerator

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

the class Rfci method getRTuples.

// //////////////////////////////////////////////
// collect in rTupleList all unshielded tuples
// //////////////////////////////////////////////
private List<Node[]> getRTuples() {
    List<Node[]> rTuples = new ArrayList<>();
    List<Node> nodes = graph.getNodes();
    for (Node j : nodes) {
        List<Node> adjacentNodes = graph.getAdjacentNodes(j);
        if (adjacentNodes.size() < 2) {
            continue;
        }
        ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2);
        int[] combination;
        while ((combination = cg.next()) != null) {
            if (Thread.currentThread().isInterrupted()) {
                break;
            }
            Node i = adjacentNodes.get(combination[0]);
            Node k = adjacentNodes.get(combination[1]);
            // Skip triples that are shielded.
            if (!graph.isAdjacentTo(i, k)) {
                Node[] newTuple = { i, j, k };
                rTuples.add(newTuple);
            }
        }
    }
    return (rTuples);
}
Also used : 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