- Timestamp:
- 04/06/21 13:13:32 (4 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 1 deleted
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r17180 r17928 35 35 using HeuristicLab.Problems.DataAnalysis.Symbolic; 36 36 using HeuristicLab.Random; 37 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 38 using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification; 37 39 38 40 namespace HeuristicLab.Algorithms.DataAnalysis { … … 338 340 symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value; 339 341 } 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 340 352 clonedAlgorithm.Prepare(); 341 353 clonedAlgorithms.Add(clonedAlgorithm); … … 509 521 foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) { 510 522 // 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;512 523 var dataset = (Dataset)Problem.ProblemData.Dataset; 513 524 if (ShuffleSamples.Value) { … … 515 526 dataset = dataset.Shuffle(random); 516 527 } 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); 518 530 // set partitions of problem data clone correctly 519 531 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; … … 809 821 } 810 822 #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 811 838 } 812 839 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessBase.cs
r17180 r17928 22 22 23 23 using System.Linq; 24 using HEAL.Attic; 24 25 using HeuristicLab.Algorithms.GradientDescent; 25 26 using HeuristicLab.Common; … … 29 30 using HeuristicLab.Optimization; 30 31 using HeuristicLab.Parameters; 31 using H EAL.Attic;32 using HeuristicLab.PluginInfrastructure; 32 33 using HeuristicLab.Problems.DataAnalysis; 33 34 … … 57 58 58 59 #region parameter properties 59 public I ValueParameter<IMeanFunction> MeanFunctionParameter {60 get { return (I ValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }61 } 62 public I ValueParameter<ICovarianceFunction> CovarianceFunctionParameter {63 get { return (I ValueParameter<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]; } 64 65 } 65 66 public IValueParameter<IntValue> MinimizationIterationsParameter { … … 106 107 : base() { 107 108 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.")); 110 111 Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20))); 111 112 Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); … … 193 194 194 195 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 } 195 212 } 196 213 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r17180 r17928 281 281 new AccuracyMaximizationThresholdCalculator()); 282 282 var classificationProblemData = new ClassificationProblemData(problemData.Dataset, 283 problemData.AllowedInputVariables, problemData.TargetVariable, problemData.Transformations);283 problemData.AllowedInputVariables, problemData.TargetVariable, transformations: problemData.Transformations); 284 284 classificationProblemData.TrainingPartition.Start = Problem.ProblemData.TrainingPartition.Start; 285 285 classificationProblemData.TrainingPartition.End = Problem.ProblemData.TrainingPartition.End; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
r17180 r17928 24 24 using System.Collections.Generic; 25 25 using System.Linq; 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; 28 using HEAL.Attic;29 29 using HeuristicLab.Problems.DataAnalysis; 30 30 … … 38 38 // don't store the actual model! 39 39 // the actual model is only recalculated when necessary 40 private IGradientBoostedTreesModel fullModel; 40 41 private readonly Lazy<IGradientBoostedTreesModel> actualModel; 41 42 private IGradientBoostedTreesModel ActualModel { … … 48 49 private readonly uint seed; 49 50 [Storable] 50 private ILossFunction lossFunction;51 private readonly ILossFunction lossFunction; 51 52 [Storable] 52 private double r;53 private readonly double r; 53 54 [Storable] 54 private double m;55 private readonly double m; 55 56 [Storable] 56 private double nu;57 private readonly double nu; 57 58 [Storable] 58 private int iterations;59 private readonly int iterations; 59 60 [Storable] 60 private int maxSize;61 private readonly int maxSize; 61 62 62 63 … … 69 70 [StorableConstructor] 70 71 private GradientBoostedTreesModelSurrogate(StorableConstructorFlag _) : base(_) { 71 actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());72 actualModel = CreateLazyInitFunc(); 72 73 } 73 74 74 75 private GradientBoostedTreesModelSurrogate(GradientBoostedTreesModelSurrogate original, Cloner cloner) 75 76 : 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 80 78 this.trainingProblemData = cloner.Clone(original.trainingProblemData); 81 79 this.lossFunction = cloner.Clone(original.lossFunction); … … 86 84 this.m = original.m; 87 85 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(); 88 90 } 89 91 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 }); 94 97 } 95 98 … … 107 110 this.nu = nu; 108 111 109 actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());112 actualModel = CreateLazyInitFunc(); 110 113 } 111 114 112 // wrap an actual model in a surrog rate115 // wrap an actual model in a surrogate 113 116 public GradientBoostedTreesModelSurrogate(IGradientBoostedTreesModel model, IRegressionProblemData trainingProblemData, uint seed, 114 117 ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu) 115 118 : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) { 116 actualModel = new Lazy<IGradientBoostedTreesModel>(() => model);119 fullModel = model; 117 120 } 118 121 … … 135 138 136 139 public IEnumerable<IRegressionModel> Models { 137 get { 138 return ActualModel.Models; 139 } 140 get { return ActualModel.Models; } 140 141 } 141 142 142 143 public IEnumerable<double> Weights { 143 get { 144 return ActualModel.Weights; 145 } 144 get { return ActualModel.Weights; } 146 145 } 147 146 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r17154 r17928 133 133 <Compile Include="DoubleArrayExtensions.cs" /> 134 134 <Compile Include="FixedDataAnalysisAlgorithm.cs" /> 135 <Compile Include="GAM\GeneralizedAdditiveModelAlgorithm.cs" /> 136 <Compile Include="GAM\Spline1dModel.cs" /> 135 137 <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceSpectralMixture.cs" /> 136 138 <Compile Include="GaussianProcess\CovarianceFunctions\CovariancePiecewisePolynomial.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelSurrogate.cs
r17180 r17928 35 35 #region parameters for recalculation of the model 36 36 [Storable] 37 private int seed;37 private readonly int seed; 38 38 [Storable] 39 private IDataAnalysisProblemData originalTrainingData;39 private readonly IDataAnalysisProblemData originalTrainingData; 40 40 [Storable] 41 private double[] classValues;41 private readonly double[] classValues; 42 42 [Storable] 43 private int nTrees;43 private readonly int nTrees; 44 44 [Storable] 45 private double r;45 private readonly double r; 46 46 [Storable] 47 private double m;47 private readonly double m; 48 48 #endregion 49 49 50 50 51 // don't store the actual model! 51 52 // the actual model is only recalculated when necessary 53 private IRandomForestModel fullModel = null; 52 54 private readonly Lazy<IRandomForestModel> actualModel; 55 53 56 private IRandomForestModel ActualModel { 54 57 get { return actualModel.Value; } … … 74 77 this.m = m; 75 78 76 actualModel = new Lazy<IRandomForestModel>(() => RecalculateModel());79 actualModel = CreateLazyInitFunc(); 77 80 } 78 81 79 // wrap an actual model in a surrog rate82 // wrap an actual model in a surrogate 80 83 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; 83 87 } 84 88 85 89 [StorableConstructor] 86 90 private RandomForestModelSurrogate(StorableConstructorFlag _) : base(_) { 87 actualModel = new Lazy<IRandomForestModel>(() => RecalculateModel());91 actualModel = CreateLazyInitFunc(); 88 92 } 89 93 90 94 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 closure94 95 95 // clone data which is necessary to rebuild the model 96 96 this.originalTrainingData = cloner.Clone(original.originalTrainingData); … … 100 100 this.r = original.r; 101 101 this.m = original.m; 102 }103 102 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(); 108 106 } 109 107 110 108 public override IDeepCloneable Clone(Cloner cloner) { 111 109 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 }); 112 117 } 113 118 … … 128 133 } 129 134 return randomForestModel; 135 } 136 137 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 138 return ActualModel.IsProblemDataCompatible(problemData, out errorMessage); 130 139 } 131 140
Note: See TracChangeset
for help on using the changeset viewer.