Switch HashMaps in CompetingRiskFunctions for ArrayLists

Provides a mild performance improvement.
This commit is contained in:
Joel Therrien 2018-08-27 19:15:06 -07:00
parent 22944115ee
commit 949c8789e7
3 changed files with 18 additions and 16 deletions

View file

@ -6,23 +6,24 @@ import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import java.util.Map; import java.util.Map;
@Builder @Builder
public class CompetingRiskFunctions implements Serializable { public class CompetingRiskFunctions implements Serializable {
private final Map<Integer, MathFunction> causeSpecificHazardFunctionMap; private final List<MathFunction> causeSpecificHazards;
private final Map<Integer, MathFunction> cumulativeIncidenceFunctionMap; private final List<MathFunction> cumulativeIncidenceCurves;
@Getter @Getter
private final MathFunction survivalCurve; private final MathFunction survivalCurve;
public MathFunction getCauseSpecificHazardFunction(int cause){ public MathFunction getCauseSpecificHazardFunction(int cause){
return causeSpecificHazardFunctionMap.get(cause); return causeSpecificHazards.get(cause-1);
} }
public MathFunction getCumulativeIncidenceFunction(int cause) { public MathFunction getCumulativeIncidenceFunction(int cause) {
return cumulativeIncidenceFunctionMap.get(cause); return cumulativeIncidenceCurves.get(cause-1);
} }
public double calculateEventSpecificMortality(final int event, final double tau){ public double calculateEventSpecificMortality(final int event, final double tau){

View file

@ -55,8 +55,9 @@ public class CompetingRiskFunctionCombiner implements ResponseCombiner<Competing
} }
final MathFunction survivalFunction = new MathFunction(survivalPoints, new Point(0.0, 1.0)); final MathFunction survivalFunction = new MathFunction(survivalPoints, new Point(0.0, 1.0));
final Map<Integer, MathFunction> causeSpecificCumulativeHazardFunctionMap = new HashMap<>();
final Map<Integer, MathFunction> cumulativeIncidenceFunctionMap = new HashMap<>(); final List<MathFunction> causeSpecificCumulativeHazardFunctionList = new ArrayList<>(events.length);
final List<MathFunction> cumulativeIncidenceFunctionList = new ArrayList<>(events.length);
for(final int event : events){ for(final int event : events){
@ -78,14 +79,14 @@ public class CompetingRiskFunctionCombiner implements ResponseCombiner<Competing
} }
causeSpecificCumulativeHazardFunctionMap.put(event, new MathFunction(cumulativeHazardFunctionPoints)); causeSpecificCumulativeHazardFunctionList.add(event-1, new MathFunction(cumulativeHazardFunctionPoints));
cumulativeIncidenceFunctionMap.put(event, new MathFunction(cumulativeIncidenceFunctionPoints)); cumulativeIncidenceFunctionList.add(event-1, new MathFunction(cumulativeIncidenceFunctionPoints));
} }
return CompetingRiskFunctions.builder() return CompetingRiskFunctions.builder()
.causeSpecificHazardFunctionMap(causeSpecificCumulativeHazardFunctionMap) .causeSpecificHazards(causeSpecificCumulativeHazardFunctionList)
.cumulativeIncidenceFunctionMap(cumulativeIncidenceFunctionMap) .cumulativeIncidenceCurves(cumulativeIncidenceFunctionList)
.survivalCurve(survivalFunction) .survivalCurve(survivalFunction)
.build(); .build();
} }

View file

@ -33,8 +33,8 @@ public class CompetingRiskResponseCombiner implements ResponseCombiner<Competing
@Override @Override
public CompetingRiskFunctions combine(List<CompetingRiskResponse> responses) { public CompetingRiskFunctions combine(List<CompetingRiskResponse> responses) {
final Map<Integer, MathFunction> causeSpecificCumulativeHazardFunctionMap = new HashMap<>(); final List<MathFunction> causeSpecificCumulativeHazardFunctionList = new ArrayList<>(events.length);
final Map<Integer, MathFunction> cumulativeIncidenceFunctionMap = new HashMap<>(); final List<MathFunction> cumulativeIncidenceFunctionList = new ArrayList<>(events.length);
final double[] timesToUse; final double[] timesToUse;
if(times != null){ if(times != null){
@ -103,16 +103,16 @@ public class CompetingRiskResponseCombiner implements ResponseCombiner<Competing
} }
final MathFunction causeSpecificCumulativeHazardFunction = new MathFunction(hazardFunctionPoints); final MathFunction causeSpecificCumulativeHazardFunction = new MathFunction(hazardFunctionPoints);
causeSpecificCumulativeHazardFunctionMap.put(event, causeSpecificCumulativeHazardFunction); causeSpecificCumulativeHazardFunctionList.add(event-1, causeSpecificCumulativeHazardFunction);
final MathFunction cifFunction = new MathFunction(cifPoints); final MathFunction cifFunction = new MathFunction(cifPoints);
cumulativeIncidenceFunctionMap.put(event, cifFunction); cumulativeIncidenceFunctionList.add(event-1, cifFunction);
} }
return CompetingRiskFunctions.builder() return CompetingRiskFunctions.builder()
.causeSpecificHazardFunctionMap(causeSpecificCumulativeHazardFunctionMap) .causeSpecificHazards(causeSpecificCumulativeHazardFunctionList)
.cumulativeIncidenceFunctionMap(cumulativeIncidenceFunctionMap) .cumulativeIncidenceCurves(cumulativeIncidenceFunctionList)
.survivalCurve(survivalCurve) .survivalCurve(survivalCurve)
.build(); .build();
} }