Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/21 16:07:45 (2 years ago)
Author:
mkommend
Message:

#2521: Merged trunk changes into branch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r17226 r18086  
    3535using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3636using HeuristicLab.Random;
     37using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
     38using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification;
    3739
    3840namespace HeuristicLab.Algorithms.DataAnalysis {
     
    338340              symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value;
    339341            }
     342
     343            // We need to set the estimation limits because they are recalculated by the problem
     344            // whenever the data partitions change.
     345            // Instead of explicitly handling all types we could also check the parameters-collection
     346            // for a parameter with name "EstimationLimits".
     347            SetEstimationLimits(problem, new[] { typeof(SymbolicRegressionSingleObjectiveProblem),
     348                                                 typeof(SymbolicRegressionMultiObjectiveProblem),
     349                                                 typeof(SymbolicClassificationSingleObjectiveProblem),
     350                                                 typeof(SymbolicClassificationMultiObjectiveProblem) });
     351
    340352            clonedAlgorithm.Prepare();
    341353            clonedAlgorithms.Add(clonedAlgorithm);
     
    509521      foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) {
    510522        // at least one algorithm (GBT with logistic regression loss) produces a classification solution even though the original problem is a regression problem.
    511         var targetVariable = solutions.Value.First().ProblemData.TargetVariable;
    512523        var dataset = (Dataset)Problem.ProblemData.Dataset;
    513524        if (ShuffleSamples.Value) {
     
    515526          dataset = dataset.Shuffle(random);
    516527        }
    517         var problemDataClone = new ClassificationProblemData(dataset, Problem.ProblemData.AllowedInputVariables, targetVariable);
     528        var problemData = (IClassificationProblemData)Problem.ProblemData;
     529        var problemDataClone = new ClassificationProblemData(dataset, problemData.AllowedInputVariables, problemData.TargetVariable, problemData.ClassNames, problemData.PositiveClass);
    518530        // set partitions of problem data clone correctly
    519531        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     
    809821    }
    810822    #endregion
     823
     824    #region helper
     825
     826    private void SetEstimationLimits(IDataAnalysisProblem problem, Type[] types) {
     827      foreach (var type in types) {
     828        if (type.IsAssignableFrom(problem.GetType())) {
     829          var originalLimits = (DoubleLimit)Problem.Parameters["EstimationLimits"].ActualValue;  // problem is a clone of Problem
     830          var limits = (DoubleLimit)problem.Parameters["EstimationLimits"].ActualValue;
     831          limits.Lower = originalLimits.Lower;
     832          limits.Upper = originalLimits.Upper;
     833        }
     834      }
     835    }
     836
     837    #endregion
    811838  }
    812839}
Note: See TracChangeset for help on using the changeset viewer.