Add serialVersionUID to Serializable classes

This makes forests between versions more compatible if only method definitions changed.
This commit is contained in:
Joel Therrien 2019-08-02 15:10:48 -07:00
parent a56ad4433d
commit f1c5b292ed
22 changed files with 42 additions and 80 deletions

View file

@ -27,6 +27,8 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CovariateRow implements Serializable, Cloneable { public class CovariateRow implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;
private final Covariate.Value[] valueArray; private final Covariate.Value[] valueArray;
@Getter @Getter

View file

@ -28,6 +28,8 @@ import java.util.Random;
public final class BooleanCovariate implements Covariate<Boolean> { public final class BooleanCovariate implements Covariate<Boolean> {
private static final long serialVersionUID = 1L;
@Getter @Getter
private final String name; private final String name;
@ -84,6 +86,8 @@ public final class BooleanCovariate implements Covariate<Boolean> {
public class BooleanValue implements Value<Boolean>{ public class BooleanValue implements Value<Boolean>{
private static final long serialVersionUID = 1L;
private final Boolean value; private final Boolean value;
private BooleanValue(final Boolean value){ private BooleanValue(final Boolean value){

View file

@ -21,6 +21,8 @@ import ca.joeltherrien.randomforest.covariates.SplitRule;
public class BooleanSplitRule implements SplitRule<Boolean> { public class BooleanSplitRule implements SplitRule<Boolean> {
private static final long serialVersionUID = 1L;
private final int parentCovariateIndex; private final int parentCovariateIndex;
public BooleanSplitRule(BooleanCovariate parent){ public BooleanSplitRule(BooleanCovariate parent){

View file

@ -26,6 +26,8 @@ import java.util.*;
public final class FactorCovariate implements Covariate<String> { public final class FactorCovariate implements Covariate<String> {
private static final long serialVersionUID = 1L;
@Getter @Getter
private final String name; private final String name;
@ -122,6 +124,8 @@ public final class FactorCovariate implements Covariate<String> {
@EqualsAndHashCode @EqualsAndHashCode
public final class FactorValue implements Covariate.Value<String>{ public final class FactorValue implements Covariate.Value<String>{
private static final long serialVersionUID = 1L;
private final String value; private final String value;
private FactorValue(final String value){ private FactorValue(final String value){

View file

@ -25,6 +25,8 @@ import java.util.Set;
@EqualsAndHashCode @EqualsAndHashCode
public final class FactorSplitRule implements SplitRule<String> { public final class FactorSplitRule implements SplitRule<String> {
private static final long serialVersionUID = 1L;
private final int parentCovariateIndex; private final int parentCovariateIndex;
private final Set<String> leftSideValues; private final Set<String> leftSideValues;

View file

@ -37,6 +37,8 @@ import java.util.stream.Stream;
@ToString @ToString
public final class NumericCovariate implements Covariate<Double> { public final class NumericCovariate implements Covariate<Double> {
private static final long serialVersionUID = 1L;
@Getter @Getter
private final String name; private final String name;
@ -122,6 +124,8 @@ public final class NumericCovariate implements Covariate<Double> {
@EqualsAndHashCode @EqualsAndHashCode
public class NumericValue implements Covariate.Value<Double>{ public class NumericValue implements Covariate.Value<Double>{
private static final long serialVersionUID = 1L;
private final Double value; // may be null private final Double value; // may be null
private NumericValue(final Double value){ private NumericValue(final Double value){

View file

@ -23,6 +23,8 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode @EqualsAndHashCode
public class NumericSplitRule implements SplitRule<Double> { public class NumericSplitRule implements SplitRule<Double> {
private static final long serialVersionUID = 1L;
private final int parentCovariateIndex; private final int parentCovariateIndex;
private final double threshold; private final double threshold;

View file

@ -26,6 +26,8 @@ import java.util.List;
@Builder @Builder
public class CompetingRiskFunctions implements Serializable { public class CompetingRiskFunctions implements Serializable {
private static final long serialVersionUID = 1L;
private final List<RightContinuousStepFunction> causeSpecificHazards; private final List<RightContinuousStepFunction> causeSpecificHazards;
private final List<RightContinuousStepFunction> cumulativeIncidenceCurves; private final List<RightContinuousStepFunction> cumulativeIncidenceCurves;

View file

@ -23,6 +23,8 @@ import java.io.Serializable;
@Data @Data
public class CompetingRiskResponse implements Serializable { public class CompetingRiskResponse implements Serializable {
private static final long serialVersionUID = 1L;
private final int delta; private final int delta;
private final double u; private final double u;

View file

@ -26,6 +26,9 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
public final class CompetingRiskResponseWithCensorTime extends CompetingRiskResponse { public final class CompetingRiskResponseWithCensorTime extends CompetingRiskResponse {
private static final long serialVersionUID = 1L;
private final double c; private final double c;
public CompetingRiskResponseWithCensorTime(int delta, double u, double c) { public CompetingRiskResponseWithCensorTime(int delta, double u, double c) {

View file

@ -29,6 +29,8 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CompetingRiskFunctionCombiner implements ResponseCombiner<CompetingRiskFunctions, CompetingRiskFunctions> { public class CompetingRiskFunctionCombiner implements ResponseCombiner<CompetingRiskFunctions, CompetingRiskFunctions> {
private static final long serialVersionUID = 1L;
private final int[] events; private final int[] events;
private final double[] times; // We may restrict ourselves to specific times. private final double[] times; // We may restrict ourselves to specific times.

View file

@ -35,6 +35,8 @@ import java.util.List;
*/ */
public class CompetingRiskResponseCombiner implements ResponseCombiner<CompetingRiskResponse, CompetingRiskFunctions> { public class CompetingRiskResponseCombiner implements ResponseCombiner<CompetingRiskResponse, CompetingRiskFunctions> {
private static final long serialVersionUID = 1L;
private final int[] events; private final int[] events;
public CompetingRiskResponseCombiner(final int[] events){ public CompetingRiskResponseCombiner(final int[] events){

View file

@ -28,6 +28,7 @@ import java.util.List;
* *
*/ */
public class GrayLogRankSplitFinder extends CompetingRiskSplitFinder<CompetingRiskResponseWithCensorTime> { public class GrayLogRankSplitFinder extends CompetingRiskSplitFinder<CompetingRiskResponseWithCensorTime> {
private static final long serialVersionUID = 1L;
private final int[] eventsOfFocus; private final int[] eventsOfFocus;
private final int[] events; private final int[] events;

View file

@ -28,6 +28,7 @@ import java.util.List;
* *
*/ */
public class LogRankSplitFinder extends CompetingRiskSplitFinder<CompetingRiskResponse> { public class LogRankSplitFinder extends CompetingRiskSplitFinder<CompetingRiskResponse> {
private static final long serialVersionUID = 1L;
private final int[] eventsOfFocus; private final int[] eventsOfFocus;
private final int[] events; private final int[] events;

View file

@ -25,6 +25,7 @@ import java.util.List;
* *
*/ */
public class MeanResponseCombiner implements ResponseCombiner<Double, Double> { public class MeanResponseCombiner implements ResponseCombiner<Double, Double> {
private static final long serialVersionUID = 1L;
@Override @Override
public Double combine(List<Double> responses) { public Double combine(List<Double> responses) {

View file

@ -27,6 +27,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class WeightedVarianceSplitFinder implements SplitFinder<Double> { public class WeightedVarianceSplitFinder implements SplitFinder<Double> {
private static final long serialVersionUID = 1L;
private Double getScore(Set leftHand, Set rightHand) { private Double getScore(Set leftHand, Set rightHand) {

View file

@ -29,6 +29,7 @@ import java.util.List;
@ToString @ToString
@Getter @Getter
public class SplitNode<Y> implements Node<Y> { public class SplitNode<Y> implements Node<Y> {
private static final long serialVersionUID = 1L;
private final Node<Y> leftHand; private final Node<Y> leftHand;
private final Node<Y> rightHand; private final Node<Y> rightHand;

View file

@ -27,6 +27,7 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
@ToString @ToString
public class TerminalNode<Y> implements Node<Y> { public class TerminalNode<Y> implements Node<Y> {
private static final long serialVersionUID = 1L;
private final Y responseValue; private final Y responseValue;

View file

@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class Tree<Y> implements Node<Y> { public class Tree<Y> implements Node<Y> {
private static final long serialVersionUID = 1L;
@Getter @Getter
private final Node<Y> rootNode; private final Node<Y> rootNode;

View file

@ -26,6 +26,8 @@ import java.io.Serializable;
*/ */
@Data @Data
public class Point implements Serializable { public class Point implements Serializable {
private static final long serialVersionUID = 1L;
private final double time; private final double time;
private final double y; private final double y;
} }

View file

@ -30,6 +30,8 @@ import java.util.function.DoubleUnaryOperator;
*/ */
public final class RightContinuousStepFunction extends StepFunction { public final class RightContinuousStepFunction extends StepFunction {
private static final long serialVersionUID = 1L;
private final double[] y; private final double[] y;
/** /**

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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<x.length; i++){
builder.append("x:");
builder.append(x[i]);
builder.append("\tyAt:");
builder.append(yAt[i]);
builder.append("\tyRight:");
builder.append(yRight[i]);
builder.append("\n");
}
return builder.toString();
}
}