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 java.io.Serializable;
import java.util.List;
import java.util.Map;
@Builder
public class CompetingRiskFunctions implements Serializable {
private final Map<Integer, MathFunction> causeSpecificHazardFunctionMap;
private final Map<Integer, MathFunction> cumulativeIncidenceFunctionMap;
private final List<MathFunction> causeSpecificHazards;
private final List<MathFunction> 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){

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 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){
@ -78,14 +79,14 @@ public class CompetingRiskFunctionCombiner implements ResponseCombiner<Competing
}
causeSpecificCumulativeHazardFunctionMap.put(event, new MathFunction(cumulativeHazardFunctionPoints));
cumulativeIncidenceFunctionMap.put(event, new MathFunction(cumulativeIncidenceFunctionPoints));
causeSpecificCumulativeHazardFunctionList.add(event-1, new MathFunction(cumulativeHazardFunctionPoints));
cumulativeIncidenceFunctionList.add(event-1, new MathFunction(cumulativeIncidenceFunctionPoints));
}
return CompetingRiskFunctions.builder()
.causeSpecificHazardFunctionMap(causeSpecificCumulativeHazardFunctionMap)
.cumulativeIncidenceFunctionMap(cumulativeIncidenceFunctionMap)
.causeSpecificHazards(causeSpecificCumulativeHazardFunctionList)
.cumulativeIncidenceCurves(cumulativeIncidenceFunctionList)
.survivalCurve(survivalFunction)
.build();
}

View file

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