Search in sources :

Example 1 with IndTestScore

use of edu.cmu.tetrad.search.IndTestScore in project tetrad by cmu-phil.

the class TestAutisticClassification method testForBiwei.

// @Test
public void testForBiwei() {
    Parameters parameters = new Parameters();
    parameters.set("penaltyDiscount", 2);
    parameters.set("depth", -1);
    parameters.set("numRuns", 10);
    parameters.set("randomSelectionSize", 1);
    parameters.set("Structure", "Placeholder");
    FaskGraphs files = new FaskGraphs("/Users/jdramsey/Downloads/USM_ABIDE", new Parameters());
    List<DataSet> datasets = files.getDatasets();
    List<String> filenames = files.getFilenames();
    for (int i = 0; i < datasets.size(); i++) {
        DataSet dataSet = datasets.get(i);
        SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet));
        Fas fas = new Fas(new IndTestScore(score));
        Graph graph = fas.search();
        System.out.println(graph);
        List<Node> nodes = graph.getNodes();
        StringBuilder b = new StringBuilder();
        for (int j = 0; j < nodes.size(); j++) {
            for (int k = 0; k < nodes.size(); k++) {
                if (graph.isAdjacentTo(nodes.get(j), nodes.get(k))) {
                    b.append("1 ");
                } else {
                    b.append("0 ");
                }
            }
            b.append("\n");
        }
        try {
            File dir = new File("/Users/jdramsey/Downloads/biwei/USM_ABIDE");
            dir.mkdirs();
            File file = new File(dir, filenames.get(i) + ".graph.txt");
            PrintStream out = new PrintStream(file);
            out.println(b);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) IndTestScore(edu.cmu.tetrad.search.IndTestScore) Node(edu.cmu.tetrad.graph.Node) FileNotFoundException(java.io.FileNotFoundException) Graph(edu.cmu.tetrad.graph.Graph) Fas(edu.cmu.tetrad.search.Fas) CovarianceMatrixOnTheFly(edu.cmu.tetrad.data.CovarianceMatrixOnTheFly) File(java.io.File) SemBicScore(edu.cmu.tetrad.search.SemBicScore)

Example 2 with IndTestScore

use of edu.cmu.tetrad.search.IndTestScore in project tetrad by cmu-phil.

the class TsImages method search.

@Override
public Graph search(List<DataModel> dataSets, Parameters parameters) {
    List<DataModel> dataModels = new ArrayList<>();
    for (DataModel dataSet : dataSets) {
        dataModels.add(dataSet);
    }
    TsGFci search;
    if (score instanceof SemBicScore) {
        SemBicScoreImages gesScore = new SemBicScoreImages(dataModels);
        gesScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
        IndependenceTest test = new IndTestScore(gesScore);
        search = new TsGFci(test, gesScore);
    } else if (score instanceof BdeuScore) {
        double samplePrior = parameters.getDouble("samplePrior", 1);
        double structurePrior = parameters.getDouble("structurePrior", 1);
        BdeuScoreImages score = new BdeuScoreImages(dataModels);
        score.setSamplePrior(samplePrior);
        score.setStructurePrior(structurePrior);
        IndependenceTest test = new IndTestScore(score);
        search = new TsGFci(test, score);
    } else {
        throw new IllegalStateException("Sorry, data must either be all continuous or all discrete.");
    }
    IKnowledge knowledge = dataModels.get(0).getKnowledge();
    search.setKnowledge(knowledge);
    return search.search();
}
Also used : BdeuScoreImages(edu.cmu.tetrad.search.BdeuScoreImages) IKnowledge(edu.cmu.tetrad.data.IKnowledge) IndependenceTest(edu.cmu.tetrad.search.IndependenceTest) SemBicScoreImages(edu.cmu.tetrad.search.SemBicScoreImages) DataModel(edu.cmu.tetrad.data.DataModel) IndTestScore(edu.cmu.tetrad.search.IndTestScore) BdeuScore(edu.cmu.tetrad.algcomparison.score.BdeuScore) ArrayList(java.util.ArrayList) TsGFci(edu.cmu.tetrad.search.TsGFci) SemBicScore(edu.cmu.tetrad.algcomparison.score.SemBicScore)

Example 3 with IndTestScore

use of edu.cmu.tetrad.search.IndTestScore 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 4 with IndTestScore

use of edu.cmu.tetrad.search.IndTestScore in project tetrad by cmu-phil.

the class SemBicDTest method getTest.

@Override
public IndependenceTest getTest(DataModel dataSet, Parameters parameters) {
    SemBicScoreDeterministic score = new SemBicScoreDeterministic(new CovarianceMatrix((ICovarianceMatrix) dataSet));
    score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
    return new IndTestScore(score, dataSet);
}
Also used : SemBicScoreDeterministic(edu.cmu.tetrad.search.SemBicScoreDeterministic) IndTestScore(edu.cmu.tetrad.search.IndTestScore)

Example 5 with IndTestScore

use of edu.cmu.tetrad.search.IndTestScore in project tetrad by cmu-phil.

the class ImagesPcStableMax method search.

@Override
public Graph search(List<DataModel> dataModels, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        List<DataSet> dataSets = new ArrayList<>();
        for (DataModel dataModel : dataModels) {
            dataSets.add((DataSet) dataModel);
        }
        SemBicScoreImages3 score = new SemBicScoreImages3(dataSets);
        score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
        IndependenceTest test = new IndTestScore(score);
        PcStableMax search = new PcStableMax(test);
        search.setUseHeuristic(parameters.getBoolean("useMaxPOrientationHeuristic"));
        search.setMaxPathLength(parameters.getInt("maxPOrientationMaxPathLength"));
        search.setKnowledge(knowledge);
        search.setDepth(parameters.getInt("depth"));
        return search.search();
    } else {
        ImagesPcStableMax imagesPcStableMax = new ImagesPcStableMax();
        // imagesPcStableMax.setKnowledge(knowledge);
        List<DataSet> datasets = new ArrayList<>();
        for (DataModel dataModel : dataModels) {
            datasets.add((DataSet) dataModel);
        }
        GeneralBootstrapTest search = new GeneralBootstrapTest(datasets, imagesPcStableMax, 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 : IndependenceTest(edu.cmu.tetrad.search.IndependenceTest) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) IndTestScore(edu.cmu.tetrad.search.IndTestScore) ArrayList(java.util.ArrayList) PcStableMax(edu.cmu.tetrad.search.PcStableMax) SemBicScoreImages3(edu.cmu.tetrad.search.SemBicScoreImages3)

Aggregations

IndTestScore (edu.cmu.tetrad.search.IndTestScore)7 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)4 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)4 IndependenceTest (edu.cmu.tetrad.search.IndependenceTest)3 ArrayList (java.util.ArrayList)3 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)2 DataSet (edu.cmu.tetrad.data.DataSet)2 SemBicScoreDeterministic (edu.cmu.tetrad.search.SemBicScoreDeterministic)2 SemBicScoreImages (edu.cmu.tetrad.search.SemBicScoreImages)2 TsGFci (edu.cmu.tetrad.search.TsGFci)2 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)1 DataModel (edu.cmu.tetrad.data.DataModel)1 IKnowledge (edu.cmu.tetrad.data.IKnowledge)1 Graph (edu.cmu.tetrad.graph.Graph)1 Node (edu.cmu.tetrad.graph.Node)1 BdeuScoreImages (edu.cmu.tetrad.search.BdeuScoreImages)1 Fas (edu.cmu.tetrad.search.Fas)1 PcStableMax (edu.cmu.tetrad.search.PcStableMax)1 Score (edu.cmu.tetrad.search.Score)1