Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
kvb2univpitt committed Dec 6, 2020
2 parents b36a0b8 + 2c44c5a commit 0ccb293
Show file tree
Hide file tree
Showing 6 changed files with 1,114 additions and 48 deletions.
26 changes: 16 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.pitt.dbmi</groupId>
<artifactId>causal-cmd</artifactId>
<version>1.1.3</version>
<version>1.2.1</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<repositories>
Expand All @@ -36,9 +36,14 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-dist-resources</id>
Expand All @@ -61,7 +66,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
Expand Down Expand Up @@ -121,7 +126,7 @@
<dependency>
<groupId>edu.cmu</groupId>
<artifactId>tetrad-lib</artifactId>
<version>6.7.0</version>
<version>6.8.0</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
Expand All @@ -144,12 +149,13 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.28</version>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/edu/pitt/dbmi/causal/cmd/tetrad/TetradRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ public void runAlgorithm(PrintStream out) throws AlgorithmRunException, IOExcept
final Parameters parameters = Tetrad.getParameters(cmdArgs);
parameters.set("printStream", out);

// warn user about the default use of testwise deletion of data contain missing values
boolean hasMissingValues = containsMissingValues(dataModels);
boolean hasScore = cmdArgs.getScoreClass() != null;
boolean hasTest = cmdArgs.getTestClass() != null;
if (hasMissingValues && (hasScore || hasTest)) {
out.println();
out.println("WARNING: Dataset contains missing values;testwise deletion will be used in test and/or score.");
}

boolean verbose = parameters.getBoolean("verbose", false);

out.printf("%nStart search: %s%n", DateTime.printNow());
Expand All @@ -103,6 +112,28 @@ public void runAlgorithm(PrintStream out) throws AlgorithmRunException, IOExcept
graphList.forEach(graph -> graphs.add(manipulateGraph(graph)));
}

/**
* Determine if any of the data model contains missing values;
*
* @param dataModels
* @return
*/
private boolean containsMissingValues(final List<DataModel> dataModels) {
boolean hasMissingValues = false;

for (DataModel dataModel : dataModels) {
if (dataModel instanceof DataSet) {
DataSet dataSet = (DataSet) dataModel;
if (dataSet.existsMissingValue()) {
hasMissingValues = true;
break;
}
}
}

return hasMissingValues;
}

private List<Graph> runSearch(final Algorithm algorithm, final Parameters parameters, final List<DataModel> dataModels) {
List<Graph> graphList = new LinkedList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package edu.pitt.dbmi.causal.cmd;

import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

/**
*
Expand All @@ -31,17 +31,14 @@
*/
public class CausalCmdApplicationMetadataTest {

@Rule
public final TemporaryFolder tmpFolder = new TemporaryFolder();

public CausalCmdApplicationMetadataTest() {
}
@TempDir
public static Path tempDir;

@Test
public void testGFCIWithMixedData() throws IOException {
String dataset = TestFiles.MIXED_INTERVENTIONAL_DATA;
String metadata = TestFiles.MIXED_INTERVENTIONAL_METADATA;
String dirOut = tmpFolder.newFolder("gfci_interv_mixed").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_interv_mixed").toString();
String[] args = {
"--dataset", dataset,
"--metadata", metadata,
Expand All @@ -63,14 +60,14 @@ public void testGFCIWithMixedData() throws IOException {
public void testGFCIWithDiscreteData() throws IOException {
String dataset = TestFiles.DISCRETE_INTERVENTIONAL_DATA;
String metadata = TestFiles.DISCRETE_INTERVENTIONAL_METADATA;
String dirOut = tmpFolder.newFolder("gfci_interv_discrete").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_interv_discrete").toString();
String[] args = {
"--dataset", dataset,
"--metadata", metadata,
"--delimiter", "tab",
"--data-type", "discrete",
"--algorithm", "gfci",
"--test", "bdeu-test",
"--test", "g-square-test",
"--score", "bdeu-score",
"--verbose",
"--skip-latest",
Expand All @@ -83,15 +80,15 @@ public void testGFCIWithDiscreteData() throws IOException {
public void testGFCIWithContinuousData() throws IOException {
String dataset = TestFiles.CONTINUOUS_INTERVENTIONAL_DATA;
String metadata = TestFiles.CONTINUOUS_INTERVENTIONAL_METADATA;
String dirOut = tmpFolder.newFolder("gfci_interv_cont").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_interv_cont").toString();
String[] args = {
"--dataset", dataset,
"--metadata", metadata,
"--delimiter", "tab",
"--data-type", "continuous",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic",
"--score", "sem-bic-score",
"--verbose",
"--skip-latest",
"--out", dirOut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
package edu.pitt.dbmi.causal.cmd;

import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.nio.file.Path;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

/**
*
Expand All @@ -31,16 +32,14 @@
*/
public class CausalCmdApplicationTest {

@Rule
public final TemporaryFolder tmpFolder = new TemporaryFolder();

public CausalCmdApplicationTest() {
}
@TempDir
public static Path tempDir;

@Disabled
@Test
public void testExperimentalAlgorithm() throws IOException {
String dataset = TestFiles.DISCRETE_DATA;
String dirOut = tmpFolder.newFolder("rfci-bsc_discrete").toString();
String dirOut = TestFiles.createSubDir(tempDir, "rfci-bsc_discrete").toString();
String[] args = {
"--dataset", dataset,
"--delimiter", "tab",
Expand All @@ -54,17 +53,36 @@ public void testExperimentalAlgorithm() throws IOException {
CausalCmdApplication.main(args);
}

@Test
public void testGFCIWithContinuousMissingData() throws IOException {
String dataset = TestFiles.CONTINUOUS_10VAR_1KCASE_MISSING_DATA;
String dirOut = TestFiles.createSubDir(tempDir, "gfci_missing_values").toString();
String[] args = {
"--dataset", dataset,
"--delimiter", "comma",
"--data-type", "continuous",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic-score",
"--missing", "*",
"--verbose",
"--skip-latest",
"--out", dirOut
};
CausalCmdApplication.main(args);
}

@Test
public void testGFCIWithContinuousDataAndChooseMagInPag() throws IOException {
String dataset = TestFiles.CONTINUOUS_DATA;
String dirOut = tmpFolder.newFolder("gfci_choose_dag_in_pattern").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_choose_dag_in_pattern").toString();
String[] args = {
"--dataset", dataset,
"--delimiter", "tab",
"--data-type", "continuous",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic",
"--score", "sem-bic-score",
"--verbose",
"--skip-latest",
"--choose-mag-in-pag",
Expand All @@ -77,12 +95,13 @@ public void testGFCIWithContinuousDataAndChooseMagInPag() throws IOException {
public void testMultiFaskWithMultipleContinuousData() throws IOException {
String dataset1 = TestFiles.CONTINUOUS_DATA_20K_PART1;
String dataset2 = TestFiles.CONTINUOUS_DATA_20K_PART2;
String dirOut = tmpFolder.newFolder("multi-fask_cont").toString();
String dirOut = TestFiles.createSubDir(tempDir, "multi-fask_cont").toString();
String[] args = {
"--dataset", dataset1 + "," + dataset2,
"--delimiter", "tab",
"--data-type", "continuous",
"--algorithm", "multi-fask",
"--test", "fisher-z-test",
"--verbose",
"--skip-latest",
"--out", dirOut
Expand All @@ -94,15 +113,15 @@ public void testMultiFaskWithMultipleContinuousData() throws IOException {
public void testGFCIWithContinuousDataAndVariablesToExclude() throws IOException {
String dataset = TestFiles.CONTINUOUS_DATA;
String excludeVar = TestFiles.EXCLUDE_VARIABLES;
String dirOut = tmpFolder.newFolder("gfci_exclude_vars").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_exclude_vars").toString();
String[] args = {
"--dataset", dataset,
"--exclude-var", excludeVar,
"--delimiter", "tab",
"--data-type", "continuous",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic",
"--score", "sem-bic-score",
"--verbose",
"--skip-latest",
"--out", dirOut
Expand All @@ -113,14 +132,14 @@ public void testGFCIWithContinuousDataAndVariablesToExclude() throws IOException
@Test
public void testFGESCovariance() throws IOException {
String dataset = TestFiles.COVARIANCE_CONTINUOUS_DATA;
String dirOut = tmpFolder.newFolder("gfci_covar").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_covar").toString();
String[] args = {
"--dataset", dataset,
"--delimiter", "tab",
"--data-type", "covariance",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic",
"--score", "sem-bic-score",
"--verbose",
"--skip-latest",
"--out", dirOut
Expand All @@ -132,15 +151,15 @@ public void testFGESCovariance() throws IOException {
public void testGFCIWithContinuousDataAndKnowledge() throws IOException {
String dataset = TestFiles.CONTINUOUS_DATA;
String knowledge = TestFiles.KNOWLEDGE_CONTINUOUS_DATA;
String dirOut = tmpFolder.newFolder("gfci_knowledge").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_knowledge").toString();
String[] args = {
"--dataset", dataset,
"--knowledge", knowledge,
"--delimiter", "tab",
"--data-type", "continuous",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic",
"--score", "sem-bic-score",
"--verbose",
"--skip-latest",
"--out", dirOut
Expand All @@ -151,15 +170,15 @@ public void testGFCIWithContinuousDataAndKnowledge() throws IOException {
@Test
public void testGFCIWithNoHeaderContinuousData() throws IOException {
String dataset = TestFiles.CONTINUOUS_DATA_NO_HEADER;
String dirOut = tmpFolder.newFolder("gfci_cont_no_header").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_cont_no_header").toString();
String[] args = {
"--dataset", dataset,
"--no-header",
"--delimiter", "tab",
"--data-type", "continuous",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic",
"--score", "sem-bic-score",
"--verbose",
"--skip-latest",
"--out", dirOut
Expand All @@ -170,7 +189,7 @@ public void testGFCIWithNoHeaderContinuousData() throws IOException {
@Test
public void testGFCIWithMixedData() throws IOException {
String dataset = TestFiles.MIXED_DATA;
String dirOut = tmpFolder.newFolder("gfci_mixed").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_mixed").toString();
String[] args = {
"--dataset", dataset,
"--delimiter", "tab",
Expand All @@ -189,13 +208,13 @@ public void testGFCIWithMixedData() throws IOException {
@Test
public void testGFCIWithDiscreteData() throws IOException {
String dataset = TestFiles.DISCRETE_DATA;
String dirOut = tmpFolder.newFolder("gfci_discrete").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_discrete").toString();
String[] args = {
"--dataset", dataset,
"--delimiter", "tab",
"--data-type", "discrete",
"--algorithm", "gfci",
"--test", "bdeu-test",
"--test", "g-square-test",
"--score", "bdeu-score",
"--faithfulnessAssumed",
"--verbose",
Expand All @@ -208,14 +227,14 @@ public void testGFCIWithDiscreteData() throws IOException {
@Test
public void testGFCIWithContinuousData() throws IOException {
String dataset = TestFiles.CONTINUOUS_DATA;
String dirOut = tmpFolder.newFolder("gfci_cont").toString();
String dirOut = TestFiles.createSubDir(tempDir, "gfci_cont").toString();
String[] args = {
"--dataset", dataset,
"--delimiter", "tab",
"--data-type", "continuous",
"--algorithm", "gfci",
"--test", "fisher-z-test",
"--score", "sem-bic",
"--score", "sem-bic-score",
"--penaltyDiscount", "1.0",
"--structurePrior", "0.01",
"--verbose",
Expand Down
Loading

0 comments on commit 0ccb293

Please sign in to comment.