mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-24 22:48:34 +00:00
Fixed IllegalStateException during models training
This commit is contained in:
-1
@@ -66,7 +66,6 @@ public class ManeuverClassifierTrainer {
|
||||
LoggingUtil.logInfo("Training with " + trainManeuvers.size() + " maneuvers...");
|
||||
double[][] x = modelContext.getXMatrix(maneuvers);
|
||||
int[] y = labelExtraction.getYVector(maneuvers);
|
||||
classifierModel.resetTrainingStats();
|
||||
classifierModel.train(x, y);
|
||||
LoggingUtil.logInfo("Training finished. Validating on train dataset...");
|
||||
ManeuverClassifierScoring classifierScoring = new ManeuverClassifierScoring(classifierModel);
|
||||
|
||||
-1
@@ -100,7 +100,6 @@ public class TwdTransitionClassifierTrainer {
|
||||
i++;
|
||||
}
|
||||
LoggingUtil.logInfo("Training with " + numberOfTrainingInstances + " instances...");
|
||||
classifierModel.resetTrainingStats();
|
||||
classifierModel.train(x, y);
|
||||
LoggingUtil.logInfo("Training finished. Validating on train dataset...");
|
||||
TwdTransitionClassifierScoring classifierScoring = new TwdTransitionClassifierScoring(classifierModel);
|
||||
|
||||
+3
@@ -41,6 +41,9 @@ public class IncrementalSingleDimensionPolynomialRegressorTrainerHelper {
|
||||
}
|
||||
|
||||
public void incrementRmseCalculation(double[] x, double y) {
|
||||
if (!model.isModelReady()) {
|
||||
model.setModelAsReadyAfterSuccessfulTraining();
|
||||
}
|
||||
double predictedStd = model.getValue(x);
|
||||
double diff = predictedStd - y;
|
||||
squareErrorSum += diff * diff;
|
||||
|
||||
+1
-2
@@ -21,8 +21,7 @@ public class TwdTransitionManualTrainingDataInputRegressorTrainer {
|
||||
throws Exception {
|
||||
IncrementalSingleDimensionPolynomialRegressorTrainerHelper trainerHelper = new IncrementalSingleDimensionPolynomialRegressorTrainerHelper(
|
||||
regressorModelStore, model);
|
||||
LoggingUtil
|
||||
.logInfo("########## Training of " + model.getModelContext().getId() + " started...");
|
||||
LoggingUtil.logInfo("########## Training of " + model.getModelContext().getId() + " started...");
|
||||
double[] modelInput = new double[1];
|
||||
for (int i = 0; i < inputOutputPairs.length; i++) {
|
||||
double xi = inputOutputPairs[i][0];
|
||||
|
||||
+5
-1
@@ -51,12 +51,16 @@ public abstract class AbstractTrainableModel<InstanceType, MC extends ModelConte
|
||||
|
||||
@Override
|
||||
public void setStatsAfterSuccessfulTraining(double trainScore, double testScore, long numberOfTrainingInstances) {
|
||||
trainingFinished = true;
|
||||
this.trainScore = trainScore;
|
||||
this.testScore = testScore;
|
||||
this.numberOfTrainingInstances = numberOfTrainingInstances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModelAsReadyAfterSuccessfulTraining() {
|
||||
trainingFinished = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTrainingStats() {
|
||||
trainingFinished = false;
|
||||
|
||||
+13
-2
@@ -46,8 +46,9 @@ public interface TrainableModel<InstanceType, MC extends ModelContext<InstanceTy
|
||||
long getNumberOfTrainingInstances();
|
||||
|
||||
/**
|
||||
* Sets the training statistics for this model and makes this model ready (see {@link #isModelReady()}) for
|
||||
* prediction tasks. This method must be called only after model training has been successfully completed.
|
||||
* Sets the training statistics for this model after successful training which should have been previously signaled
|
||||
* with {@link #setModelAsReadyAfterSuccessfulTraining()}. This method must be called only after model training has
|
||||
* been successfully completed.
|
||||
*
|
||||
* @param trainScore
|
||||
* Macro-averaged F2-Score with training data (see {@link #getTrainScore()})
|
||||
@@ -58,6 +59,16 @@ public interface TrainableModel<InstanceType, MC extends ModelContext<InstanceTy
|
||||
*/
|
||||
void setStatsAfterSuccessfulTraining(double trainScore, double testScore, long numberOfTrainingInstances);
|
||||
|
||||
/**
|
||||
* Marks this model as ready for prediction tasks. This method should be called after successful training of this
|
||||
* model. Afterwards, model evaluation should be performed to determine the training and test score of the model and
|
||||
* set it with {@link #setStatsAfterSuccessfulTraining(double, double, long)}.
|
||||
*
|
||||
* @see #isModelReady()
|
||||
* @see #setStatsAfterSuccessfulTraining(double, double, long)
|
||||
*/
|
||||
void setModelAsReadyAfterSuccessfulTraining();
|
||||
|
||||
/**
|
||||
* Resets the training stats and marks this model as not ready (see {@link #isModelReady()}). Should be called
|
||||
* before model training starts.
|
||||
|
||||
+2
@@ -38,6 +38,7 @@ public abstract class AbstractSmileClassificationModel<InstanceType, MC extends
|
||||
|
||||
@Override
|
||||
public void train(double[][] x, int[] y) {
|
||||
resetTrainingStats();
|
||||
PreprocessingConfig preprocessingConfig = getPreprocessingConfig();
|
||||
scaler = null;
|
||||
if (preprocessingConfig.isScaling()) {
|
||||
@@ -56,6 +57,7 @@ public abstract class AbstractSmileClassificationModel<InstanceType, MC extends
|
||||
x = pca.project(x);
|
||||
}
|
||||
internalModel = trainInternalModel(x, y);
|
||||
setModelAsReadyAfterSuccessfulTraining();
|
||||
}
|
||||
|
||||
protected abstract SoftClassifier<double[]> trainInternalModel(double[][] x, int[] y);
|
||||
|
||||
Reference in New Issue
Block a user