Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/06/21 13:13:32 (4 years ago)
Author:
dpiringe
Message:

#3026

  • merged trunk into branch
Location:
branches/3026_IntegrationIntoSymSpace
Files:
1 deleted
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r17180 r17928  
    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}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessBase.cs

    r17180 r17928  
    2222
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Algorithms.GradientDescent;
    2526using HeuristicLab.Common;
     
    2930using HeuristicLab.Optimization;
    3031using HeuristicLab.Parameters;
    31 using HEAL.Attic;
     32using HeuristicLab.PluginInfrastructure;
    3233using HeuristicLab.Problems.DataAnalysis;
    3334
     
    5758
    5859    #region parameter properties
    59     public IValueParameter<IMeanFunction> MeanFunctionParameter {
    60       get { return (IValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
    61     }
    62     public IValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
    63       get { return (IValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
     60    public IConstrainedValueParameter<IMeanFunction> MeanFunctionParameter {
     61      get { return (IConstrainedValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
     62    }
     63    public IConstrainedValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
     64      get { return (IConstrainedValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
    6465    }
    6566    public IValueParameter<IntValue> MinimizationIterationsParameter {
     
    106107      : base() {
    107108      Problem = problem;
    108       Parameters.Add(new ValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use.", new MeanConst()));
    109       Parameters.Add(new ValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use.", new CovarianceSquaredExponentialIso()));
     109      Parameters.Add(new ConstrainedValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use."));
     110      Parameters.Add(new ConstrainedValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use."));
    110111      Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20)));
    111112      Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     
    193194
    194195      solutionCreator.OperatorParameter.ActualName = SolutionCreatorParameterName;
     196
     197      foreach (var meanfunction in ApplicationManager.Manager.GetInstances<IMeanFunction>().OrderBy(s => s.ItemName))
     198        MeanFunctionParameter.ValidValues.Add(meanfunction);
     199
     200      var defaultMeanFunction = MeanFunctionParameter.ValidValues.OfType<MeanConst>().FirstOrDefault();
     201      if (defaultMeanFunction != null) {
     202        MeanFunctionParameter.Value = defaultMeanFunction;
     203      }
     204
     205      foreach (var covarianceFunction in ApplicationManager.Manager.GetInstances<ICovarianceFunction>().OrderBy(s => s.ItemName))
     206        CovarianceFunctionParameter.ValidValues.Add(covarianceFunction);
     207
     208      var defaultCovarianceFunctionParameter = CovarianceFunctionParameter.ValidValues.OfType<CovarianceSquaredExponentialIso>().FirstOrDefault();
     209      if (defaultCovarianceFunctionParameter != null) {
     210        CovarianceFunctionParameter.Value = defaultCovarianceFunctionParameter;
     211      }
    195212    }
    196213
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs

    r17180 r17928  
    281281            new AccuracyMaximizationThresholdCalculator());
    282282          var classificationProblemData = new ClassificationProblemData(problemData.Dataset,
    283             problemData.AllowedInputVariables, problemData.TargetVariable, problemData.Transformations);
     283            problemData.AllowedInputVariables, problemData.TargetVariable, transformations: problemData.Transformations);
    284284          classificationProblemData.TrainingPartition.Start = Problem.ProblemData.TrainingPartition.Start;
    285285          classificationProblemData.TrainingPartition.End = Problem.ProblemData.TrainingPartition.End;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs

    r17180 r17928  
    2424using System.Collections.Generic;
    2525using System.Linq;
     26using HEAL.Attic;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    28 using HEAL.Attic;
    2929using HeuristicLab.Problems.DataAnalysis;
    3030
     
    3838    // don't store the actual model!
    3939    // the actual model is only recalculated when necessary
     40    private IGradientBoostedTreesModel fullModel;
    4041    private readonly Lazy<IGradientBoostedTreesModel> actualModel;
    4142    private IGradientBoostedTreesModel ActualModel {
     
    4849    private readonly uint seed;
    4950    [Storable]
    50     private ILossFunction lossFunction;
     51    private readonly ILossFunction lossFunction;
    5152    [Storable]
    52     private double r;
     53    private readonly double r;
    5354    [Storable]
    54     private double m;
     55    private readonly double m;
    5556    [Storable]
    56     private double nu;
     57    private readonly double nu;
    5758    [Storable]
    58     private int iterations;
     59    private readonly int iterations;
    5960    [Storable]
    60     private int maxSize;
     61    private readonly int maxSize;
    6162
    6263
     
    6970    [StorableConstructor]
    7071    private GradientBoostedTreesModelSurrogate(StorableConstructorFlag _) : base(_) {
    71       actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());
     72      actualModel = CreateLazyInitFunc();
    7273    }
    7374
    7475    private GradientBoostedTreesModelSurrogate(GradientBoostedTreesModelSurrogate original, Cloner cloner)
    7576      : base(original, cloner) {
    76       IGradientBoostedTreesModel clonedModel = null;
    77       if (original.actualModel.IsValueCreated) clonedModel = cloner.Clone(original.ActualModel);
    78       actualModel = new Lazy<IGradientBoostedTreesModel>(CreateLazyInitFunc(clonedModel)); // only capture clonedModel in the closure
    79 
     77      // clone data which is necessary to rebuild the model
    8078      this.trainingProblemData = cloner.Clone(original.trainingProblemData);
    8179      this.lossFunction = cloner.Clone(original.lossFunction);
     
    8684      this.m = original.m;
    8785      this.nu = original.nu;
     86
     87      // clone full model if it has already been created
     88      if (original.fullModel != null) this.fullModel = cloner.Clone(original.fullModel);
     89      actualModel = CreateLazyInitFunc();
    8890    }
    8991
    90     private Func<IGradientBoostedTreesModel> CreateLazyInitFunc(IGradientBoostedTreesModel clonedModel) {
    91       return () => {
    92         return clonedModel ?? RecalculateModel();
    93       };
     92    private Lazy<IGradientBoostedTreesModel> CreateLazyInitFunc() {
     93      return new Lazy<IGradientBoostedTreesModel>(() => {
     94        if (fullModel == null) fullModel = RecalculateModel();
     95        return fullModel;
     96      });
    9497    }
    9598
     
    107110      this.nu = nu;
    108111
    109       actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());
     112      actualModel = CreateLazyInitFunc();
    110113    }
    111114
    112     // wrap an actual model in a surrograte
     115    // wrap an actual model in a surrogate
    113116    public GradientBoostedTreesModelSurrogate(IGradientBoostedTreesModel model, IRegressionProblemData trainingProblemData, uint seed,
    114117      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
    115118      : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) {
    116       actualModel = new Lazy<IGradientBoostedTreesModel>(() => model);
     119      fullModel = model;
    117120    }
    118121
     
    135138
    136139    public IEnumerable<IRegressionModel> Models {
    137       get {
    138         return ActualModel.Models;
    139       }
     140      get { return ActualModel.Models; }
    140141    }
    141142
    142143    public IEnumerable<double> Weights {
    143       get {
    144         return ActualModel.Weights;
    145       }
     144      get { return ActualModel.Weights; }
    146145    }
    147146  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj

    r17154 r17928  
    133133    <Compile Include="DoubleArrayExtensions.cs" />
    134134    <Compile Include="FixedDataAnalysisAlgorithm.cs" />
     135    <Compile Include="GAM\GeneralizedAdditiveModelAlgorithm.cs" />
     136    <Compile Include="GAM\Spline1dModel.cs" />
    135137    <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceSpectralMixture.cs" />
    136138    <Compile Include="GaussianProcess\CovarianceFunctions\CovariancePiecewisePolynomial.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelSurrogate.cs

    r17180 r17928  
    3535    #region parameters for recalculation of the model
    3636    [Storable]
    37     private int seed;
     37    private readonly int seed;
    3838    [Storable]
    39     private IDataAnalysisProblemData originalTrainingData;
     39    private readonly IDataAnalysisProblemData originalTrainingData;
    4040    [Storable]
    41     private double[] classValues;
     41    private readonly double[] classValues;
    4242    [Storable]
    43     private int nTrees;
     43    private readonly int nTrees;
    4444    [Storable]
    45     private double r;
     45    private readonly double r;
    4646    [Storable]
    47     private double m;
     47    private readonly double m;
    4848    #endregion
     49
    4950
    5051    // don't store the actual model!
    5152    // the actual model is only recalculated when necessary
     53    private IRandomForestModel fullModel = null;
    5254    private readonly Lazy<IRandomForestModel> actualModel;
     55
    5356    private IRandomForestModel ActualModel {
    5457      get { return actualModel.Value; }
     
    7477      this.m = m;
    7578
    76       actualModel = new Lazy<IRandomForestModel>(() => RecalculateModel());
     79      actualModel = CreateLazyInitFunc();
    7780    }
    7881
    79     // wrap an actual model in a surrograte
     82    // wrap an actual model in a surrogate
    8083    public RandomForestModelSurrogate(IRandomForestModel model, string targetVariable, IDataAnalysisProblemData originalTrainingData,
    81       int seed, int nTrees, double r, double m, double[] classValues = null) : this(targetVariable, originalTrainingData, seed, nTrees, r, m, classValues) {
    82       actualModel = new Lazy<IRandomForestModel>(() => model);
     84      int seed, int nTrees, double r, double m, double[] classValues = null)
     85      : this(targetVariable, originalTrainingData, seed, nTrees, r, m, classValues) {
     86      fullModel = model;
    8387    }
    8488
    8589    [StorableConstructor]
    8690    private RandomForestModelSurrogate(StorableConstructorFlag _) : base(_) {
    87       actualModel = new Lazy<IRandomForestModel>(() => RecalculateModel());
     91      actualModel = CreateLazyInitFunc();
    8892    }
    8993
    9094    private RandomForestModelSurrogate(RandomForestModelSurrogate original, Cloner cloner) : base(original, cloner) {
    91       IRandomForestModel clonedModel = null;
    92       if (original.actualModel.IsValueCreated) clonedModel = cloner.Clone(original.ActualModel);
    93       actualModel = new Lazy<IRandomForestModel>(CreateLazyInitFunc(clonedModel)); // only capture clonedModel in the closure
    94 
    9595      // clone data which is necessary to rebuild the model
    9696      this.originalTrainingData = cloner.Clone(original.originalTrainingData);
     
    100100      this.r = original.r;
    101101      this.m = original.m;
    102     }
    103102
    104     private Func<IRandomForestModel> CreateLazyInitFunc(IRandomForestModel clonedModel) {
    105       return () => {
    106         return clonedModel ?? RecalculateModel();
    107       };
     103      // clone full model if it has already been created
     104      if (original.fullModel != null) this.fullModel = cloner.Clone(original.fullModel);
     105      actualModel = CreateLazyInitFunc();
    108106    }
    109107
    110108    public override IDeepCloneable Clone(Cloner cloner) {
    111109      return new RandomForestModelSurrogate(this, cloner);
     110    }
     111
     112    private Lazy<IRandomForestModel> CreateLazyInitFunc() {
     113      return new Lazy<IRandomForestModel>(() => {
     114        if (fullModel == null) fullModel = RecalculateModel();
     115        return fullModel;
     116      });
    112117    }
    113118
     
    128133      }
    129134      return randomForestModel;
     135    }
     136
     137    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     138      return ActualModel.IsProblemDataCompatible(problemData, out errorMessage);
    130139    }
    131140
Note: See TracChangeset for help on using the changeset viewer.