From f1c5b292ed7caf06b99ed8a8f50508e704960ad4 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Fri, 2 Aug 2019 15:10:48 -0700 Subject: [PATCH] Add serialVersionUID to Serializable classes This makes forests between versions more compatible if only method definitions changed. --- .../randomforest/CovariateRow.java | 2 + .../covariates/bool/BooleanCovariate.java | 4 + .../covariates/bool/BooleanSplitRule.java | 2 + .../covariates/factor/FactorCovariate.java | 4 + .../covariates/factor/FactorSplitRule.java | 2 + .../covariates/numeric/NumericCovariate.java | 4 + .../covariates/numeric/NumericSplitRule.java | 2 + .../competingrisk/CompetingRiskFunctions.java | 2 + .../competingrisk/CompetingRiskResponse.java | 2 + .../CompetingRiskResponseWithCensorTime.java | 3 + .../CompetingRiskFunctionCombiner.java | 2 + .../CompetingRiskResponseCombiner.java | 2 + .../splitfinder/GrayLogRankSplitFinder.java | 1 + .../splitfinder/LogRankSplitFinder.java | 1 + .../regression/MeanResponseCombiner.java | 1 + .../WeightedVarianceSplitFinder.java | 1 + .../randomforest/tree/SplitNode.java | 1 + .../randomforest/tree/TerminalNode.java | 1 + .../joeltherrien/randomforest/tree/Tree.java | 1 + .../randomforest/utils/Point.java | 2 + .../utils/RightContinuousStepFunction.java | 2 + .../utils/VeryDiscontinuousStepFunction.java | 80 ------------------- 22 files changed, 42 insertions(+), 80 deletions(-) delete mode 100644 library/src/main/java/ca/joeltherrien/randomforest/utils/VeryDiscontinuousStepFunction.java diff --git a/library/src/main/java/ca/joeltherrien/randomforest/CovariateRow.java b/library/src/main/java/ca/joeltherrien/randomforest/CovariateRow.java index 3e053bf..89b6c27 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/CovariateRow.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/CovariateRow.java @@ -27,6 +27,8 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class CovariateRow implements Serializable, Cloneable { + private static final long serialVersionUID = 1L; + private final Covariate.Value[] valueArray; @Getter diff --git a/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanCovariate.java b/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanCovariate.java index 797378b..824c5eb 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanCovariate.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanCovariate.java @@ -28,6 +28,8 @@ import java.util.Random; public final class BooleanCovariate implements Covariate { + private static final long serialVersionUID = 1L; + @Getter private final String name; @@ -84,6 +86,8 @@ public final class BooleanCovariate implements Covariate { public class BooleanValue implements Value{ + private static final long serialVersionUID = 1L; + private final Boolean value; private BooleanValue(final Boolean value){ diff --git a/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanSplitRule.java b/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanSplitRule.java index 813d13a..dfdf2fd 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanSplitRule.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/covariates/bool/BooleanSplitRule.java @@ -21,6 +21,8 @@ import ca.joeltherrien.randomforest.covariates.SplitRule; public class BooleanSplitRule implements SplitRule { + private static final long serialVersionUID = 1L; + private final int parentCovariateIndex; public BooleanSplitRule(BooleanCovariate parent){ diff --git a/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorCovariate.java b/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorCovariate.java index b3eb245..63db922 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorCovariate.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorCovariate.java @@ -26,6 +26,8 @@ import java.util.*; public final class FactorCovariate implements Covariate { + private static final long serialVersionUID = 1L; + @Getter private final String name; @@ -122,6 +124,8 @@ public final class FactorCovariate implements Covariate { @EqualsAndHashCode public final class FactorValue implements Covariate.Value{ + private static final long serialVersionUID = 1L; + private final String value; private FactorValue(final String value){ diff --git a/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorSplitRule.java b/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorSplitRule.java index 7fb4b4c..56b613f 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorSplitRule.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/covariates/factor/FactorSplitRule.java @@ -25,6 +25,8 @@ import java.util.Set; @EqualsAndHashCode public final class FactorSplitRule implements SplitRule { + private static final long serialVersionUID = 1L; + private final int parentCovariateIndex; private final Set leftSideValues; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericCovariate.java b/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericCovariate.java index 6c1c490..9b65187 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericCovariate.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericCovariate.java @@ -37,6 +37,8 @@ import java.util.stream.Stream; @ToString public final class NumericCovariate implements Covariate { + private static final long serialVersionUID = 1L; + @Getter private final String name; @@ -122,6 +124,8 @@ public final class NumericCovariate implements Covariate { @EqualsAndHashCode public class NumericValue implements Covariate.Value{ + private static final long serialVersionUID = 1L; + private final Double value; // may be null private NumericValue(final Double value){ diff --git a/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericSplitRule.java b/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericSplitRule.java index 43b0c95..dd7e4a3 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericSplitRule.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/covariates/numeric/NumericSplitRule.java @@ -23,6 +23,8 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode public class NumericSplitRule implements SplitRule { + private static final long serialVersionUID = 1L; + private final int parentCovariateIndex; private final double threshold; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java index 7dcddfb..7b1218d 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskFunctions.java @@ -26,6 +26,8 @@ import java.util.List; @Builder public class CompetingRiskFunctions implements Serializable { + private static final long serialVersionUID = 1L; + private final List causeSpecificHazards; private final List cumulativeIncidenceCurves; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponse.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponse.java index afdc4bf..2a94ecd 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponse.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponse.java @@ -23,6 +23,8 @@ import java.io.Serializable; @Data public class CompetingRiskResponse implements Serializable { + private static final long serialVersionUID = 1L; + private final int delta; private final double u; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponseWithCensorTime.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponseWithCensorTime.java index a2fcc7e..e1086b4 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponseWithCensorTime.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/CompetingRiskResponseWithCensorTime.java @@ -26,6 +26,9 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data public final class CompetingRiskResponseWithCensorTime extends CompetingRiskResponse { + + private static final long serialVersionUID = 1L; + private final double c; public CompetingRiskResponseWithCensorTime(int delta, double u, double c) { diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java index ee8292a..89d55f5 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskFunctionCombiner.java @@ -29,6 +29,8 @@ import java.util.List; @RequiredArgsConstructor public class CompetingRiskFunctionCombiner implements ResponseCombiner { + private static final long serialVersionUID = 1L; + private final int[] events; private final double[] times; // We may restrict ourselves to specific times. diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskResponseCombiner.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskResponseCombiner.java index 0ff9ef8..8f2515b 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskResponseCombiner.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/combiner/CompetingRiskResponseCombiner.java @@ -35,6 +35,8 @@ import java.util.List; */ public class CompetingRiskResponseCombiner implements ResponseCombiner { + private static final long serialVersionUID = 1L; + private final int[] events; public CompetingRiskResponseCombiner(final int[] events){ diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/GrayLogRankSplitFinder.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/GrayLogRankSplitFinder.java index b6eed13..c34e975 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/GrayLogRankSplitFinder.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/GrayLogRankSplitFinder.java @@ -28,6 +28,7 @@ import java.util.List; * */ public class GrayLogRankSplitFinder extends CompetingRiskSplitFinder { + private static final long serialVersionUID = 1L; private final int[] eventsOfFocus; private final int[] events; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/LogRankSplitFinder.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/LogRankSplitFinder.java index c31bb84..b0787b2 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/LogRankSplitFinder.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/competingrisk/splitfinder/LogRankSplitFinder.java @@ -28,6 +28,7 @@ import java.util.List; * */ public class LogRankSplitFinder extends CompetingRiskSplitFinder { + private static final long serialVersionUID = 1L; private final int[] eventsOfFocus; private final int[] events; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/MeanResponseCombiner.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/MeanResponseCombiner.java index 137c02c..a6a65d0 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/MeanResponseCombiner.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/MeanResponseCombiner.java @@ -25,6 +25,7 @@ import java.util.List; * */ public class MeanResponseCombiner implements ResponseCombiner { + private static final long serialVersionUID = 1L; @Override public Double combine(List responses) { diff --git a/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/WeightedVarianceSplitFinder.java b/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/WeightedVarianceSplitFinder.java index 9fb4d43..f903d65 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/WeightedVarianceSplitFinder.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/responses/regression/WeightedVarianceSplitFinder.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.stream.Collectors; public class WeightedVarianceSplitFinder implements SplitFinder { + private static final long serialVersionUID = 1L; private Double getScore(Set leftHand, Set rightHand) { diff --git a/library/src/main/java/ca/joeltherrien/randomforest/tree/SplitNode.java b/library/src/main/java/ca/joeltherrien/randomforest/tree/SplitNode.java index f3bd170..8dedaae 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/tree/SplitNode.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/tree/SplitNode.java @@ -29,6 +29,7 @@ import java.util.List; @ToString @Getter public class SplitNode implements Node { + private static final long serialVersionUID = 1L; private final Node leftHand; private final Node rightHand; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/tree/TerminalNode.java b/library/src/main/java/ca/joeltherrien/randomforest/tree/TerminalNode.java index 17c6249..06ad951 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/tree/TerminalNode.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/tree/TerminalNode.java @@ -27,6 +27,7 @@ import java.util.List; @RequiredArgsConstructor @ToString public class TerminalNode implements Node { + private static final long serialVersionUID = 1L; private final Y responseValue; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/tree/Tree.java b/library/src/main/java/ca/joeltherrien/randomforest/tree/Tree.java index fdf4919..baab407 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/tree/Tree.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/tree/Tree.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.List; public class Tree implements Node { + private static final long serialVersionUID = 1L; @Getter private final Node rootNode; diff --git a/library/src/main/java/ca/joeltherrien/randomforest/utils/Point.java b/library/src/main/java/ca/joeltherrien/randomforest/utils/Point.java index 75fad2f..754a4fc 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/utils/Point.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/utils/Point.java @@ -26,6 +26,8 @@ import java.io.Serializable; */ @Data public class Point implements Serializable { + private static final long serialVersionUID = 1L; + private final double time; private final double y; } diff --git a/library/src/main/java/ca/joeltherrien/randomforest/utils/RightContinuousStepFunction.java b/library/src/main/java/ca/joeltherrien/randomforest/utils/RightContinuousStepFunction.java index 5cc673e..2ae8056 100644 --- a/library/src/main/java/ca/joeltherrien/randomforest/utils/RightContinuousStepFunction.java +++ b/library/src/main/java/ca/joeltherrien/randomforest/utils/RightContinuousStepFunction.java @@ -30,6 +30,8 @@ import java.util.function.DoubleUnaryOperator; */ public final class RightContinuousStepFunction extends StepFunction { + private static final long serialVersionUID = 1L; + private final double[] y; /** diff --git a/library/src/main/java/ca/joeltherrien/randomforest/utils/VeryDiscontinuousStepFunction.java b/library/src/main/java/ca/joeltherrien/randomforest/utils/VeryDiscontinuousStepFunction.java deleted file mode 100644 index ce6827c..0000000 --- a/library/src/main/java/ca/joeltherrien/randomforest/utils/VeryDiscontinuousStepFunction.java +++ /dev/null @@ -1,80 +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 . - */ - -package ca.joeltherrien.randomforest.utils; - -/** - * Represents a step function represented by discrete points. However, there may be individual time values that has - * a y value that doesn't belong to a particular 'step'. - */ -public final class VeryDiscontinuousStepFunction implements MathFunction { - - private final double[] x; - private final double[] yAt; - private final double[] yRight; - - /** - * Represents the value that should be returned by evaluate if there are points prior to the time the function is being evaluated at. - * - * Map be null. - */ - private final double defaultY; - - public VeryDiscontinuousStepFunction(double[] x, double[] yAt, double[] yRight, double defaultY) { - this.x = x; - this.yAt = yAt; - this.yRight = yRight; - this.defaultY = defaultY; - } - - @Override - public double evaluate(double time){ - int index = Utils.binarySearchLessThan(0, x.length, x, time); - if(index < 0){ - return defaultY; - } - else{ - if(x[index] == time){ - return yAt[index]; - } - else{ // time > x[index] - return yRight[index]; - } - } - } - - - @Override - public String toString(){ - final StringBuilder builder = new StringBuilder(); - builder.append("Default point: "); - builder.append(defaultY); - builder.append("\n"); - - for(int i=0; i