Remove the executable component, as the R package component has advanced enough that it can do everything.
Also, the executable component uses a dependency that keeps having security vulnerabilities.
This commit is contained in:
parent
f3a4ef01ed
commit
c4bab39245
121 changed files with 95 additions and 1400 deletions
34
README.md
34
README.md
|
@ -1,21 +1,18 @@
|
||||||
# README
|
# README
|
||||||
|
|
||||||
This repository contains two Java projects;
|
This repository contains the largeRCRF Java library, containing all of the logic used for training the random forests. This provides the Jar file used in the R package [largeRCRF](https://github.com/jatherrien/largeRCRF).
|
||||||
|
|
||||||
* The first is the largeRCRF library (`library/`) containing all of the logic used for training the random forests. This part provides the Jar file used in the R package [largeRCRF](https://github.com/jatherrien/largeRCRF).
|
Most users interested in training random competing risks forests should use the [R package component](https://github.com/jatherrien/largeRCRF); the content in this repository is only useful for advanced users.
|
||||||
* The second is a small executable (`executable/`) Java project that uses the library and can be run directly outside of R. It's still in its early stages and isn't polished, nor is it yet well documented; but you can take a look if you want.
|
|
||||||
|
|
||||||
Most users interested in training random competing risks forests should use the [R package component](https://github.com/jatherrien/largeRCRF); the content in this repository will only be useful to advanced users.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
You're free to use / modify / redistribute either of the two projects above, as long as you follow the terms of the GPL-3 license.
|
You're free to use / modify / redistribute thep project, as long as you follow the terms of the GPL-3 license.
|
||||||
|
|
||||||
## Extending
|
## Extending
|
||||||
|
|
||||||
Documentation on how to extend the library to add support for other types of random forests will eventually be added, but for now if you're interested in that I suggest you take a look at the `MeanResponseCombiner` and `WeightedVarianceSplitFinder` classes to see how some basic regression random forests were introduced.
|
Documentation on how to extend the library to add support for other types of random forests will eventually be added, but for now if you're interested in that I suggest you take a look at the `MeanResponseCombiner` and `WeightedVarianceSplitFinder` classes to see how some basic regression random forests were introduced.
|
||||||
|
|
||||||
If you've made a modification to the package and would like to integrate it into the R package component, build the project in Maven with `mvn clean package` (in the same directory as this `README` file), then just copy `library/target/largeRCRF-library-1.0-SNAPSHOT.jar` into the `inst/java/` directory for the R package, replacing the previous Jar file there. Then build the R package, possibly with your modifications to the code there, with `R> devtools::build()`.
|
If you've made a modification to the package and would like to integrate it into the R package component, build the project in Maven with `mvn clean package`, then just copy `target/largeRCRF-library-1.0-SNAPSHOT.jar` into the `inst/java/` directory for the R package, replacing the previous Jar file there. Then build the R package, possibly with your modifications to the code there, with `R> devtools::build()`.
|
||||||
|
|
||||||
Please don't take the current lack of documentation as a sign that I oppose others extending or modifying the project; if you have any questions on running, extending, integrating with R, or anything else related to this project, please don't hesitate to either [email me](mailto:joelt@sfu.ca) or create an Issue. Most likely my answers to your questions will end up forming the basis for any documentation written.
|
Please don't take the current lack of documentation as a sign that I oppose others extending or modifying the project; if you have any questions on running, extending, integrating with R, or anything else related to this project, please don't hesitate to either [email me](mailto:joelt@sfu.ca) or create an Issue. Most likely my answers to your questions will end up forming the basis for any documentation written.
|
||||||
|
|
||||||
|
@ -26,26 +23,3 @@ You need:
|
||||||
* A Java runtime version 1.8 or greater
|
* A Java runtime version 1.8 or greater
|
||||||
* Maven to build the project
|
* Maven to build the project
|
||||||
|
|
||||||
## Troubleshooting (Running `executable`)
|
|
||||||
|
|
||||||
Some of these Troubleshooting items can also apply if you are integrating the library classes into your own Java project.
|
|
||||||
|
|
||||||
### I get an `OutOfMemoryException` error but I have plenty of RAM
|
|
||||||
|
|
||||||
By default the Java virtual machine only uses a quarter of the available system memory. When launching the Jar file you can manually specify the memory available like below:
|
|
||||||
```
|
|
||||||
java -jar -Xmx15G -Xms15G largeRCRF-executable-1.0-SNAPSHOT.jar settings.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
with `15G` replaced with a little less than your available system memory.
|
|
||||||
|
|
||||||
### I get an `OutOfMemoryException` error and I'm short on RAM
|
|
||||||
|
|
||||||
Try reducing the number of trees being trained simultaneously by reducing the number of threads in the settings file.
|
|
||||||
|
|
||||||
### Training stalls immediately at 0 trees and the CPU is idle
|
|
||||||
|
|
||||||
This issue has been observed before on one particular system (and only on that system) but it's not clear what causes it. If you encounter this, please open an Issue and describe what operating system you're running on, what cloud system (if relevant) you're running on, and the entire output of `java --version`.
|
|
||||||
|
|
||||||
From my observation this issues occurs randomly but only at 0 trees; so as an imperfect workaround you can cancel the training and try again. Another imperfect workaround is to set the number of threads to 1; this causes the code to not use Java's parallel code capabilities which will bypass the problem (at the cost of slower training).
|
|
||||||
|
|
||||||
|
|
|
@ -1,126 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>largeRCRF</artifactId>
|
|
||||||
<groupId>ca.joeltherrien</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>largeRCRF-executable</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<jackson.version>2.9.9</jackson.version>
|
|
||||||
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-csv</artifactId>
|
|
||||||
<version>1.5</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<!--<version>${jackson.version}</version> 2.9.9.1 fixes some vulnerability; other Jackson dependencies are still on 2.9.9-->
|
|
||||||
<version>2.9.9.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
|
||||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
|
||||||
<version>${jackson.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>5.2.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>5.2.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>2.20.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ca.joeltherrien</groupId>
|
|
||||||
<artifactId>largeRCRF-library</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>
|
|
||||||
ca.joeltherrien.randomforest.Main
|
|
||||||
</mainClass>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-pmd-plugin</artifactId>
|
|
||||||
<version>3.11.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<rulesets>
|
|
||||||
<!-- Custom local file system rule set -->
|
|
||||||
<ruleset>${project.basedir}/../pmd-rules.xml</ruleset>
|
|
||||||
</rulesets>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,252 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.covariates.Covariate;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.BooleanCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.FactorCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.NumericCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.CompetingRiskErrorRateCalculator;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.CompetingRiskFunctions;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.CompetingRiskResponse;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.CompetingRiskResponseWithCensorTime;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.combiner.CompetingRiskFunctionCombiner;
|
|
||||||
import ca.joeltherrien.randomforest.tree.Forest;
|
|
||||||
import ca.joeltherrien.randomforest.tree.ForestTrainer;
|
|
||||||
import ca.joeltherrien.randomforest.tree.ResponseCombiner;
|
|
||||||
import ca.joeltherrien.randomforest.tree.TreeTrainer;
|
|
||||||
import ca.joeltherrien.randomforest.utils.CSVUtils;
|
|
||||||
import ca.joeltherrien.randomforest.utils.DataUtils;
|
|
||||||
import ca.joeltherrien.randomforest.utils.StepFunction;
|
|
||||||
import ca.joeltherrien.randomforest.utils.Utils;
|
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import com.fasterxml.jackson.databind.node.TextNode;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
|
||||||
if(args.length < 2){
|
|
||||||
System.out.println("Must provide two arguments - the path to the settings.yaml file and instructions to either train or analyze.");
|
|
||||||
System.out.println("Note that analyzing only supports competing risk data, and that you must then specify a sample size for testing errors.");
|
|
||||||
if(args.length == 0){
|
|
||||||
final File templateFile = new File("template.yaml");
|
|
||||||
if(templateFile.exists()){
|
|
||||||
System.out.println("Template file exists; not creating a new one");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
System.out.println("Generating template file.");
|
|
||||||
defaultTemplate().save(templateFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final File settingsFile = new File(args[0]);
|
|
||||||
final Settings settings = Settings.load(settingsFile);
|
|
||||||
|
|
||||||
final List<Covariate> covariates = settings.getCovariates();
|
|
||||||
|
|
||||||
if(args[1].equalsIgnoreCase("train")){
|
|
||||||
final List<Row<Object>> dataset = CSVUtils.loadData(covariates, settings.getResponseLoader(), settings.getTrainingDataLocation());
|
|
||||||
|
|
||||||
final ForestTrainer forestTrainer = constructForestTrainer(settings, dataset, covariates);
|
|
||||||
|
|
||||||
if(settings.isSaveProgress()){
|
|
||||||
if(settings.getNumberOfThreads() > 1){
|
|
||||||
forestTrainer.trainParallelOnDisk(Optional.empty(), settings.getNumberOfThreads());
|
|
||||||
} else{
|
|
||||||
forestTrainer.trainSerialOnDisk(Optional.empty());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(settings.getNumberOfThreads() > 1){
|
|
||||||
forestTrainer.trainParallelInMemory(Optional.empty(), settings.getNumberOfThreads());
|
|
||||||
} else{
|
|
||||||
forestTrainer.trainSerialInMemory(Optional.empty());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(args[1].equalsIgnoreCase("analyze")){
|
|
||||||
// Perform different prediction measures
|
|
||||||
|
|
||||||
if(args.length < 3){
|
|
||||||
System.out.println("Specify error sample size");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String yVarType = settings.getYVarSettings().get("type").asText();
|
|
||||||
|
|
||||||
if(!yVarType.equalsIgnoreCase("CompetingRiskResponse") && !yVarType.equalsIgnoreCase("CompetingRiskResponseWithCensorTime")){
|
|
||||||
System.out.println("Analyze currently only works on competing risk data");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ResponseCombiner<?, CompetingRiskFunctions> responseCombiner = settings.getTreeCombiner();
|
|
||||||
final int[] events;
|
|
||||||
|
|
||||||
if(responseCombiner instanceof CompetingRiskFunctionCombiner){
|
|
||||||
events = ((CompetingRiskFunctionCombiner) responseCombiner).getEvents();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
System.out.println("Unsupported tree combiner");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Row<CompetingRiskResponse>> dataset = CSVUtils.loadData(covariates, settings.getResponseLoader(), settings.getValidationDataLocation());
|
|
||||||
|
|
||||||
// Let's reduce this down to n
|
|
||||||
final int n = Integer.parseInt(args[2]);
|
|
||||||
Utils.reduceListToSize(dataset, n, new Random());
|
|
||||||
|
|
||||||
final File folder = new File(settings.getSaveTreeLocation());
|
|
||||||
final Forest<?, CompetingRiskFunctions> forest = DataUtils.loadOnlineForest(folder, responseCombiner);
|
|
||||||
|
|
||||||
final boolean useBootstrapPredictions = settings.getTrainingDataLocation().equals(settings.getValidationDataLocation());
|
|
||||||
|
|
||||||
if(useBootstrapPredictions){
|
|
||||||
System.out.println("Finished loading trees + dataset; creating calculator and evaluating OOB predictions");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
System.out.println("Finished loading trees + dataset; creating calculator and evaluating predictions");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final CompetingRiskErrorRateCalculator errorRateCalculator = new CompetingRiskErrorRateCalculator(dataset, forest, useBootstrapPredictions);
|
|
||||||
final PrintWriter printWriter = new PrintWriter(settings.getSaveTreeLocation() + "/errors.txt");
|
|
||||||
|
|
||||||
System.out.println("Running Naive Concordance");
|
|
||||||
|
|
||||||
final double[] naiveConcordance = errorRateCalculator.calculateConcordance(events);
|
|
||||||
printWriter.write("Naive concordance:\n");
|
|
||||||
for(int i=0; i<events.length; i++){
|
|
||||||
printWriter.write('\t');
|
|
||||||
printWriter.write(Integer.toString(events[i]));
|
|
||||||
printWriter.write(": ");
|
|
||||||
printWriter.write(Double.toString(naiveConcordance[i]));
|
|
||||||
printWriter.write('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(yVarType.equalsIgnoreCase("CompetingRiskResponseWithCensorTime")){
|
|
||||||
System.out.println("Running IPCW Concordance - creating censor distribution");
|
|
||||||
|
|
||||||
final double[] censorTimes = dataset.stream()
|
|
||||||
.mapToDouble(row -> ((CompetingRiskResponseWithCensorTime) row.getResponse()).getC())
|
|
||||||
.toArray();
|
|
||||||
final StepFunction censorDistribution = Utils.estimateOneMinusECDF(censorTimes);
|
|
||||||
|
|
||||||
System.out.println("Finished generating censor distribution - running concordance");
|
|
||||||
|
|
||||||
final double[] ipcwConcordance = errorRateCalculator.calculateIPCWConcordance(events, censorDistribution);
|
|
||||||
printWriter.write("IPCW concordance:\n");
|
|
||||||
for(int i=0; i<events.length; i++){
|
|
||||||
printWriter.write('\t');
|
|
||||||
printWriter.write(Integer.toString(events[i]));
|
|
||||||
printWriter.write(": ");
|
|
||||||
printWriter.write(Double.toString(ipcwConcordance[i]));
|
|
||||||
printWriter.write('\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
printWriter.close();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
System.out.println("Invalid instruction; use either train or analyze.");
|
|
||||||
System.out.println("Note that analyzing only supports competing risk data.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ForestTrainer constructForestTrainer(final Settings settings, final List<Row<Object>> data, final List<Covariate> covariates){
|
|
||||||
|
|
||||||
return ForestTrainer.builder()
|
|
||||||
.ntree(settings.getNtree())
|
|
||||||
.data(data)
|
|
||||||
.displayProgress(true)
|
|
||||||
.saveTreeLocation(settings.getSaveTreeLocation())
|
|
||||||
.covariates(covariates)
|
|
||||||
.treeResponseCombiner(settings.getTreeCombiner())
|
|
||||||
.treeTrainer(constructTreeTrainer(settings, covariates))
|
|
||||||
.randomSeed(settings.getRandomSeed() != null ? settings.getRandomSeed() : System.nanoTime())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TreeTrainer constructTreeTrainer(final Settings settings, final List<Covariate> covariates) {
|
|
||||||
|
|
||||||
return TreeTrainer.builder()
|
|
||||||
.numberOfSplits(settings.getNumberOfSplits())
|
|
||||||
.nodeSize(settings.getNodeSize())
|
|
||||||
.maxNodeDepth(settings.getMaxNodeDepth())
|
|
||||||
.mtry(settings.getMtry())
|
|
||||||
.checkNodePurity(settings.isCheckNodePurity())
|
|
||||||
.responseCombiner(settings.getResponseCombiner())
|
|
||||||
.splitFinder(settings.getSplitFinder())
|
|
||||||
.covariates(covariates)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Settings defaultTemplate(){
|
|
||||||
|
|
||||||
final ObjectNode splitFinderSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
splitFinderSettings.set("type", new TextNode("WeightedVarianceSplitFinder"));
|
|
||||||
|
|
||||||
final ObjectNode responseCombinerSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
responseCombinerSettings.set("type", new TextNode("MeanResponseCombiner"));
|
|
||||||
|
|
||||||
final ObjectNode treeCombinerSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
treeCombinerSettings.set("type", new TextNode("MeanResponseCombiner"));
|
|
||||||
|
|
||||||
final ObjectNode yVarSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
yVarSettings.set("type", new TextNode("Double"));
|
|
||||||
yVarSettings.set("name", new TextNode("y"));
|
|
||||||
|
|
||||||
return Settings.builder()
|
|
||||||
.covariateSettings(Utils.easyList(
|
|
||||||
new NumericCovariateSettings("x1", true),
|
|
||||||
new BooleanCovariateSettings("x2", false),
|
|
||||||
new FactorCovariateSettings("x3", Utils.easyList("cat", "mouse", "dog"), true)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.trainingDataLocation("training_data.csv")
|
|
||||||
.validationDataLocation("validation_data.csv")
|
|
||||||
.responseCombinerSettings(responseCombinerSettings)
|
|
||||||
.treeCombinerSettings(treeCombinerSettings)
|
|
||||||
.splitFinderSettings(splitFinderSettings)
|
|
||||||
.yVarSettings(yVarSettings)
|
|
||||||
.maxNodeDepth(100000)
|
|
||||||
.mtry(2)
|
|
||||||
.nodeSize(5)
|
|
||||||
.ntree(500)
|
|
||||||
.numberOfSplits(5)
|
|
||||||
.numberOfThreads(1)
|
|
||||||
.saveProgress(true)
|
|
||||||
.saveTreeLocation("trees/")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,247 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.covariates.Covariate;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.CovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.loaders.CompetingResponseLoader;
|
|
||||||
import ca.joeltherrien.randomforest.loaders.CompetingResponseWithCensorTimeLoader;
|
|
||||||
import ca.joeltherrien.randomforest.loaders.DoubleLoader;
|
|
||||||
import ca.joeltherrien.randomforest.loaders.ResponseLoader;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.combiner.CompetingRiskFunctionCombiner;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.combiner.CompetingRiskResponseCombiner;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.splitfinder.GrayLogRankSplitFinder;
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.splitfinder.LogRankSplitFinder;
|
|
||||||
import ca.joeltherrien.randomforest.responses.regression.MeanResponseCombiner;
|
|
||||||
import ca.joeltherrien.randomforest.responses.regression.WeightedVarianceSplitFinder;
|
|
||||||
import ca.joeltherrien.randomforest.tree.ForestResponseCombiner;
|
|
||||||
import ca.joeltherrien.randomforest.tree.ResponseCombiner;
|
|
||||||
import ca.joeltherrien.randomforest.tree.SplitFinder;
|
|
||||||
import ca.joeltherrien.randomforest.utils.JsonUtils;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is saved & loaded using a saved configuration file. It contains all relevant settings when training a forest.
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class Settings {
|
|
||||||
|
|
||||||
private static Map<String, Function<ObjectNode, ResponseLoader>> RESPONSE_LOADER_MAP = new HashMap<>();
|
|
||||||
public static Function<ObjectNode, ResponseLoader> getResponseLoaderConstructor(final String name){
|
|
||||||
return RESPONSE_LOADER_MAP.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
public static void registerResponseLoaderConstructor(final String name, final Function<ObjectNode, ResponseLoader> responseLoaderConstructor){
|
|
||||||
RESPONSE_LOADER_MAP.put(name.toLowerCase(), responseLoaderConstructor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static{
|
|
||||||
registerResponseLoaderConstructor("double",
|
|
||||||
node -> new DoubleLoader(node)
|
|
||||||
);
|
|
||||||
registerResponseLoaderConstructor("CompetingRiskResponse",
|
|
||||||
node -> new CompetingResponseLoader(node)
|
|
||||||
);
|
|
||||||
registerResponseLoaderConstructor("CompetingRiskResponseWithCensorTime",
|
|
||||||
node -> new CompetingResponseWithCensorTimeLoader(node)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, Function<ObjectNode, SplitFinder>> SPLIT_FINDER_MAP = new HashMap<>();
|
|
||||||
public static Function<ObjectNode, SplitFinder> getSplitFinderConstructor(final String name){
|
|
||||||
return SPLIT_FINDER_MAP.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
public static void registerSplitFinderConstructor(final String name, final Function<ObjectNode, SplitFinder> splitFinderConstructor){
|
|
||||||
SPLIT_FINDER_MAP.put(name.toLowerCase(), splitFinderConstructor);
|
|
||||||
}
|
|
||||||
static{
|
|
||||||
registerSplitFinderConstructor("WeightedVarianceSplitFinder",
|
|
||||||
(node) -> new WeightedVarianceSplitFinder()
|
|
||||||
);
|
|
||||||
registerSplitFinderConstructor("GrayLogRankSplitFinder",
|
|
||||||
(objectNode) -> {
|
|
||||||
final int[] eventsOfFocusArray = JsonUtils.jsonToIntArray(objectNode.get("eventsOfFocus"));
|
|
||||||
final int[] eventArray = JsonUtils.jsonToIntArray(objectNode.get("events"));
|
|
||||||
|
|
||||||
return new GrayLogRankSplitFinder(eventsOfFocusArray, eventArray);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
registerSplitFinderConstructor("LogRankSplitFinder",
|
|
||||||
(objectNode) -> {
|
|
||||||
final int[] eventsOfFocusArray = JsonUtils.jsonToIntArray(objectNode.get("eventsOfFocus"));
|
|
||||||
final int[] eventArray = JsonUtils.jsonToIntArray(objectNode.get("events"));
|
|
||||||
|
|
||||||
return new LogRankSplitFinder(eventsOfFocusArray, eventArray);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static Map<String, Function<ObjectNode, ResponseCombiner>> RESPONSE_COMBINER_MAP = new HashMap<>();
|
|
||||||
private static Map<String, Function<ObjectNode, ForestResponseCombiner>> FOREST_RESPONSE_COMBINER_MAP = new HashMap<>();
|
|
||||||
|
|
||||||
public static Function<ObjectNode, ResponseCombiner> getResponseCombinerConstructor(final String name){
|
|
||||||
return RESPONSE_COMBINER_MAP.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
public static void registerResponseCombinerConstructor(final String name, final Function<ObjectNode, ResponseCombiner> responseCombinerConstructor){
|
|
||||||
RESPONSE_COMBINER_MAP.put(name.toLowerCase(), responseCombinerConstructor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Function<ObjectNode, ForestResponseCombiner> getForestResponseCombinerConstructor(final String name){
|
|
||||||
return FOREST_RESPONSE_COMBINER_MAP.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
public static void registerForestResponseCombinerConstructor(final String name, final Function<ObjectNode, ForestResponseCombiner> responseCombinerConstructor){
|
|
||||||
FOREST_RESPONSE_COMBINER_MAP.put(name.toLowerCase(), responseCombinerConstructor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static{
|
|
||||||
|
|
||||||
registerResponseCombinerConstructor("MeanResponseCombiner",
|
|
||||||
(node) -> new MeanResponseCombiner()
|
|
||||||
);
|
|
||||||
registerForestResponseCombinerConstructor("MeanResponseCombiner",
|
|
||||||
(node) -> new MeanResponseCombiner()
|
|
||||||
);
|
|
||||||
registerResponseCombinerConstructor("CompetingRiskResponseCombiner",
|
|
||||||
(node) -> {
|
|
||||||
final int[] events = JsonUtils.jsonToIntArray(node.get("events"));
|
|
||||||
|
|
||||||
return new CompetingRiskResponseCombiner(events);
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
registerForestResponseCombinerConstructor("CompetingRiskFunctionCombiner",
|
|
||||||
(node) -> {
|
|
||||||
final int[] events = JsonUtils.jsonToIntArray(node.get("events"));
|
|
||||||
|
|
||||||
double[] times = null;
|
|
||||||
if(node.hasNonNull("times")){
|
|
||||||
times = JsonUtils.jsonToDoubleArray(node.get("times"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CompetingRiskFunctionCombiner(events, times);
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int numberOfSplits = 5;
|
|
||||||
private int nodeSize = 5;
|
|
||||||
private int maxNodeDepth = 1000000; // basically no maxNodeDepth
|
|
||||||
private boolean checkNodePurity = false;
|
|
||||||
private Long randomSeed;
|
|
||||||
|
|
||||||
private ObjectNode responseCombinerSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
private ObjectNode splitFinderSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
private ObjectNode treeCombinerSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
|
|
||||||
private List<CovariateSettings> covariateSettings = new ArrayList<>();
|
|
||||||
private ObjectNode yVarSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
|
|
||||||
// number of covariates to randomly try
|
|
||||||
private int mtry = 0;
|
|
||||||
|
|
||||||
// number of trees to try
|
|
||||||
private int ntree = 500;
|
|
||||||
|
|
||||||
private String trainingDataLocation = "data.csv";
|
|
||||||
private String validationDataLocation = "data.csv";
|
|
||||||
private String saveTreeLocation = "trees/";
|
|
||||||
|
|
||||||
private int numberOfThreads = 1;
|
|
||||||
private boolean saveProgress = false;
|
|
||||||
|
|
||||||
public Settings(){
|
|
||||||
} // required for Jackson
|
|
||||||
|
|
||||||
public static Settings load(File file) throws IOException {
|
|
||||||
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
|
||||||
//mapper.enableDefaultTyping();
|
|
||||||
|
|
||||||
return mapper.readValue(file, Settings.class);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(File file) throws IOException {
|
|
||||||
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
|
||||||
//mapper.enableDefaultTyping();
|
|
||||||
|
|
||||||
// Jackson can struggle with some types of Lists, such as that returned by the useful List.of(...)
|
|
||||||
this.covariateSettings = new ArrayList<>(this.covariateSettings);
|
|
||||||
|
|
||||||
mapper.writeValue(file, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
public SplitFinder getSplitFinder(){
|
|
||||||
final String type = splitFinderSettings.get("type").asText();
|
|
||||||
|
|
||||||
return getSplitFinderConstructor(type).apply(splitFinderSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
public ResponseLoader getResponseLoader(){
|
|
||||||
final String type = yVarSettings.get("type").asText();
|
|
||||||
|
|
||||||
return getResponseLoaderConstructor(type).apply(yVarSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
public ResponseCombiner getResponseCombiner(){
|
|
||||||
final String type = responseCombinerSettings.get("type").asText();
|
|
||||||
|
|
||||||
return getResponseCombinerConstructor(type).apply(responseCombinerSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
public ForestResponseCombiner getTreeCombiner(){
|
|
||||||
final String type = treeCombinerSettings.get("type").asText();
|
|
||||||
|
|
||||||
return getForestResponseCombinerConstructor(type).apply(treeCombinerSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
public List<Covariate> getCovariates(){
|
|
||||||
final List<CovariateSettings> covariateSettingsList = this.getCovariateSettings();
|
|
||||||
final List<Covariate> covariates = new ArrayList<>(covariateSettingsList.size());
|
|
||||||
for(int i = 0; i < covariateSettingsList.size(); i++){
|
|
||||||
covariates.add(covariateSettingsList.get(i).build(i));
|
|
||||||
}
|
|
||||||
return covariates;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.covariates.settings;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.covariates.bool.BooleanCovariate;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@NoArgsConstructor // required by Jackson
|
|
||||||
@Data
|
|
||||||
public final class BooleanCovariateSettings extends CovariateSettings<Boolean> {
|
|
||||||
|
|
||||||
public BooleanCovariateSettings(String name, boolean naSplitPenalty){
|
|
||||||
super(name, naSplitPenalty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BooleanCovariate build(int index) {
|
|
||||||
return new BooleanCovariate(name, index, naSplitPenalty);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.covariates.settings;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.covariates.Covariate;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Nuisance class to work with Jackson for persisting settings.
|
|
||||||
*
|
|
||||||
* @param <V>
|
|
||||||
*/
|
|
||||||
@NoArgsConstructor // required for Jackson
|
|
||||||
@Getter
|
|
||||||
@JsonTypeInfo(
|
|
||||||
use = JsonTypeInfo.Id.NAME,
|
|
||||||
property = "type")
|
|
||||||
@JsonSubTypes({
|
|
||||||
@JsonSubTypes.Type(value = BooleanCovariateSettings.class, name = "boolean"),
|
|
||||||
@JsonSubTypes.Type(value = NumericCovariateSettings.class, name = "numeric"),
|
|
||||||
@JsonSubTypes.Type(value = FactorCovariateSettings.class, name = "factor")
|
|
||||||
})
|
|
||||||
public abstract class CovariateSettings<V> {
|
|
||||||
|
|
||||||
String name;
|
|
||||||
boolean naSplitPenalty;
|
|
||||||
|
|
||||||
CovariateSettings(String name, boolean naSplitPenalty){
|
|
||||||
this.name = name;
|
|
||||||
this.naSplitPenalty = naSplitPenalty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Covariate<V> build(int index);
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.covariates.settings;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.covariates.factor.FactorCovariate;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@NoArgsConstructor // required by Jackson
|
|
||||||
@Data
|
|
||||||
public final class FactorCovariateSettings extends CovariateSettings<String> {
|
|
||||||
|
|
||||||
private List<String> levels;
|
|
||||||
|
|
||||||
public FactorCovariateSettings(String name, List<String> levels, boolean naSplitPenalty){
|
|
||||||
super(name, naSplitPenalty);
|
|
||||||
this.levels = new ArrayList<>(levels); // Jackson struggles with List.of(...)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FactorCovariate build(int index) {
|
|
||||||
return new FactorCovariate(name, index, levels, naSplitPenalty);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.covariates.settings;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.covariates.numeric.NumericCovariate;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@NoArgsConstructor // required by Jackson
|
|
||||||
@Data
|
|
||||||
public final class NumericCovariateSettings extends CovariateSettings<Double> {
|
|
||||||
|
|
||||||
public NumericCovariateSettings(String name, boolean naSplitPenalty){
|
|
||||||
super(name, naSplitPenalty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NumericCovariate build(int index) {
|
|
||||||
return new NumericCovariate(name, index, naSplitPenalty);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.loaders;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.CompetingRiskResponse;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.apache.commons.csv.CSVRecord;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class CompetingResponseLoader implements ResponseLoader<CompetingRiskResponse> {
|
|
||||||
|
|
||||||
private final String deltaName;
|
|
||||||
private final String uName;
|
|
||||||
|
|
||||||
public CompetingResponseLoader(ObjectNode node){
|
|
||||||
this.deltaName = node.get("delta").asText();
|
|
||||||
this.uName = node.get("u").asText();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompetingRiskResponse parse(CSVRecord record) {
|
|
||||||
final int delta = Integer.parseInt(record.get(deltaName));
|
|
||||||
final double u = Double.parseDouble(record.get(uName));
|
|
||||||
|
|
||||||
return new CompetingRiskResponse(delta, u);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.loaders;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.responses.competingrisk.CompetingRiskResponseWithCensorTime;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.apache.commons.csv.CSVRecord;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class CompetingResponseWithCensorTimeLoader implements ResponseLoader<CompetingRiskResponseWithCensorTime>{
|
|
||||||
|
|
||||||
private final String deltaName;
|
|
||||||
private final String uName;
|
|
||||||
private final String cName;
|
|
||||||
|
|
||||||
public CompetingResponseWithCensorTimeLoader(ObjectNode node){
|
|
||||||
this.deltaName = node.get("delta").asText();
|
|
||||||
this.uName = node.get("u").asText();
|
|
||||||
this.cName = node.get("c").asText();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompetingRiskResponseWithCensorTime parse(CSVRecord record) {
|
|
||||||
final int delta = Integer.parseInt(record.get(deltaName));
|
|
||||||
final double u = Double.parseDouble(record.get(uName));
|
|
||||||
final double c = Double.parseDouble(record.get(cName));
|
|
||||||
|
|
||||||
return new CompetingRiskResponseWithCensorTime(delta, u, c);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.loaders;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.apache.commons.csv.CSVRecord;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class DoubleLoader implements ResponseLoader<Double> {
|
|
||||||
|
|
||||||
private final String yName;
|
|
||||||
|
|
||||||
public DoubleLoader(final ObjectNode node){
|
|
||||||
this.yName = node.get("name").asText();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Double parse(CSVRecord record) {
|
|
||||||
return Double.parseDouble(record.get(yName));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.loaders;
|
|
||||||
|
|
||||||
import org.apache.commons.csv.CSVRecord;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface ResponseLoader<Y> {
|
|
||||||
|
|
||||||
Y parse(CSVRecord record);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.utils;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.Row;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.Covariate;
|
|
||||||
import ca.joeltherrien.randomforest.loaders.ResponseLoader;
|
|
||||||
import org.apache.commons.csv.CSVFormat;
|
|
||||||
import org.apache.commons.csv.CSVParser;
|
|
||||||
import org.apache.commons.csv.CSVRecord;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
public class CSVUtils {
|
|
||||||
|
|
||||||
public static <Y> List<Row<Y>> loadData(final List<Covariate> covariates, final ResponseLoader<Y> responseLoader, String filename) throws IOException {
|
|
||||||
|
|
||||||
final List<Row<Y>> dataset = new ArrayList<>();
|
|
||||||
|
|
||||||
final Reader input;
|
|
||||||
if(filename.endsWith(".gz")){
|
|
||||||
final FileInputStream inputStream = new FileInputStream(filename);
|
|
||||||
final GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);
|
|
||||||
|
|
||||||
input = new InputStreamReader(gzipInputStream);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
input = new FileReader(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final CSVParser parser = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(input);
|
|
||||||
|
|
||||||
|
|
||||||
int id = 1;
|
|
||||||
for(final CSVRecord record : parser){
|
|
||||||
final Covariate.Value[] valueArray = new Covariate.Value[covariates.size()];
|
|
||||||
|
|
||||||
for(final Covariate<?> covariate : covariates){
|
|
||||||
valueArray[covariate.getIndex()] = covariate.createValue(record.get(covariate.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
final Y y = responseLoader.parse(record);
|
|
||||||
|
|
||||||
dataset.add(new Row<>(valueArray, id++, y));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataset;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.utils;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class JsonUtils {
|
|
||||||
|
|
||||||
public static int[] jsonToIntArray(final JsonNode node){
|
|
||||||
final Iterator<JsonNode> elements = node.elements();
|
|
||||||
final List<JsonNode> elementList = new ArrayList<>();
|
|
||||||
elements.forEachRemaining(n -> elementList.add(n));
|
|
||||||
|
|
||||||
final int[] array = elementList.stream().mapToInt(n -> n.asInt()).toArray();
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double[] jsonToDoubleArray(final JsonNode node){
|
|
||||||
final Iterator<JsonNode> elements = node.elements();
|
|
||||||
final List<JsonNode> elementList = new ArrayList<>();
|
|
||||||
elements.forEachRemaining(n -> elementList.add(n));
|
|
||||||
|
|
||||||
final double[] array = elementList.stream().mapToDouble(n -> n.asDouble()).toArray();
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.BooleanCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.FactorCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.NumericCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.utils.Utils;
|
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import com.fasterxml.jackson.databind.node.TextNode;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class TestPersistence {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSaving() throws IOException {
|
|
||||||
final ObjectNode splitFinderSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
splitFinderSettings.set("type", new TextNode("WeightedVarianceSplitFinder"));
|
|
||||||
|
|
||||||
final ObjectNode responseCombinerSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
responseCombinerSettings.set("type", new TextNode("MeanResponseCombiner"));
|
|
||||||
|
|
||||||
final ObjectNode treeCombinerSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
treeCombinerSettings.set("type", new TextNode("MeanResponseCombiner"));
|
|
||||||
|
|
||||||
final ObjectNode yVarSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
yVarSettings.set("type", new TextNode("Double"));
|
|
||||||
yVarSettings.set("name", new TextNode("y"));
|
|
||||||
|
|
||||||
final Settings settingsOriginal = Settings.builder()
|
|
||||||
.covariateSettings(Utils.easyList(
|
|
||||||
new NumericCovariateSettings("x1", true),
|
|
||||||
new BooleanCovariateSettings("x2", false),
|
|
||||||
new FactorCovariateSettings("x3", Utils.easyList("cat", "mouse", "dog"), true)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.trainingDataLocation("training_data.csv")
|
|
||||||
.validationDataLocation("validation_data.csv")
|
|
||||||
.responseCombinerSettings(responseCombinerSettings)
|
|
||||||
.treeCombinerSettings(treeCombinerSettings)
|
|
||||||
.splitFinderSettings(splitFinderSettings)
|
|
||||||
.yVarSettings(yVarSettings)
|
|
||||||
.maxNodeDepth(100000)
|
|
||||||
.mtry(2)
|
|
||||||
.nodeSize(5)
|
|
||||||
.ntree(500)
|
|
||||||
.numberOfSplits(5)
|
|
||||||
.numberOfThreads(1)
|
|
||||||
.saveProgress(true)
|
|
||||||
.saveTreeLocation("trees/")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
final File templateFile = new File("template.yaml");
|
|
||||||
settingsOriginal.save(templateFile);
|
|
||||||
|
|
||||||
final Settings reloadedSettings = Settings.load(templateFile);
|
|
||||||
|
|
||||||
assertEquals(settingsOriginal, reloadedSettings);
|
|
||||||
|
|
||||||
//templateFile.delete();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Joel Therrien.
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ca.joeltherrien.randomforest.csv;
|
|
||||||
|
|
||||||
import ca.joeltherrien.randomforest.Row;
|
|
||||||
import ca.joeltherrien.randomforest.Settings;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.Covariate;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.BooleanCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.FactorCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.covariates.settings.NumericCovariateSettings;
|
|
||||||
import ca.joeltherrien.randomforest.loaders.ResponseLoader;
|
|
||||||
import ca.joeltherrien.randomforest.utils.CSVUtils;
|
|
||||||
import ca.joeltherrien.randomforest.utils.Utils;
|
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import com.fasterxml.jackson.databind.node.TextNode;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
public class TestLoadingCSV {
|
|
||||||
|
|
||||||
/*
|
|
||||||
y,x1,x2,x3
|
|
||||||
5,3.0,"mouse",true
|
|
||||||
2,1.0,"dog",false
|
|
||||||
9,1.5,"cat",true
|
|
||||||
-3,NA,NA,NA
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
public List<Row<Double>> loadData(String filename) throws IOException {
|
|
||||||
final ObjectNode yVarSettings = new ObjectNode(JsonNodeFactory.instance);
|
|
||||||
yVarSettings.set("type", new TextNode("Double"));
|
|
||||||
yVarSettings.set("name", new TextNode("y"));
|
|
||||||
|
|
||||||
final Settings settings = Settings.builder()
|
|
||||||
.trainingDataLocation(filename)
|
|
||||||
.covariateSettings(
|
|
||||||
Utils.easyList(new NumericCovariateSettings("x1", true),
|
|
||||||
new FactorCovariateSettings("x2", Utils.easyList("dog", "cat", "mouse"), false),
|
|
||||||
new BooleanCovariateSettings("x3", true))
|
|
||||||
)
|
|
||||||
.yVarSettings(yVarSettings)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
final List<Covariate> covariates = settings.getCovariates();
|
|
||||||
|
|
||||||
|
|
||||||
final ResponseLoader loader = settings.getResponseLoader();
|
|
||||||
|
|
||||||
return CSVUtils.loadData(covariates, loader, settings.getTrainingDataLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLoadingNormal(final List<Covariate> covariates) throws IOException {
|
|
||||||
final List<Row<Double>> data = loadData("src/test/resources/testCSV.csv");
|
|
||||||
|
|
||||||
assertData(data, covariates);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLoadingGz(final List<Covariate> covariates) throws IOException {
|
|
||||||
final List<Row<Double>> data = loadData("src/test/resources/testCSV.csv.gz");
|
|
||||||
|
|
||||||
assertData(data, covariates);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void assertData(final List<Row<Double>> data, final List<Covariate> covariates){
|
|
||||||
final Covariate x1 = covariates.get(0);
|
|
||||||
final Covariate x2 = covariates.get(0);
|
|
||||||
final Covariate x3 = covariates.get(0);
|
|
||||||
|
|
||||||
assertEquals(4, data.size());
|
|
||||||
|
|
||||||
Row<Double> row = data.get(0);
|
|
||||||
assertEquals(5.0, (double)row.getResponse());
|
|
||||||
assertEquals(3.0, row.getCovariateValue(x1).getValue());
|
|
||||||
assertEquals("mouse", row.getCovariateValue(x2).getValue());
|
|
||||||
assertEquals(true, row.getCovariateValue(x3).getValue());
|
|
||||||
|
|
||||||
row = data.get(1);
|
|
||||||
assertEquals(2.0, (double)row.getResponse());
|
|
||||||
assertEquals(1.0, row.getCovariateValue(x1).getValue());
|
|
||||||
assertEquals("dog", row.getCovariateValue(x2).getValue());
|
|
||||||
assertEquals(false, row.getCovariateValue(x3).getValue());
|
|
||||||
|
|
||||||
row = data.get(2);
|
|
||||||
assertEquals(9.0, (double)row.getResponse());
|
|
||||||
assertEquals(1.5, row.getCovariateValue(x1).getValue());
|
|
||||||
assertEquals("cat", row.getCovariateValue(x2).getValue());
|
|
||||||
assertEquals(true, row.getCovariateValue(x3).getValue());
|
|
||||||
|
|
||||||
row = data.get(3);
|
|
||||||
assertEquals(-3.0, (double)row.getResponse());
|
|
||||||
assertTrue(row.getCovariateValue(x1).isNA());
|
|
||||||
assertTrue(row.getCovariateValue(x2).isNA());
|
|
||||||
assertTrue(row.getCovariateValue(x3).isNA());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
102
library/pom.xml
102
library/pom.xml
|
@ -1,102 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>largeRCRF-library</artifactId>
|
|
||||||
|
|
||||||
<!-- parent pom -->
|
|
||||||
<parent>
|
|
||||||
<groupId>ca.joeltherrien</groupId>
|
|
||||||
<artifactId>largeRCRF</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-csv</artifactId>
|
|
||||||
<version>1.5</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>5.2.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>5.2.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>2.20.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-pmd-plugin</artifactId>
|
|
||||||
<version>3.11.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<rulesets>
|
|
||||||
<!-- Custom local file system rule set -->
|
|
||||||
<ruleset>${project.basedir}/../pmd-rules.xml</ruleset>
|
|
||||||
</rulesets>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
105
pom.xml
105
pom.xml
|
@ -1,21 +1,98 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<!-- parent pom -->
|
<groupId>ca.joeltherrien.ca</groupId>
|
||||||
<groupId>ca.joeltherrien</groupId>
|
<artifactId>largeRCRF-library</artifactId>
|
||||||
<artifactId>largeRCRF</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
|
||||||
|
|
||||||
<!-- sub modules -->
|
<properties>
|
||||||
<modules>
|
<java.version>1.8</java.version>
|
||||||
<module>library</module>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<module>executable</module>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
</modules>
|
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-csv</artifactId>
|
||||||
|
<version>1.5</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>5.2.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.2.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>2.20.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-pmd-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<rulesets>
|
||||||
|
<!-- Custom local file system rule set -->
|
||||||
|
<ruleset>pmd-rules.xml</ruleset>
|
||||||
|
</rulesets>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue