use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class TestFges method testFgesMbFromGraph.
@Test
public void testFgesMbFromGraph() {
RandomUtil.getInstance().setSeed(1450184147770L);
int numNodes = 20;
int numIterations = 1;
for (int i = 0; i < numIterations; i++) {
// System.out.println("Iteration " + (i + 1));
Graph dag = GraphUtils.randomDag(numNodes, 0, numNodes, 10, 10, 10, false);
GraphScore fgesScore = new GraphScore(dag);
Fges fges = new Fges(fgesScore);
Graph pattern1 = fges.search();
Node x1 = fgesScore.getVariable("X1");
Set<Node> mb = new HashSet<>();
mb.add(x1);
mb.addAll(pattern1.getAdjacentNodes(x1));
for (Node child : pattern1.getChildren(x1)) {
mb.addAll(pattern1.getParents(child));
}
Graph mb1 = pattern1.subgraph(new ArrayList<>(mb));
FgesMb fgesMb = new FgesMb(fgesScore);
Graph mb2 = fgesMb.search(x1);
assertEquals(mb1, mb2);
}
}
use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class TestFges method testCites.
@Test
public void testCites() {
String citesString = "164\n" + "ABILITY\tGPQ\tPREPROD\tQFJ\tSEX\tCITES\tPUBS\n" + "1.0\n" + ".62\t1.0\n" + ".25\t.09\t1.0\n" + ".16\t.28\t.07\t1.0\n" + "-.10\t.00\t.03\t.10\t1.0\n" + ".29\t.25\t.34\t.37\t.13\t1.0\n" + ".18\t.15\t.19\t.41\t.43\t.55\t1.0";
char[] citesChars = citesString.toCharArray();
DataReader reader = new DataReader();
ICovarianceMatrix dataSet = reader.parseCovariance(citesChars);
IKnowledge knowledge = new Knowledge2();
knowledge.addToTier(1, "ABILITY");
knowledge.addToTier(2, "GPQ");
knowledge.addToTier(3, "QFJ");
knowledge.addToTier(3, "PREPROD");
knowledge.addToTier(4, "SEX");
knowledge.addToTier(5, "PUBS");
knowledge.addToTier(6, "CITES");
SemBicScore score = new SemBicScore(dataSet);
score.setPenaltyDiscount(1);
Fges fges = new Fges(score);
fges.setKnowledge(knowledge);
Graph pattern = fges.search();
// System.out.println(pattern);
String trueString = "Graph Nodes:\n" + "ABILITY,GPQ,PREPROD,QFJ,SEX,CITES,PUBS\n" + "\n" + "Graph Edges: \n" + "1. ABILITY --> GPQ \n" + "2. ABILITY --> PREPROD \n" + "3. GPQ --> QFJ \n" + "4. PUBS --> CITES \n" + "5. QFJ --> PUBS \n" + "6. SEX --> PUBS";
Graph trueGraph = null;
try {
trueGraph = GraphUtils.readerToGraphTxt(trueString);
} catch (IOException e) {
e.printStackTrace();
}
pattern = GraphUtils.replaceNodes(pattern, trueGraph.getNodes());
assertEquals(trueGraph, pattern);
}
use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class TestFges method test7.
@Test
public void test7() {
for (int i = 0; i < 10; i++) {
Graph graph = GraphUtils.randomGraph(10, 0, 10, 10, 10, 10, false);
SemPm semPm = new SemPm(graph);
SemIm semIm = new SemIm(semPm);
DataSet dataSet = semIm.simulateData(1000, false);
Fges fges = new Fges(new SemBicScore(new CovarianceMatrixOnTheFly(dataSet)));
Graph pattern = fges.search();
Graph dag = dagFromPattern(pattern);
assertFalse(dag.existsDirectedCycle());
}
}
use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class TestFges method searchMixedFges.
private Graph searchMixedFges(DataSet dk, double penalty) {
MixedBicScore score = new MixedBicScore(dk);
score.setPenaltyDiscount(penalty);
Fges fges = new Fges(score);
return fges.search();
}
use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class ExploreAutisticsNeurotypicals method runAlgorithm.
private List<List<Graph>> runAlgorithm(String path, List<List<DataSet>> allDatasets, double penaltyDiscount) {
List<List<Graph>> allGraphs = new ArrayList<>();
for (List<DataSet> dataSets : allDatasets) {
List<Graph> graphs = new ArrayList<>();
for (DataSet dataSet : dataSets) {
String name = dataSet.getName() + "." + penaltyDiscount + ".graph.txt";
File file = new File(path, name);
SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet));
score.setPenaltyDiscount(penaltyDiscount);
Fges search = new Fges(score);
search.setVerbose(false);
Graph graph = search.search();
GraphUtils.saveGraph(graph, file, false);
graphs.add(GraphUtils.undirectedGraph(GraphUtils.loadGraphTxt(file)));
}
allGraphs.add(graphs);
}
return allGraphs;
}
Aggregations