Search in sources :

Example 1 with CombinationGenerator

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

the class TestCombinationGenerator method test2.

@Test
public void test2() {
    CombinationGenerator gen = new CombinationGenerator(new int[] { 2, 1 });
    int count = 0;
    while (gen.next() != null) {
        count++;
    }
    assertEquals(2, count);
}
Also used : CombinationGenerator(edu.cmu.tetrad.util.CombinationGenerator) Test(org.junit.Test)

Example 2 with CombinationGenerator

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

the class TestCombinationGenerator method test3.

@Test
public void test3() {
    CombinationGenerator gen = new CombinationGenerator(new int[] { 2, 3, 4 });
    int count = 0;
    while (gen.next() != null) {
        count++;
    }
    assertEquals(24, count);
}
Also used : CombinationGenerator(edu.cmu.tetrad.util.CombinationGenerator) Test(org.junit.Test)

Example 3 with CombinationGenerator

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

the class Vcpc method search.

/**
 * Runs PC starting with a fully connected graph over all of the variables in the domain of the independence test.
 * See PC for caveats. The number of possible cycles and bidirected edges is far less with CPC than with PC.
 */
// public final Graph search() {
// return search(independenceTest.getVariable());
// }
// //    public Graph search(List<Node> nodes) {
// //
// ////        return search(new FasICov2(getIndependenceTest()), nodes);
// ////        return search(new Fas(getIndependenceTest()), nodes);
// //        return search(new Fas(getIndependenceTest()), nodes);
// }
// modified FAS into VCFAS; added in definitelyNonadjacencies set of edges.
public Graph search() {
    this.logger.log("info", "Starting VCCPC algorithm");
    final IndependenceTest independenceTest = getIndependenceTest();
    this.logger.log("info", "Independence test = " + independenceTest + ".");
    this.allTriples = new HashSet<>();
    this.ambiguousTriples = new HashSet<>();
    this.colliderTriples = new HashSet<>();
    this.noncolliderTriples = new HashSet<>();
    Vcfas fas = new Vcfas(independenceTest);
    definitelyNonadjacencies = new HashSet<>();
    markovInAllPatterns = new HashSet<>();
    // this.logger.log("info", "Variables " + independenceTest.getVariable());
    long startTime = System.currentTimeMillis();
    if (independenceTest == null) {
        throw new NullPointerException();
    }
    List<Node> allNodes = independenceTest.getVariables();
    // if (!allNodes.containsAll(nodes)) {
    // throw new IllegalArgumentException("All of the given nodes must " +
    // "be in the domain of the independence test provided.");
    // }
    // Fas fas = new Fas(graph, getIndependenceTest());
    // FasStableConcurrent fas = new FasStableConcurrent(graph, getIndependenceTest());
    // Fas6 fas = new Fas6(graph, getIndependenceTest());
    // fas = new FasICov(graph, (IndTestFisherZ) getIndependenceTest());
    fas.setKnowledge(getKnowledge());
    fas.setDepth(getDepth());
    fas.setVerbose(verbose);
    // Note that we are ignoring the sepset map returned by this method
    // on purpose; it is not used in this search.
    graph = fas.search();
    apparentlyNonadjacencies = fas.getApparentlyNonadjacencies();
    if (isDoOrientation()) {
        if (verbose) {
            System.out.println("CPC orientation...");
        }
        SearchGraphUtils.pcOrientbk(knowledge, graph, allNodes);
        orientUnshieldedTriples(knowledge, independenceTest, getDepth());
        // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree());
        MeekRules meekRules = new MeekRules();
        meekRules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles);
        meekRules.setKnowledge(knowledge);
        meekRules.orientImplied(graph);
    }
    List<Triple> ambiguousTriples = new ArrayList(graph.getAmbiguousTriples());
    int[] dims = new int[ambiguousTriples.size()];
    for (int i = 0; i < ambiguousTriples.size(); i++) {
        dims[i] = 2;
    }
    // Pattern Search:
    List<Graph> patterns = new ArrayList<>();
    Map<Graph, List<Triple>> newColliders = new IdentityHashMap<>();
    Map<Graph, List<Triple>> newNonColliders = new IdentityHashMap<>();
    // Using combination generator to generate a list of combinations of ambiguous triples dismabiguated into colliders
    // and non-colliders. The combinations are added as graphs to the list patterns. The graphs are then subject to
    // basic rules to ensure consistent patterns.
    CombinationGenerator generator = new CombinationGenerator(dims);
    int[] combination;
    while ((combination = generator.next()) != null) {
        Graph _graph = new EdgeListGraph(graph);
        newColliders.put(_graph, new ArrayList<Triple>());
        newNonColliders.put(_graph, new ArrayList<Triple>());
        for (Graph graph : newColliders.keySet()) {
        // System.out.println("$$$ " + newColliders.get(graph));
        }
        for (int k = 0; k < combination.length; k++) {
            // System.out.println("k = " + combination[k]);
            Triple triple = ambiguousTriples.get(k);
            _graph.removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ());
            if (combination[k] == 0) {
                newColliders.get(_graph).add(triple);
                // System.out.println(newColliders.get(_graph));
                Node x = triple.getX();
                Node y = triple.getY();
                Node z = triple.getZ();
                _graph.setEndpoint(x, y, Endpoint.ARROW);
                _graph.setEndpoint(z, y, Endpoint.ARROW);
            }
            if (combination[k] == 1) {
                newNonColliders.get(_graph).add(triple);
            }
        }
        patterns.add(_graph);
    }
    List<Graph> _patterns = new ArrayList<>(patterns);
    GRAPH: for (Graph graph : new ArrayList<>(patterns)) {
        // _graph = new EdgeListGraph(graph);
        // System.out.println("graph = " + graph + " in keyset? " + newColliders.containsKey(graph));
        // 
        List<Triple> colliders = newColliders.get(graph);
        List<Triple> nonColliders = newNonColliders.get(graph);
        for (Triple triple : colliders) {
            Node x = triple.getX();
            Node y = triple.getY();
            Node z = triple.getZ();
            if (graph.getEdge(x, y).pointsTowards(x) || (graph.getEdge(y, z).pointsTowards(z))) {
                patterns.remove(graph);
                continue GRAPH;
            }
        }
        for (Triple triple : colliders) {
            Node x = triple.getX();
            Node y = triple.getY();
            Node z = triple.getZ();
            graph.setEndpoint(x, y, Endpoint.ARROW);
            graph.setEndpoint(z, y, Endpoint.ARROW);
        }
        for (Triple triple : nonColliders) {
            Node x = triple.getX();
            Node y = triple.getY();
            Node z = triple.getZ();
            if (graph.getEdge(x, y).pointsTowards(y)) {
                graph.removeEdge(y, z);
                graph.addDirectedEdge(y, z);
            }
            if (graph.getEdge(y, z).pointsTowards(y)) {
                graph.removeEdge(x, y);
                graph.addDirectedEdge(y, x);
            }
        }
        for (Edge edge : graph.getEdges()) {
            Node x = edge.getNode1();
            Node y = edge.getNode2();
            if (Edges.isBidirectedEdge(edge)) {
                graph.removeEdge(x, y);
                graph.addUndirectedEdge(x, y);
            }
        }
        // for (Edge edge : graph.getEdges()) {
        // if (Edges.isBidirectedEdge(edge)) {
        // patterns.remove(graph);
        // continue Graph;
        // }
        // }
        MeekRules rules = new MeekRules();
        rules.orientImplied(graph);
        if (graph.existsDirectedCycle()) {
            patterns.remove(graph);
            continue GRAPH;
        }
    }
    MARKOV: for (Edge edge : apparentlyNonadjacencies.keySet()) {
        Node x = edge.getNode1();
        Node y = edge.getNode2();
        for (Graph _graph : new ArrayList<>(patterns)) {
            List<Node> boundaryX = new ArrayList<>(boundary(x, _graph));
            List<Node> boundaryY = new ArrayList<>(boundary(y, _graph));
            List<Node> futureX = new ArrayList<>(future(x, _graph));
            List<Node> futureY = new ArrayList<>(future(y, _graph));
            if (y == x) {
                continue;
            }
            if (boundaryX.contains(y) || boundaryY.contains(x)) {
                continue;
            }
            IndependenceTest test = this.independenceTest;
            if (!futureX.contains(y)) {
                if (!test.isIndependent(x, y, boundaryX)) {
                    continue MARKOV;
                }
            }
            if (!futureY.contains(x)) {
                if (!test.isIndependent(y, x, boundaryY)) {
                    continue MARKOV;
                }
            }
        }
        definitelyNonadjacencies.add(edge);
    // apparentlyNonadjacencies.remove(edge);
    }
    for (Edge edge : definitelyNonadjacencies) {
        if (apparentlyNonadjacencies.keySet().contains(edge)) {
            apparentlyNonadjacencies.keySet().remove(edge);
        }
    }
    // Modified VCPC to be faster but less correct 4/14/15
    // IndependenceTest test = independenceTest;
    // //
    // MARKOV:
    // for (Edge edge : apparentlyNonadjacencies.keySet()) {
    // Node x = edge.getNode1();
    // Node y = edge.getNode2();
    // //        Build Power sets from boundary.
    // powerSet = new HashSet<List<Node>>();
    // Set<Node> ssX = new HashSet<Node>(boundary(x, graph));
    // List<Node> listX = new ArrayList<Node>(ssX);
    // buildPowerSet(listX, listX.size());
    // Set<List<Node>> bdryX = powerSet;
    // powerSet = new HashSet<List<Node>>();
    // Set<Node> ssY = new HashSet<Node>(boundary(y, graph));
    // List<Node> listY = new ArrayList<Node>(ssY);
    // buildPowerSet(listY, listY.size());
    // Set<List<Node>> bdryY = powerSet;
    // for (List<Node> boundaryX : bdryX) {
    // List<Node> futureX = new ArrayList<Node>(future(x, graph));
    // if (y == x) {
    // continue;
    // }
    // if (boundaryX.contains(y)) {
    // continue;
    // }
    // if (!futureX.contains(y)) {
    // if (!test.isIndependent(x, y, boundaryX)) {
    // continue MARKOV;
    // }
    // }
    // }
    // for (List<Node> boundaryY : bdryY) {
    // List<Node> futureX = new ArrayList<Node>(future(x, graph));
    // List<Node> futureY = new ArrayList<Node>(future(y, graph));
    // if (y == x) {
    // continue;
    // }
    // if (boundaryY.contains(x)) {
    // continue;
    // }
    // if (!futureY.contains(x)) {
    // if (!test.isIndependent(y, x, boundaryY)) {
    // continue MARKOV;
    // }
    // }
    // }
    // definitelyNonadjacencies.add(edge);
    // //            apparentlyNonadjacencies.remove(edge);
    // }
    // for (Edge edge : definitelyNonadjacencies) {
    // if (apparentlyNonadjacencies.keySet().contains(edge)) {
    // apparentlyNonadjacencies.keySet().remove(edge);
    // }
    // }
    System.out.println("VCPC:");
    // System.out.println("# of patterns: " + patterns.size());
    long endTime = System.currentTimeMillis();
    this.elapsedTime = endTime - startTime;
    System.out.println("Search Time (seconds):" + (elapsedTime) / 1000 + " s");
    System.out.println("Search Time (milli):" + elapsedTime + " ms");
    System.out.println("# of Apparent Nonadj: " + apparentlyNonadjacencies.size());
    System.out.println("# of Definite Nonadj: " + definitelyNonadjacencies.size());
    // System.out.println("aMIGUOUS tRIPLES: " + ambiguousTriples);
    // System.out.println("Definitely Nonadjacencies:");
    // for (Edge edge : definitelyNonadjacencies) {
    // System.out.println(edge);
    // }
    // System.out.println("markov in all patterns:" + markovInAllPatterns);
    // //        System.out.println("patterns:" + patterns);
    // System.out.println("Apparently Nonadjacencies:");
    // for (Edge edge : apparentlyNonadjacencies.keySet()) {
    // System.out.println(edge);
    // }
    // System.out.println("Definitely Nonadjacencies:");
    // for (Edge edge : definitelyNonadjacencies) {
    // System.out.println(edge);
    // }
    TetradLogger.getInstance().log("apparentlyNonadjacencies", "\n Apparent Non-adjacencies" + apparentlyNonadjacencies);
    TetradLogger.getInstance().log("definitelyNonadjacencies", "\n Definite Non-adjacencies" + definitelyNonadjacencies);
    // TetradLogger.getInstance().log("patterns", "Disambiguated Patterns: " + patterns);
    TetradLogger.getInstance().log("graph", "\nReturning this graph: " + graph);
    TetradLogger.getInstance().log("info", "Elapsed time = " + (elapsedTime) / 1000. + " s");
    TetradLogger.getInstance().log("info", "Finishing CPC algorithm.");
    // logTriples();
    TetradLogger.getInstance().flush();
    // SearchGraphUtils.verifySepsetIntegrity(Map<Edge, List<Node>>, graph);
    return graph;
}
Also used : CombinationGenerator(edu.cmu.tetrad.util.CombinationGenerator)

Example 4 with CombinationGenerator

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

the class VcpcFast method search.

/**
 * Runs PC starting with a fully connected graph over all of the variables in the domain of the independence test.
 * See PC for caveats. The number of possible cycles and bidirected edges is far less with CPC than with PC.
 */
// public final Graph search() {
// return search(independenceTest.getVariable());
// }
// //    public Graph search(List<Node> nodes) {
// //
// ////        return search(new FasICov2(getIndependenceTest()), nodes);
// ////        return search(new Fas(getIndependenceTest()), nodes);
// //        return search(new Fas(getIndependenceTest()), nodes);
// }
// modified FAS into VCFAS; added in definitelyNonadjacencies set of edges.
public Graph search() {
    this.logger.log("info", "Starting VCCPC algorithm");
    this.logger.log("info", "Independence test = " + getIndependenceTest() + ".");
    this.allTriples = new HashSet<>();
    this.ambiguousTriples = new HashSet<>();
    this.colliderTriples = new HashSet<>();
    this.noncolliderTriples = new HashSet<>();
    Vcfas fas = new Vcfas(getIndependenceTest());
    definitelyNonadjacencies = new HashSet<>();
    markovInAllPatterns = new HashSet<>();
    // this.logger.log("info", "Variables " + independenceTest.getVariable());
    long startTime = System.currentTimeMillis();
    if (getIndependenceTest() == null) {
        throw new NullPointerException();
    }
    List<Node> allNodes = getIndependenceTest().getVariables();
    // if (!allNodes.containsAll(nodes)) {
    // throw new IllegalArgumentException("All of the given nodes must " +
    // "be in the domain of the independence test provided.");
    // }
    // Fas fas = new Fas(graph, getIndependenceTest());
    // FasStableConcurrent fas = new FasStableConcurrent(graph, getIndependenceTest());
    // Fas6 fas = new Fas6(graph, getIndependenceTest());
    // fas = new FasICov(graph, (IndTestFisherZ) getIndependenceTest());
    fas.setKnowledge(getKnowledge());
    fas.setDepth(getDepth());
    fas.setVerbose(verbose);
    // Note that we are ignoring the sepset map returned by this method
    // on purpose; it is not used in this search.
    graph = fas.search();
    apparentlyNonadjacencies = fas.getApparentlyNonadjacencies();
    if (isDoOrientation()) {
        if (verbose) {
            System.out.println("CPC orientation...");
        }
        SearchGraphUtils.pcOrientbk(knowledge, graph, allNodes);
        orientUnshieldedTriples(knowledge, getIndependenceTest(), getDepth());
        // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree());
        MeekRules meekRules = new MeekRules();
        meekRules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles);
        meekRules.setKnowledge(knowledge);
        meekRules.orientImplied(graph);
    }
    List<Triple> ambiguousTriples = new ArrayList(graph.getAmbiguousTriples());
    int[] dims = new int[ambiguousTriples.size()];
    for (int i = 0; i < ambiguousTriples.size(); i++) {
        dims[i] = 2;
    }
    // Pattern Search:
    List<Graph> patterns = new ArrayList<>();
    Map<Graph, List<Triple>> newColliders = new IdentityHashMap<>();
    Map<Graph, List<Triple>> newNonColliders = new IdentityHashMap<>();
    // Using combination generator to generate a list of combinations of ambiguous triples dismabiguated into colliders
    // and non-colliders. The combinations are added as graphs to the list patterns. The graphs are then subject to
    // basic rules to ensure consistent patterns.
    CombinationGenerator generator = new CombinationGenerator(dims);
    int[] combination;
    while ((combination = generator.next()) != null) {
        Graph _graph = new EdgeListGraph(graph);
        newColliders.put(_graph, new ArrayList<Triple>());
        newNonColliders.put(_graph, new ArrayList<Triple>());
        for (Graph graph : newColliders.keySet()) {
        // System.out.println("$$$ " + newColliders.get(graph));
        }
        for (int k = 0; k < combination.length; k++) {
            // System.out.println("k = " + combination[k]);
            Triple triple = ambiguousTriples.get(k);
            _graph.removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ());
            if (combination[k] == 0) {
                newColliders.get(_graph).add(triple);
                // System.out.println(newColliders.get(_graph));
                Node x = triple.getX();
                Node y = triple.getY();
                Node z = triple.getZ();
                _graph.setEndpoint(x, y, Endpoint.ARROW);
                _graph.setEndpoint(z, y, Endpoint.ARROW);
            }
            if (combination[k] == 1) {
                newNonColliders.get(_graph).add(triple);
            }
        }
        patterns.add(_graph);
    }
    List<Graph> _patterns = new ArrayList<>(patterns);
    GRAPH: for (Graph graph : new ArrayList<>(patterns)) {
        // _graph = new EdgeListGraph(graph);
        // System.out.println("graph = " + graph + " in keyset? " + newColliders.containsKey(graph));
        // 
        List<Triple> colliders = newColliders.get(graph);
        List<Triple> nonColliders = newNonColliders.get(graph);
        for (Triple triple : colliders) {
            Node x = triple.getX();
            Node y = triple.getY();
            Node z = triple.getZ();
            if (graph.getEdge(x, y).pointsTowards(x) || (graph.getEdge(y, z).pointsTowards(z))) {
                patterns.remove(graph);
                continue GRAPH;
            }
        }
        for (Triple triple : colliders) {
            Node x = triple.getX();
            Node y = triple.getY();
            Node z = triple.getZ();
            graph.setEndpoint(x, y, Endpoint.ARROW);
            graph.setEndpoint(z, y, Endpoint.ARROW);
        }
        for (Triple triple : nonColliders) {
            Node x = triple.getX();
            Node y = triple.getY();
            Node z = triple.getZ();
            if (graph.getEdge(x, y).pointsTowards(y)) {
                graph.removeEdge(y, z);
                graph.addDirectedEdge(y, z);
            }
            if (graph.getEdge(y, z).pointsTowards(y)) {
                graph.removeEdge(x, y);
                graph.addDirectedEdge(y, x);
            }
        }
        for (Edge edge : graph.getEdges()) {
            Node x = edge.getNode1();
            Node y = edge.getNode2();
            if (Edges.isBidirectedEdge(edge)) {
                graph.removeEdge(x, y);
                graph.addUndirectedEdge(x, y);
            }
        }
        // for (Edge edge : graph.getEdges()) {
        // if (Edges.isBidirectedEdge(edge)) {
        // patterns.remove(graph);
        // continue Graph;
        // }
        // }
        MeekRules rules = new MeekRules();
        rules.orientImplied(graph);
        if (graph.existsDirectedCycle()) {
            patterns.remove(graph);
            continue GRAPH;
        }
    }
    MARKOV: for (Edge edge : apparentlyNonadjacencies.keySet()) {
        Node x = edge.getNode1();
        Node y = edge.getNode2();
        for (Graph _graph : new ArrayList<>(patterns)) {
            List<Node> boundaryX = new ArrayList<>(boundary(x, _graph));
            List<Node> boundaryY = new ArrayList<>(boundary(y, _graph));
            List<Node> futureX = new ArrayList<>(future(x, _graph));
            List<Node> futureY = new ArrayList<>(future(y, _graph));
            if (y == x) {
                continue;
            }
            if (boundaryX.contains(y) || boundaryY.contains(x)) {
                continue;
            }
            IndependenceTest test = independenceTest;
            if (!futureX.contains(y)) {
                if (!test.isIndependent(x, y, boundaryX)) {
                    continue MARKOV;
                }
            }
            if (!futureY.contains(x)) {
                if (!test.isIndependent(y, x, boundaryY)) {
                    continue MARKOV;
                }
            }
        }
        definitelyNonadjacencies.add(edge);
    // apparentlyNonadjacencies.remove(edge);
    }
    for (Edge edge : definitelyNonadjacencies) {
        if (apparentlyNonadjacencies.keySet().contains(edge)) {
            apparentlyNonadjacencies.keySet().remove(edge);
        }
    }
    // Modified VCPC to be faster but less correct 4/14/15
    // IndependenceTest test = independenceTest;
    // //
    // MARKOV:
    // for (Edge edge : apparentlyNonadjacencies.keySet()) {
    // Node x = edge.getNode1();
    // Node y = edge.getNode2();
    // //        Build Power sets from boundary.
    // powerSet = new HashSet<List<Node>>();
    // Set<Node> ssX = new HashSet<Node>(boundary(x, graph));
    // List<Node> listX = new ArrayList<Node>(ssX);
    // buildPowerSet(listX, listX.size());
    // Set<List<Node>> bdryX = powerSet;
    // powerSet = new HashSet<List<Node>>();
    // Set<Node> ssY = new HashSet<Node>(boundary(y, graph));
    // List<Node> listY = new ArrayList<Node>(ssY);
    // buildPowerSet(listY, listY.size());
    // Set<List<Node>> bdryY = powerSet;
    // for (List<Node> boundaryX : bdryX) {
    // List<Node> futureX = new ArrayList<Node>(future(x, graph));
    // if (y == x) {
    // continue;
    // }
    // if (boundaryX.contains(y)) {
    // continue;
    // }
    // if (!futureX.contains(y)) {
    // if (!test.isIndependent(x, y, boundaryX)) {
    // continue MARKOV;
    // }
    // }
    // }
    // for (List<Node> boundaryY : bdryY) {
    // List<Node> futureX = new ArrayList<Node>(future(x, graph));
    // List<Node> futureY = new ArrayList<Node>(future(y, graph));
    // if (y == x) {
    // continue;
    // }
    // if (boundaryY.contains(x)) {
    // continue;
    // }
    // if (!futureY.contains(x)) {
    // if (!test.isIndependent(y, x, boundaryY)) {
    // continue MARKOV;
    // }
    // }
    // }
    // definitelyNonadjacencies.add(edge);
    // //            apparentlyNonadjacencies.remove(edge);
    // }
    // for (Edge edge : definitelyNonadjacencies) {
    // if (apparentlyNonadjacencies.keySet().contains(edge)) {
    // apparentlyNonadjacencies.keySet().remove(edge);
    // }
    // }
    System.out.println("VCPC:");
    // System.out.println("# of patterns: " + patterns.size());
    long endTime = System.currentTimeMillis();
    this.elapsedTime = endTime - startTime;
    System.out.println("Search Time (seconds):" + (elapsedTime) / 1000 + " s");
    System.out.println("Search Time (milli):" + elapsedTime + " ms");
    System.out.println("# of Apparent Nonadj: " + apparentlyNonadjacencies.size());
    System.out.println("# of Definite Nonadj: " + definitelyNonadjacencies.size());
    // System.out.println("aMIGUOUS tRIPLES: " + ambiguousTriples);
    // System.out.println("Definitely Nonadjacencies:");
    // for (Edge edge : definitelyNonadjacencies) {
    // System.out.println(edge);
    // }
    // System.out.println("markov in all patterns:" + markovInAllPatterns);
    // //        System.out.println("patterns:" + patterns);
    // System.out.println("Apparently Nonadjacencies:");
    // for (Edge edge : apparentlyNonadjacencies.keySet()) {
    // System.out.println(edge);
    // }
    // System.out.println("Definitely Nonadjacencies:");
    // for (Edge edge : definitelyNonadjacencies) {
    // System.out.println(edge);
    // }
    TetradLogger.getInstance().log("apparentlyNonadjacencies", "\n Apparent Non-adjacencies" + apparentlyNonadjacencies);
    TetradLogger.getInstance().log("definitelyNonadjacencies", "\n Definite Non-adjacencies" + definitelyNonadjacencies);
    // TetradLogger.getInstance().log("patterns", "Disambiguated Patterns: " + patterns);
    TetradLogger.getInstance().log("graph", "\nReturning this graph: " + graph);
    TetradLogger.getInstance().log("info", "Elapsed time = " + (elapsedTime) / 1000. + " s");
    TetradLogger.getInstance().log("info", "Finishing CPC algorithm.");
    // logTriples();
    TetradLogger.getInstance().flush();
    // SearchGraphUtils.verifySepsetIntegrity(Map<Edge, List<Node>>, graph);
    return graph;
}
Also used : CombinationGenerator(edu.cmu.tetrad.util.CombinationGenerator)

Example 5 with CombinationGenerator

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

the class TimeoutComparison method getSimulationWrappers.

private List<SimulationWrapper> getSimulationWrappers(Simulation simulation, Parameters parameters) {
    List<SimulationWrapper> simulationWrappers = new ArrayList<>();
    List<Integer> _dims = new ArrayList<>();
    List<String> varyingParams = new ArrayList<>();
    final List<String> parameters1 = simulation.getParameters();
    for (String param : parameters1) {
        final int numValues = parameters.getNumValues(param);
        if (numValues > 1) {
            _dims.add(numValues);
            varyingParams.add(param);
        }
    }
    if (varyingParams.isEmpty()) {
        simulationWrappers.add(new SimulationWrapper(simulation, parameters));
    } else {
        int[] dims = new int[_dims.size()];
        for (int i = 0; i < _dims.size(); i++) {
            dims[i] = _dims.get(i);
        }
        CombinationGenerator gen = new CombinationGenerator(dims);
        int[] choice;
        while ((choice = gen.next()) != null) {
            SimulationWrapper wrapper = new SimulationWrapper(simulation, parameters);
            for (int h = 0; h < dims.length; h++) {
                String param = varyingParams.get(h);
                Object[] values = parameters.getValues(param);
                Object value = values[choice[h]];
                wrapper.setValue(param, value);
            }
            simulationWrappers.add(wrapper);
        }
    }
    return simulationWrappers;
}
Also used : CombinationGenerator(edu.cmu.tetrad.util.CombinationGenerator) ArrayList(java.util.ArrayList)

Aggregations

CombinationGenerator (edu.cmu.tetrad.util.CombinationGenerator)10 Test (org.junit.Test)3 Regression (edu.cmu.tetrad.regression.Regression)2 RegressionDataset (edu.cmu.tetrad.regression.RegressionDataset)2 RegressionResult (edu.cmu.tetrad.regression.RegressionResult)2 ArrayList (java.util.ArrayList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)1 ExternalAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm)1 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)1 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)1 Statistic (edu.cmu.tetrad.algcomparison.statistic.Statistic)1 DataType (edu.cmu.tetrad.data.DataType)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1