Search in sources :

Example 11 with BootstrapEdgeEnsemble

use of edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble in project tetrad by cmu-phil.

the class Mgm method search.

@Override
public Graph search(DataModel ds, Parameters parameters) {
    // Notify the user that you need at least one continuous and one discrete variable to run MGM
    List<Node> variables = ds.getVariables();
    boolean hasContinuous = false;
    boolean hasDiscrete = false;
    for (Node node : variables) {
        if (node instanceof ContinuousVariable) {
            hasContinuous = true;
        }
        if (node instanceof DiscreteVariable) {
            hasDiscrete = true;
        }
    }
    if (!hasContinuous || !hasDiscrete) {
        throw new IllegalArgumentException("You need at least one continuous and one discrete variable to run MGM.");
    }
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        DataSet _ds = DataUtils.getMixedDataSet(ds);
        double mgmParam1 = parameters.getDouble("mgmParam1");
        double mgmParam2 = parameters.getDouble("mgmParam2");
        double mgmParam3 = parameters.getDouble("mgmParam3");
        double[] lambda = { mgmParam1, mgmParam2, mgmParam3 };
        MGM m = new MGM(_ds, lambda);
        return m.search();
    } else {
        Mgm algorithm = new Mgm();
        DataSet data = (DataSet) ds;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) MGM(edu.pitt.csb.mgm.MGM)

Example 12 with BootstrapEdgeEnsemble

use of edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble in project tetrad by cmu-phil.

the class PcAll method search.

@Override
public Graph search(DataModel dataSet, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        if (algorithm != null) {
        // initialGraph = algorithm.search(dataSet, parameters);
        }
        edu.cmu.tetrad.search.PcAll.FasRule fasRule;
        switch(parameters.getInt("fasRule")) {
            case 1:
                fasRule = edu.cmu.tetrad.search.PcAll.FasRule.FAS;
                break;
            case 2:
                fasRule = edu.cmu.tetrad.search.PcAll.FasRule.FAS_STABLE;
                break;
            case 3:
                fasRule = edu.cmu.tetrad.search.PcAll.FasRule.FAS_STABLE_CONCURRENT;
                break;
            default:
                throw new IllegalArgumentException("Not a choice.");
        }
        edu.cmu.tetrad.search.PcAll.ColliderDiscovery colliderDiscovery;
        switch(parameters.getInt("colliderDiscoveryRule")) {
            case 1:
                colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.FAS_SEPSETS;
                break;
            case 2:
                colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.CONSERVATIVE;
                break;
            case 3:
                colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.MAX_P;
                break;
            default:
                throw new IllegalArgumentException("Not a choice.");
        }
        edu.cmu.tetrad.search.PcAll.ConflictRule conflictRule;
        switch(parameters.getInt("conflictRule")) {
            case 1:
                conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.OVERWRITE;
                break;
            case 2:
                conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.BIDIRECTED;
                break;
            case 3:
                conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.PRIORITY;
                break;
            default:
                throw new IllegalArgumentException("Not a choice.");
        }
        edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(test.getTest(dataSet, parameters), initialGraph);
        search.setDepth(parameters.getInt("depth"));
        search.setKnowledge(knowledge);
        search.setFasRule(fasRule);
        search.setColliderDiscovery(colliderDiscovery);
        search.setConflictRule(conflictRule);
        search.setUseHeuristic(parameters.getBoolean("useMaxPOrientationHeuristic"));
        search.setMaxPathLength(parameters.getInt("maxPOrientationMaxPathLength"));
        return search.search();
    } else {
        PcAll pcAll = new PcAll(test, algorithm);
        // pcAll.setKnowledge(knowledge);
        if (initialGraph != null) {
            pcAll.setInitialGraph(initialGraph);
        }
        DataSet data = (DataSet) dataSet;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, pcAll, parameters.getInt("bootstrapSampleSize"));
        search.setKnowledge(knowledge);
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) DataSet(edu.cmu.tetrad.data.DataSet)

Example 13 with BootstrapEdgeEnsemble

use of edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble in project tetrad by cmu-phil.

the class PcStable method search.

@Override
public Graph search(DataModel dataSet, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        if (algorithm != null) {
        // initialGraph = algorithm.search(dataSet, parameters);
        }
        edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(test.getTest(dataSet, parameters), initialGraph);
        search.setDepth(parameters.getInt("depth"));
        search.setKnowledge(knowledge);
        search.setFasRule(PcAll.FasRule.FAS_STABLE);
        search.setColliderDiscovery(edu.cmu.tetrad.search.PcAll.ColliderDiscovery.FAS_SEPSETS);
        search.setConflictRule(PcAll.ConflictRule.PRIORITY);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    } else {
        PcStable pcStable = new PcStable(test, algorithm);
        // pcStable.setKnowledge(knowledge);
        if (initialGraph != null) {
            pcStable.setInitialGraph(initialGraph);
        }
        DataSet data = (DataSet) dataSet;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, pcStable, parameters.getInt("bootstrapSampleSize"));
        search.setKnowledge(knowledge);
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) PcAll(edu.cmu.tetrad.search.PcAll) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) DataSet(edu.cmu.tetrad.data.DataSet) PcAll(edu.cmu.tetrad.search.PcAll)

Example 14 with BootstrapEdgeEnsemble

use of edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble in project tetrad by cmu-phil.

the class Pcd method search.

@Override
public Graph search(DataModel dataSet, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        IndTestScore test;
        if (dataSet instanceof ICovarianceMatrix) {
            SemBicScoreDeterministic score = new SemBicScoreDeterministic((ICovarianceMatrix) dataSet);
            score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
            score.setDeterminismThreshold(parameters.getDouble("determinismThreshold"));
            test = new IndTestScore(score);
        } else if (dataSet instanceof DataSet) {
            SemBicScoreDeterministic score = new SemBicScoreDeterministic(new CovarianceMatrix((DataSet) dataSet));
            score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
            score.setDeterminismThreshold(parameters.getDouble("determinismThreshold"));
            test = new IndTestScore(score);
        } else {
            throw new IllegalArgumentException("Expecting a dataset or a covariance matrix.");
        }
        edu.cmu.tetrad.search.Pcd search = new edu.cmu.tetrad.search.Pcd(test);
        search.setDepth(parameters.getInt("depth"));
        search.setKnowledge(knowledge);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    } else {
        Pcd algorithm = new Pcd();
        // algorithm.setKnowledge(knowledge);
        DataSet data = (DataSet) dataSet;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
        search.setKnowledge(knowledge);
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : SemBicScoreDeterministic(edu.cmu.tetrad.search.SemBicScoreDeterministic) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) IndTestScore(edu.cmu.tetrad.search.IndTestScore)

Example 15 with BootstrapEdgeEnsemble

use of edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble in project tetrad by cmu-phil.

the class EB method search.

@Override
public Graph search(DataModel dataSet, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        initialGraph = algorithm.search(dataSet, parameters);
        if (initialGraph != null) {
            initialGraph = algorithm.search(dataSet, parameters);
        } else {
            throw new IllegalArgumentException("This EB algorithm needs both data and a graph source as inputs; it \n" + "will orient the edges in the input graph using the data.");
        }
        List<DataSet> dataSets = new ArrayList<>();
        dataSets.add(DataUtils.getContinuousDataSet(dataSet));
        Lofs2 lofs = new Lofs2(initialGraph, dataSets);
        lofs.setRule(Lofs2.Rule.EB);
        return lofs.orient();
    } else {
        EB eb = new EB(algorithm);
        if (initialGraph != null) {
            eb.setInitialGraph(initialGraph);
        }
        DataSet data = (DataSet) dataSet;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, eb, parameters.getInt("bootstrapSampleSize"));
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : Lofs2(edu.cmu.tetrad.search.Lofs2) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) DataSet(edu.cmu.tetrad.data.DataSet) ArrayList(java.util.ArrayList)

Aggregations

BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)66 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)66 DataSet (edu.cmu.tetrad.data.DataSet)26 ArrayList (java.util.ArrayList)21 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)15 Graph (edu.cmu.tetrad.graph.Graph)15 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)10 Lofs2 (edu.cmu.tetrad.search.Lofs2)10 Node (edu.cmu.tetrad.graph.Node)6 PrintStream (java.io.PrintStream)6 PcAll (edu.cmu.tetrad.search.PcAll)5 edu.cmu.tetrad.search (edu.cmu.tetrad.search)4 IndTestScore (edu.cmu.tetrad.search.IndTestScore)4 IndependenceTest (edu.cmu.tetrad.search.IndependenceTest)4 Fges (edu.cmu.tetrad.search.Fges)3 Score (edu.cmu.tetrad.search.Score)3 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)2 PcStableMax (edu.cmu.tetrad.search.PcStableMax)2 SemBicScoreDeterministic (edu.cmu.tetrad.search.SemBicScoreDeterministic)2 SemBicScoreImages (edu.cmu.tetrad.search.SemBicScoreImages)2