- Timestamp:
- 10/20/13 20:18:38 (11 years ago)
- Location:
- branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisEvaluator.cs
r10072 r10073 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.IntegerVectorEncoding; 28 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 using HeuristicLab.Operators; … … 31 32 using HeuristicLab.Parameters; 32 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.Problems.DataAnalysis; 35 using HeuristicLab.Problems.DataAnalysis.Symbolic; 36 using HeuristicLab.Problems.GrammaticalEvolution.Mappers; 33 37 using HeuristicLab.Random; 34 38 35 namespace HeuristicLab.Problems. DataAnalysis.Symbolic{39 namespace HeuristicLab.Problems.GrammaticalEvolution { 36 40 [StorableClass] 37 public abstract class SymbolicDataAnalysisEvaluator<T> : SingleSuccessorOperator,38 I SymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, IStochasticOperator41 public abstract class GESymbolicDataAnalysisEvaluator<T> : SingleSuccessorOperator, 42 IGESymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, IStochasticOperator 39 43 where T : class, IDataAnalysisProblemData { 40 44 private const string RandomParameterName = "Random"; … … 42 46 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 43 47 private const string ProblemDataParameterName = "ProblemData"; 48 private const string IntegerVectorParameterName = "IntegerVector"; 49 private const string GenotypeToPhenotypeMapperParameterName = "GenotypeToPhenotypeMapper"; 50 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar"; 51 44 52 private const string EstimationLimitsParameterName = "EstimationLimits"; 45 53 private const string EvaluationPartitionParameterName = "EvaluationPartition"; … … 67 75 get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; } 68 76 } 77 public ILookupParameter<IntegerVector> IntegerVectorParameter { 78 get { return (ILookupParameter<IntegerVector>)Parameters[IntegerVectorParameterName]; } 79 } 80 public ILookupParameter<IGenotypeToPhenotypeMapper> GenotypeToPhenotypeMapperParameter { 81 get { return (ILookupParameter<IGenotypeToPhenotypeMapper>)Parameters[GenotypeToPhenotypeMapperParameterName]; } 82 } 83 public IValueLookupParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter { 84 get { return (IValueLookupParameter<ISymbolicDataAnalysisGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; } 85 } 69 86 70 87 public IValueLookupParameter<IntRange> EvaluationPartitionParameter { … … 87 104 88 105 [StorableConstructor] 89 protected SymbolicDataAnalysisEvaluator(bool deserializing) : base(deserializing) { }90 protected SymbolicDataAnalysisEvaluator(SymbolicDataAnalysisEvaluator<T> original, Cloner cloner)106 protected GESymbolicDataAnalysisEvaluator(bool deserializing) : base(deserializing) { } 107 protected GESymbolicDataAnalysisEvaluator(GESymbolicDataAnalysisEvaluator<T> original, Cloner cloner) 91 108 : base(original, cloner) { 92 109 } 93 public SymbolicDataAnalysisEvaluator()110 public GESymbolicDataAnalysisEvaluator() 94 111 : base() { 95 112 Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use.")); … … 97 114 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree.")); 98 115 Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.")); 116 Parameters.Add(new LookupParameter<IntegerVector>(IntegerVectorParameterName, "The symbolic data analysis solution encoded as an integer vector genome.")); 117 Parameters.Add(new LookupParameter<IGenotypeToPhenotypeMapper>(GenotypeToPhenotypeMapperParameterName, "Maps the genotype (an integer vector) to the phenotype (a symbolic expression tree).")); 118 Parameters.Add(new ValueLookupParameter<ISymbolicDataAnalysisGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created.")); 119 99 120 Parameters.Add(new ValueLookupParameter<IntRange>(EvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.")); 100 121 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees.")); -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisProblem.cs
r10072 r10073 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Encodings.IntegerVectorEncoding; 29 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 31 using HeuristicLab.Optimization; … … 32 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 34 using HeuristicLab.PluginInfrastructure; 35 using HeuristicLab.Problems.DataAnalysis; 36 using HeuristicLab.Problems.DataAnalysis.Symbolic; 37 using HeuristicLab.Problems.GrammaticalEvolution.Mappers; 34 38 using HeuristicLab.Problems.Instances; 35 39 36 namespace HeuristicLab.Problems. DataAnalysis.Symbolic{40 namespace HeuristicLab.Problems.GrammaticalEvolution { 37 41 [StorableClass] 38 public abstract class SymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, IDataAnalysisProblem<T>, ISymbolicDataAnalysisProblem, IStorableContent, 42 // TODO: ISymbolicDataAnalysisProblem -> IGESymbolicDataAnalysisProblem 43 public abstract class GESymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, IDataAnalysisProblem<T>, ISymbolicDataAnalysisProblem, IStorableContent, 39 44 IProblemInstanceConsumer<T>, IProblemInstanceExporter<T> 40 45 where T : class, IDataAnalysisProblemData 41 where U : class, I SymbolicDataAnalysisEvaluator<T>42 where V : class, I SymbolicDataAnalysisSolutionCreator {46 where U : class, IGESymbolicDataAnalysisEvaluator<T> 47 where V : class, IIntegerVectorCreator { 43 48 44 49 #region parameter names & descriptions … … 54 59 private const string ValidationPartitionParameterName = "ValidationPartition"; 55 60 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 61 private const string BoundsParameterName = "Bounds"; 62 private const string GenotypeToPhenotypeMapperParameterName = "GenotypeToPhenotypeMapper"; 56 63 57 64 private const string ProblemDataParameterDescription = ""; … … 66 73 private const string ValidationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to select the best model from (optional)."; 67 74 private const string ApplyLinearScalingParameterDescription = "Flag that indicates if the individual should be linearly scaled before evaluating."; 75 private const string BoundsParameterDescription = "The integer number range in which the single genomes of a genotype are created."; 76 private const string GenotypeToPhenotypeMapperParameterDescription = "Maps the genotype (an integer vector) to the phenotype (a symbolic expression tree)."; 68 77 #endregion 69 78 … … 105 114 get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 106 115 } 116 public IValueParameter<IntMatrix> BoundsParameter { 117 get { return (IValueParameter<IntMatrix>)Parameters[BoundsParameterName]; } 118 } 119 public IValueParameter<IGenotypeToPhenotypeMapper> GenotypeToPhenotypeMapperParameter { 120 get { return (IValueParameter<IGenotypeToPhenotypeMapper>)Parameters[GenotypeToPhenotypeMapperParameterName]; } 121 } 107 122 #endregion 108 123 … … 156 171 157 172 [StorableConstructor] 158 protected SymbolicDataAnalysisProblem(bool deserializing) : base(deserializing) { }173 protected GESymbolicDataAnalysisProblem(bool deserializing) : base(deserializing) { } 159 174 [StorableHook(HookType.AfterDeserialization)] 160 175 private void AfterDeserialization() { … … 171 186 RegisterEventHandlers(); 172 187 } 173 protected SymbolicDataAnalysisProblem(SymbolicDataAnalysisProblem<T, U, V> original, Cloner cloner)188 protected GESymbolicDataAnalysisProblem(GESymbolicDataAnalysisProblem<T, U, V> original, Cloner cloner) 174 189 : base(original, cloner) { 175 190 RegisterEventHandlers(); 176 191 } 177 192 178 protected SymbolicDataAnalysisProblem(T problemData, U evaluator, V solutionCreator)193 protected GESymbolicDataAnalysisProblem(T problemData, U evaluator, V solutionCreator) 179 194 : base(evaluator, solutionCreator) { 180 195 Parameters.Add(new ValueParameter<T>(ProblemDataParameterName, ProblemDataParameterDescription, problemData)); … … 189 204 Parameters.Add(new FixedValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, RelativeNumberOfEvaluatedSamplesParameterDescription, new PercentValue(1))); 190 205 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false))); 206 IntMatrix m = new IntMatrix(new int[,] { { 0, 100 } }); 207 Parameters.Add(new ValueParameter<IntMatrix>(BoundsParameterName, BoundsParameterDescription, m)); 208 Parameters.Add(new ValueParameter<IGenotypeToPhenotypeMapper>(GenotypeToPhenotypeMapperParameterName, GenotypeToPhenotypeMapperParameterDescription, new DepthFirstMapper())); 191 209 192 210 SymbolicExpressionTreeInterpreterParameter.Hidden = true; … … 225 243 226 244 private void InitializeOperators() { 227 Operators.AddRange(ApplicationManager.Manager.GetInstances<I SymbolicExpressionTreeOperator>());245 Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>().OfType<IOperator>()); 228 246 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>()); 229 247 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); … … 266 284 } 267 285 286 /* 268 287 protected override void OnSolutionCreatorChanged() { 269 288 base.OnSolutionCreatorChanged(); 270 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged); 271 ParameterizeOperators(); 272 } 273 274 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 275 ParameterizeOperators(); 276 } 289 ParameterizeOperators(); 290 } 291 */ 277 292 278 293 protected override void OnEvaluatorChanged() { 279 294 base.OnEvaluatorChanged(); 295 Evaluator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(Evaluator_SymbolicExpressionTreeParameter_ActualNameChanged); 296 ParameterizeOperators(); 297 } 298 299 private void Evaluator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 280 300 ParameterizeOperators(); 281 301 } … … 302 322 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name; 303 323 } 324 /* 304 325 foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) { 305 326 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name; … … 310 331 op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name; 311 332 } 312 foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) { 333 */ 334 foreach (var op in operators.OfType<IGESymbolicDataAnalysisEvaluator<T>>()) { 313 335 op.ProblemDataParameter.ActualName = ProblemDataParameterName; 314 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;336 op.SymbolicExpressionTreeParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName; 315 337 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name; 316 338 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name; 317 339 op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name; 318 340 } 319 foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) { 320 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 321 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 322 } 323 foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) { 324 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 341 foreach (var op in operators.OfType<IIntegerVectorCrossover>()) { 342 op.ParentsParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName; 343 op.ChildParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName; 344 } 345 foreach (var op in operators.OfType<IIntegerVectorManipulator>()) { 346 op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 347 } 348 foreach (var op in operators.OfType<IIntegerVectorCreator>()) { 349 op.BoundsParameter.ActualName = BoundsParameter.Name; 350 op.LengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name; 325 351 } 326 352 foreach (var op in operators.OfType<ISymbolicExpressionTreeAnalyzer>()) { 327 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;353 op.SymbolicExpressionTreeParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName; 328 354 } 329 355 foreach (var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) { … … 334 360 } 335 361 foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) { 336 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;337 } 338 foreach (var op in operators.OfType<I SymbolicDataAnalysisValidationAnalyzer<U, T>>()) {362 op.SymbolicExpressionTreeParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName; 363 } 364 foreach (var op in operators.OfType<IGESymbolicDataAnalysisValidationAnalyzer<U, T>>()) { 339 365 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name; 340 366 op.ValidationPartitionParameter.ActualName = ValidationPartitionParameter.Name; -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveEvaluator.cs
r10072 r10073 20 20 #endregion 21 21 22 using System. Linq;22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System.Collections.Generic;29 using HeuristicLab. Encodings.SymbolicExpressionTreeEncoding;29 using HeuristicLab.Problems.DataAnalysis; 30 using HeuristicLab.Problems.DataAnalysis.Symbolic; 30 31 31 namespace HeuristicLab.Problems. DataAnalysis.Symbolic{32 namespace HeuristicLab.Problems.GrammaticalEvolution { 32 33 [StorableClass] 33 public abstract class SymbolicDataAnalysisSingleObjectiveEvaluator<T> : SymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisSingleObjectiveEvaluator<T>34 public abstract class GESymbolicDataAnalysisSingleObjectiveEvaluator<T> : GESymbolicDataAnalysisEvaluator<T>, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T> 34 35 where T : class, IDataAnalysisProblemData { 35 36 private const string QualityParameterName = "Quality"; … … 43 44 #endregion 44 45 [StorableConstructor] 45 protected SymbolicDataAnalysisSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }46 protected SymbolicDataAnalysisSingleObjectiveEvaluator(SymbolicDataAnalysisSingleObjectiveEvaluator<T> original, Cloner cloner)46 protected GESymbolicDataAnalysisSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { } 47 protected GESymbolicDataAnalysisSingleObjectiveEvaluator(GESymbolicDataAnalysisSingleObjectiveEvaluator<T> original, Cloner cloner) 47 48 : base(original, cloner) { 48 49 } 49 50 50 protected SymbolicDataAnalysisSingleObjectiveEvaluator()51 protected GESymbolicDataAnalysisSingleObjectiveEvaluator() 51 52 : base() { 52 53 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic data analysis solution.")); -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveProblem.cs
r10072 r10073 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.IntegerVectorEncoding; 27 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Problems.DataAnalysis; 32 using HeuristicLab.Problems.DataAnalysis.Symbolic; 30 33 31 namespace HeuristicLab.Problems. DataAnalysis.Symbolic{34 namespace HeuristicLab.Problems.GrammaticalEvolution { 32 35 [StorableClass] 33 public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> :SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem36 public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : GESymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem 34 37 where T : class,IDataAnalysisProblemData 35 where U : class, I SymbolicDataAnalysisSingleObjectiveEvaluator<T>36 where V : class, I SymbolicDataAnalysisSolutionCreator {38 where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T> 39 where V : class, IIntegerVectorCreator { 37 40 private const string MaximizationParameterName = "Maximization"; 38 41 private const string BestKnownQualityParameterName = "BestKnownQuality"; … … 66 69 67 70 [StorableConstructor] 68 protected SymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { }69 protected SymbolicDataAnalysisSingleObjectiveProblem(SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)71 protected GESymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { } 72 protected GESymbolicDataAnalysisSingleObjectiveProblem(GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner) 70 73 : base(original, cloner) { 71 74 RegisterEventHandler(); … … 73 76 } 74 77 75 public SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)78 public GESymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator) 76 79 : base(problemData, evaluator, solutionCreator) { 77 80 Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.")); -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs
r10072 r10073 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 22 using HeuristicLab.Common; 26 using HeuristicLab.Core;27 using HeuristicLab.Data;28 using HeuristicLab.Parameters;29 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 24 using HeuristicLab.Problems.DataAnalysis; 25 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 26 27 namespace HeuristicLab.Problems.GrammaticalEvolution { 31 28 [StorableClass] 32 public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator {29 public abstract class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, IGESymbolicRegressionSingleObjectiveEvaluator { 33 30 [StorableConstructor] 34 protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }36 protected SymbolicRegressionSingleObjectiveEvaluator(): base() {}31 protected GESymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { } 32 protected GESymbolicRegressionSingleObjectiveEvaluator(GESymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { } 33 protected GESymbolicRegressionSingleObjectiveEvaluator() : base() { } 37 34 } 38 35 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r10072 r10073 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.DataAnalysis; 29 using HeuristicLab.Problems.DataAnalysis.Symbolic; 28 30 29 namespace HeuristicLab.Problems. DataAnalysis.Symbolic.Regression {31 namespace HeuristicLab.Problems.GrammaticalEvolution { 30 32 [Item("Pearson R² Evaluator", "Calculates the square of the pearson correlation coefficient (also known as coefficient of determination) of a symbolic regression solution.")] 31 33 [StorableClass] 32 public class SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator :SymbolicRegressionSingleObjectiveEvaluator {34 public class GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator : GESymbolicRegressionSingleObjectiveEvaluator { 33 35 [StorableConstructor] 34 protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator original, Cloner cloner)36 protected GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(bool deserializing) : base(deserializing) { } 37 protected GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator original, Cloner cloner) 36 38 : base(original, cloner) { 37 39 } 38 40 public override IDeepCloneable Clone(Cloner cloner) { 39 return new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(this, cloner);41 return new GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(this, cloner); 40 42 } 41 43 42 public SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator() : base() { }44 public GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator() : base() { } 43 45 44 46 public override bool Maximization { get { return true; } } 45 47 46 48 public override IOperation Apply() { 47 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 var solution = GenotypeToPhenotypeMapperParameter.ActualValue.Map( 50 SymbolicExpressionTreeGrammarParameter.ActualValue, 51 IntegerVectorParameter.ActualValue 52 ); 53 SymbolicExpressionTreeParameter.ActualValue = solution; 48 54 IEnumerable<int> rows = GenerateRowsToEvaluate(); 49 55 50 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 56 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 57 solution, EstimationLimitsParameter.ActualValue.Lower, 58 EstimationLimitsParameter.ActualValue.Upper, 59 ProblemDataParameter.ActualValue, rows, 60 ApplyLinearScalingParameter.ActualValue.Value); 51 61 QualityParameter.ActualValue = new DoubleValue(quality); 52 62 … … 54 64 } 55 65 56 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 66 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 67 ISymbolicExpressionTree solution, 68 double lowerEstimationLimit, double upperEstimationLimit, 69 IRegressionProblemData problemData, 70 IEnumerable<int> rows, bool applyLinearScaling) { 57 71 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 58 72 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); … … 73 87 } 74 88 75 public override double Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, IRegressionProblemData problemData, IEnumerable<int> rows) { 89 public override double Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, 90 IRegressionProblemData problemData, IEnumerable<int> rows) { 76 91 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 77 92 EstimationLimitsParameter.ExecutionContext = context; 78 93 ApplyLinearScalingParameter.ExecutionContext = context; 79 94 80 double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 95 double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, 96 tree, EstimationLimitsParameter.ActualValue.Lower, 97 EstimationLimitsParameter.ActualValue.Upper, 98 problemData, rows, 99 ApplyLinearScalingParameter.ActualValue.Value); 81 100 82 101 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs
r10072 r10073 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.IntegerVectorEncoding; 25 26 using HeuristicLab.Parameters; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.DataAnalysis; 29 using HeuristicLab.Problems.DataAnalysis.Symbolic; 30 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 27 31 28 namespace HeuristicLab.Problems. DataAnalysis.Symbolic.Regression {29 [Item(" Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem.")]32 namespace HeuristicLab.Problems.GrammaticalEvolution { 33 [Item("Grammatical Evolution Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem, implemented in Grammatical Evolution.")] 30 34 [StorableClass] 31 35 [Creatable("Problems")] 32 public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem {36 public class GESymbolicRegressionSingleObjectiveProblem : GESymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, IGESymbolicRegressionSingleObjectiveEvaluator, IIntegerVectorCreator>, IRegressionProblem { 33 37 private const double PunishmentFactor = 10; 34 38 private const int InitialMaximumTreeDepth = 8; … … 48 52 #endregion 49 53 [StorableConstructor] 50 protected SymbolicRegressionSingleObjectiveProblem(bool deserializing) : base(deserializing) { }51 protected SymbolicRegressionSingleObjectiveProblem(SymbolicRegressionSingleObjectiveProblem original, Cloner cloner)54 protected GESymbolicRegressionSingleObjectiveProblem(bool deserializing) : base(deserializing) { } 55 protected GESymbolicRegressionSingleObjectiveProblem(GESymbolicRegressionSingleObjectiveProblem original, Cloner cloner) 52 56 : base(original, cloner) { 53 57 RegisterEventHandlers(); 54 58 } 55 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionSingleObjectiveProblem(this, cloner); }59 public override IDeepCloneable Clone(Cloner cloner) { return new GESymbolicRegressionSingleObjectiveProblem(this, cloner); } 56 60 57 public SymbolicRegressionSingleObjectiveProblem()58 : base(new RegressionProblemData(), new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {61 public GESymbolicRegressionSingleObjectiveProblem() 62 : base(new RegressionProblemData(), new GESymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(), new UniformRandomIntegerVectorCreator()) { 59 63 Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription)); 60 64 -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisEvaluator.cs
r10072 r10073 19 19 */ 20 20 #endregion 21 21 22 using HeuristicLab.Core; 22 23 using HeuristicLab.Data; 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 23 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 24 26 using HeuristicLab.Optimization; 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 26 public interface ISymbolicDataAnalysisEvaluator<T> : IEvaluator 27 where T : class,IDataAnalysisProblemData { 28 ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; } 27 using HeuristicLab.Problems.DataAnalysis; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 using HeuristicLab.Problems.GrammaticalEvolution.Mappers; 30 31 namespace HeuristicLab.Problems.GrammaticalEvolution { 32 33 public interface IGESymbolicDataAnalysisEvaluator<T> : IEvaluator 34 where T : class, IDataAnalysisProblemData { 35 36 ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; } // phenotype 29 37 IValueLookupParameter<IntRange> EvaluationPartitionParameter { get; } 30 38 IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; } … … 32 40 33 41 IValueLookupParameter<T> ProblemDataParameter { get; } 42 43 ILookupParameter<IntegerVector> IntegerVectorParameter { get; } // genotype 44 ILookupParameter<IGenotypeToPhenotypeMapper> GenotypeToPhenotypeMapperParameter { get; } 45 IValueLookupParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter { get; } 34 46 } 35 47 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisSingleObjectiveEvaluator.cs
r10072 r10073 20 20 #endregion 21 21 22 using HeuristicLab.Optimization;23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;24 22 using System.Collections.Generic; 25 23 using HeuristicLab.Core; 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 public interface ISymbolicDataAnalysisSingleObjectiveEvaluator<T> : ISymbolicDataAnalysisEvaluator<T>, ISingleObjectiveEvaluator 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 using HeuristicLab.Optimization; 26 using HeuristicLab.Problems.DataAnalysis; 27 28 namespace HeuristicLab.Problems.GrammaticalEvolution { 29 public interface IGESymbolicDataAnalysisSingleObjectiveEvaluator<T> : IGESymbolicDataAnalysisEvaluator<T>, ISingleObjectiveEvaluator 28 30 where T : class,IDataAnalysisProblemData { 29 31 bool Maximization { get; } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisValidationAnalyzer.cs
r10072 r10073 21 21 using HeuristicLab.Core; 22 22 using HeuristicLab.Data; 23 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 24 public interface ISymbolicDataAnalysisValidationAnalyzer<T, U> : ISymbolicDataAnalysisAnalyzer, ISymbolicDataAnalysisInterpreterOperator 25 where T : class,ISymbolicDataAnalysisEvaluator<U> 23 using HeuristicLab.Problems.DataAnalysis; 24 using HeuristicLab.Problems.DataAnalysis.Symbolic; 25 26 namespace HeuristicLab.Problems.GrammaticalEvolution { 27 public interface IGESymbolicDataAnalysisValidationAnalyzer<T, U> : ISymbolicDataAnalysisAnalyzer, ISymbolicDataAnalysisInterpreterOperator 28 where T : class,IGESymbolicDataAnalysisEvaluator<U> 26 29 where U : class, IDataAnalysisProblemData { 27 30 ILookupParameter<IRandom> RandomParameter { get; } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicRegressionEvaluator.cs
r10072 r10073 20 20 #endregion 21 21 22 using HeuristicLab.Problems.DataAnalysis; 22 23 23 namespace HeuristicLab.Problems. DataAnalysis.Symbolic.Regression {24 public interface I SymbolicRegressionEvaluator : ISymbolicDataAnalysisEvaluator<IRegressionProblemData> {24 namespace HeuristicLab.Problems.GrammaticalEvolution { 25 public interface IGESymbolicRegressionEvaluator : IGESymbolicDataAnalysisEvaluator<IRegressionProblemData> { 25 26 } 26 27 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicRegressionSingleObjectiveEvaluator.cs
r10072 r10073 20 20 #endregion 21 21 22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 23 public interface ISymbolicRegressionSingleObjectiveEvaluator : ISymbolicRegressionEvaluator, ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData> { 22 using HeuristicLab.Problems.DataAnalysis; 23 24 namespace HeuristicLab.Problems.GrammaticalEvolution { 25 public interface IGESymbolicRegressionSingleObjectiveEvaluator : IGESymbolicRegressionEvaluator, 26 IGESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData> { 24 27 } 25 28 }
Note: See TracChangeset
for help on using the changeset viewer.