From 949c8789e7cb45103aed6cabd9f90cbc3d17c60e Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Mon, 27 Aug 2018 19:15:06 -0700 Subject: [PATCH] Switch HashMaps in CompetingRiskFunctions for ArrayLists Provides a mild performance improvement. --- .../competingrisk/CompetingRiskFunctions.java | 9 +++++---- .../combiner/CompetingRiskFunctionCombiner.java | 13 +++++++------ .../combiner/CompetingRiskResponseCombiner.java | 12 ++++++------ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java b/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java index 2e6baf9..4aa4470 100644 --- a/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java +++ b/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java @@ -6,23 +6,24 @@ import lombok.Builder; import lombok.Getter; import java.io.Serializable; +import java.util.List; import java.util.Map; @Builder public class CompetingRiskFunctions implements Serializable { - private final Map causeSpecificHazardFunctionMap; - private final Map cumulativeIncidenceFunctionMap; + private final List causeSpecificHazards; + private final List cumulativeIncidenceCurves; @Getter private final MathFunction survivalCurve; public MathFunction getCauseSpecificHazardFunction(int cause){ - return causeSpecificHazardFunctionMap.get(cause); + return causeSpecificHazards.get(cause-1); } public MathFunction getCumulativeIncidenceFunction(int cause) { - return cumulativeIncidenceFunctionMap.get(cause); + return cumulativeIncidenceCurves.get(cause-1); } public double calculateEventSpecificMortality(final int event, final double tau){ diff --git a/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java b/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java index 8da1d91..ed5fff2 100644 --- a/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java +++ b/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java @@ -55,8 +55,9 @@ public class CompetingRiskFunctionCombiner implements ResponseCombiner causeSpecificCumulativeHazardFunctionMap = new HashMap<>(); - final Map cumulativeIncidenceFunctionMap = new HashMap<>(); + + final List causeSpecificCumulativeHazardFunctionList = new ArrayList<>(events.length); + final List cumulativeIncidenceFunctionList = new ArrayList<>(events.length); for(final int event : events){ @@ -78,14 +79,14 @@ public class CompetingRiskFunctionCombiner implements ResponseCombiner responses) { - final Map causeSpecificCumulativeHazardFunctionMap = new HashMap<>(); - final Map cumulativeIncidenceFunctionMap = new HashMap<>(); + final List causeSpecificCumulativeHazardFunctionList = new ArrayList<>(events.length); + final List cumulativeIncidenceFunctionList = new ArrayList<>(events.length); final double[] timesToUse; if(times != null){ @@ -103,16 +103,16 @@ public class CompetingRiskResponseCombiner implements ResponseCombiner