Add serialVersionUID to Serializable classes
This makes forests between versions more compatible if only method definitions changed.
This commit is contained in:
parent
a56ad4433d
commit
f1c5b292ed
22 changed files with 42 additions and 80 deletions
|
@ -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
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.util.Random;
|
|||
|
||||
public final class BooleanCovariate implements Covariate<Boolean> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
|
@ -84,6 +86,8 @@ public final class BooleanCovariate implements Covariate<Boolean> {
|
|||
|
||||
public class BooleanValue implements Value<Boolean>{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Boolean value;
|
||||
|
||||
private BooleanValue(final Boolean value){
|
||||
|
|
|
@ -21,6 +21,8 @@ import ca.joeltherrien.randomforest.covariates.SplitRule;
|
|||
|
||||
public class BooleanSplitRule implements SplitRule<Boolean> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int parentCovariateIndex;
|
||||
|
||||
public BooleanSplitRule(BooleanCovariate parent){
|
||||
|
|
|
@ -26,6 +26,8 @@ import java.util.*;
|
|||
|
||||
public final class FactorCovariate implements Covariate<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
|
@ -122,6 +124,8 @@ public final class FactorCovariate implements Covariate<String> {
|
|||
@EqualsAndHashCode
|
||||
public final class FactorValue implements Covariate.Value<String>{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String value;
|
||||
|
||||
private FactorValue(final String value){
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.Set;
|
|||
@EqualsAndHashCode
|
||||
public final class FactorSplitRule implements SplitRule<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int parentCovariateIndex;
|
||||
private final Set<String> leftSideValues;
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ import java.util.stream.Stream;
|
|||
@ToString
|
||||
public final class NumericCovariate implements Covariate<Double> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
|
@ -122,6 +124,8 @@ public final class NumericCovariate implements Covariate<Double> {
|
|||
@EqualsAndHashCode
|
||||
public class NumericValue implements Covariate.Value<Double>{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Double value; // may be null
|
||||
|
||||
private NumericValue(final Double value){
|
||||
|
|
|
@ -23,6 +23,8 @@ import lombok.EqualsAndHashCode;
|
|||
@EqualsAndHashCode
|
||||
public class NumericSplitRule implements SplitRule<Double> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int parentCovariateIndex;
|
||||
private final double threshold;
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ import java.util.List;
|
|||
@Builder
|
||||
public class CompetingRiskFunctions implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final List<RightContinuousStepFunction> causeSpecificHazards;
|
||||
private final List<RightContinuousStepFunction> cumulativeIncidenceCurves;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.List;
|
|||
@RequiredArgsConstructor
|
||||
public class CompetingRiskFunctionCombiner implements ResponseCombiner<CompetingRiskFunctions, CompetingRiskFunctions> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int[] events;
|
||||
private final double[] times; // We may restrict ourselves to specific times.
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ import java.util.List;
|
|||
*/
|
||||
public class CompetingRiskResponseCombiner implements ResponseCombiner<CompetingRiskResponse, CompetingRiskFunctions> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int[] events;
|
||||
|
||||
public CompetingRiskResponseCombiner(final int[] events){
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
*
|
||||
*/
|
||||
public class GrayLogRankSplitFinder extends CompetingRiskSplitFinder<CompetingRiskResponseWithCensorTime> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int[] eventsOfFocus;
|
||||
private final int[] events;
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
*
|
||||
*/
|
||||
public class LogRankSplitFinder extends CompetingRiskSplitFinder<CompetingRiskResponse> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int[] eventsOfFocus;
|
||||
private final int[] events;
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
*
|
||||
*/
|
||||
public class MeanResponseCombiner implements ResponseCombiner<Double, Double> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Double combine(List<Double> responses) {
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class WeightedVarianceSplitFinder implements SplitFinder<Double> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Double getScore(Set leftHand, Set rightHand) {
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
@ToString
|
||||
@Getter
|
||||
public class SplitNode<Y> implements Node<Y> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Node<Y> leftHand;
|
||||
private final Node<Y> rightHand;
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
@RequiredArgsConstructor
|
||||
@ToString
|
||||
public class TerminalNode<Y> implements Node<Y> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Y responseValue;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
public class Tree<Y> implements Node<Y> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Getter
|
||||
private final Node<Y> rootNode;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue