Changeset 10276
- Timestamp:
- 01/04/14 12:23:59 (11 years ago)
- Location:
- branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs
r10229 r10276 65 65 tree.Root = rootNode; 66 66 67 //int genotypeIndex = 0;68 //int currSubtreeCount = 1;69 //MapDepthFirstRecursively(startNode, genotype,70 // grammar, genotype.Length,71 // ref genotypeIndex, ref currSubtreeCount,72 // new MersenneTwister());73 74 67 MapDepthFirstIteratively(startNode, genotype, grammar, 75 68 genotype.Length, new MersenneTwister()); 76 69 return tree; 77 }78 79 80 /// <summary>81 /// Genotype-to-Phenotype mapper (recursive depth-first approach).82 /// Appends maximum allowed children (non-terminal symbols) to83 /// <paramref name="currentNode"/>, as long as <paramref name="currSubtreeCount"/>84 /// doesn't exceed <paramref name="maxSubtreeCount"/>.85 /// If at most <paramref name="maxSubtreeCount"/> subtrees were created,86 /// each non-full node is filled with randomly chosen nodes87 /// (non-terminal and terminal), and each non-terminal node is again filled with a terminal node.88 /// </summary>89 /// <param name="currentNode">current parent node</param>90 /// <param name="genotype">integer vector, which should be mapped to a tree</param>91 /// <param name="grammar">grammar to determine the allowed child symbols for currentNode </param>92 /// <param name="maxSubtreeCount">maximum allowed subtrees (= number of used genomes)</param>93 /// <param name="genotypeIndex">current index in integer vector</param>94 /// <param name="currSubtreeCount">number of already determined subtrees (filled or still incomplete)</param>95 private void MapDepthFirstRecursively(ISymbolicExpressionTreeNode currentNode,96 IntegerVector genotype,97 ISymbolicExpressionGrammar grammar,98 int maxSubtreeCount,99 ref int genotypeIndex,100 ref int currSubtreeCount,101 IRandom random) {102 103 // TODO: check, if method calls of GetNewChildNode() and GetRandomTerminalNode() don't return null104 if (currSubtreeCount < maxSubtreeCount) {105 106 var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex, random);107 108 if ((currSubtreeCount + newNode.Symbol.MinimumArity) > maxSubtreeCount) {109 // TODO: maybe check, if there is any node, which fits in the tree yet110 currentNode.AddSubtree(GetRandomTerminalNode(currentNode, grammar, random));111 } else {112 currentNode.AddSubtree(newNode);113 genotypeIndex++;114 currSubtreeCount += newNode.Symbol.MinimumArity;115 116 while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) {117 MapDepthFirstRecursively(newNode, genotype,118 grammar, maxSubtreeCount,119 ref genotypeIndex, ref currSubtreeCount, random);120 }121 }122 123 } else {124 while (currentNode.Symbol.MinimumArity > currentNode.SubtreeCount) {125 var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex, random);126 currentNode.AddSubtree(newNode);127 genotypeIndex++;128 while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) {129 newNode.AddSubtree(GetRandomTerminalNode(newNode, grammar, random));130 }131 }132 }133 70 } 134 71 -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisProblem.cs
r10268 r10276 51 51 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar"; 52 52 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 53 //private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";54 53 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 55 //private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions";56 //private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments";57 54 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 58 55 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; … … 90 87 get { return (IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; } 91 88 } 92 //public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {93 // get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }94 //}95 89 public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { 96 90 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; } 97 91 } 98 //public IFixedValueParameter<IntValue> MaximumFunctionDefinitionsParameter {99 // get { return (IFixedValueParameter<IntValue>)Parameters[MaximumFunctionDefinitionsParameterName]; }100 //}101 //public IFixedValueParameter<IntValue> MaximumFunctionArgumentsParameter {102 // get { return (IFixedValueParameter<IntValue>)Parameters[MaximumFunctionArgumentsParameterName]; }103 //}104 92 public IFixedValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { 105 93 get { return (IFixedValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } … … 143 131 } 144 132 145 //public IntValue MaximumSymbolicExpressionTreeDepth {146 // get { return MaximumSymbolicExpressionTreeDepthParameter.Value; }147 //}148 133 public IntValue MaximumSymbolicExpressionTreeLength { 149 134 get { return MaximumSymbolicExpressionTreeLengthParameter.Value; } 150 135 } 151 //public IntValue MaximumFunctionDefinitions { 152 // get { return MaximumFunctionDefinitionsParameter.Value; } 153 //} 154 //public IntValue MaximumFunctionArguments { 155 // get { return MaximumFunctionArgumentsParameter.Value; } 156 //} 136 157 137 public PercentValue RelativeNumberOfEvaluatedSamples { 158 138 get { return RelativeNumberOfEvaluatedSamplesParameter.Value; } … … 186 166 Parameters.Add(new ValueParameter<GESymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription)); 187 167 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, SymoblicExpressionTreeInterpreterParameterDescription)); 188 //Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, MaximumSymbolicExpressionTreeDepthParameterDescription));189 168 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, MaximumSymbolicExpressionTreeLengthParameterDescription)); 190 //Parameters.Add(new FixedValueParameter<IntValue>(MaximumFunctionDefinitionsParameterName, MaximumFunctionDefinitionsParameterDescription));191 //Parameters.Add(new FixedValueParameter<IntValue>(MaximumFunctionArgumentsParameterName, MaximumFunctionArgumentsParameterDescription));192 169 Parameters.Add(new FixedValueParameter<IntRange>(FitnessCalculationPartitionParameterName, FitnessCalculationPartitionParameterDescription)); 193 170 Parameters.Add(new FixedValueParameter<IntRange>(ValidationPartitionParameterName, ValidationPartitionParameterDescription)); … … 199 176 200 177 SymbolicExpressionTreeInterpreterParameter.Hidden = true; 201 //MaximumFunctionArgumentsParameter.Hidden = true;202 //MaximumFunctionDefinitionsParameter.Hidden = true;203 178 ApplyLinearScalingParameter.Hidden = true; 204 179 … … 232 207 private void InitializeOperators() { 233 208 Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>().OfType<IOperator>()); 234 // Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());235 209 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 236 210 Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer()); … … 246 220 247 221 RegisterGrammarHandler(); 248 249 //MaximumFunctionArguments.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);250 //MaximumFunctionDefinitions.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);251 //MaximumSymbolicExpressionTreeDepth.ValueChanged += new EventHandler(MaximumSymbolicExpressionTreeDepth_ValueChanged);252 222 } 253 223 … … 263 233 } 264 234 265 //private void MaximumSymbolicExpressionTreeDepth_ValueChanged(object sender, EventArgs e) {266 // if (MaximumSymbolicExpressionTreeDepth != null && MaximumSymbolicExpressionTreeDepth.Value < 3)267 // MaximumSymbolicExpressionTreeDepth.Value = 3;268 //}269 270 //protected override void OnSolutionCreatorChanged() {271 // base.OnSolutionCreatorChanged();272 // ParameterizeOperators();273 //}274 275 235 protected override void OnEvaluatorChanged() { 276 236 base.OnEvaluatorChanged(); … … 304 264 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name; 305 265 } 306 /*307 foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {308 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name;309 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;310 }311 foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {312 op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name;313 op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name;314 }315 */316 266 foreach (var op in operators.OfType<IGESymbolicDataAnalysisEvaluator<T>>()) { 317 267 op.ProblemDataParameter.ActualName = ProblemDataParameterName; … … 354 304 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 355 305 } 356 /*357 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {358 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;359 op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;360 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;361 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;362 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;363 }364 */365 306 } 366 307 -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveEvaluator.cs
r10263 r10276 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.IntegerVectorEncoding;27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;28 25 using HeuristicLab.Parameters; 29 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 27 using HeuristicLab.Problems.DataAnalysis; 31 using HeuristicLab.Problems.DataAnalysis.Symbolic;32 28 33 29 namespace HeuristicLab.Problems.GrammaticalEvolution { -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicExpressionGrammar.cs
r10268 r10276 28 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 29 using HeuristicLab.Random; 30 using Variable = HeuristicLab.Core.Variable;31 30 32 31 namespace HeuristicLab.Problems.GrammaticalEvolution { -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs
r10263 r10276 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.IntegerVectorEncoding;26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;27 24 using HeuristicLab.Parameters; 28 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 33 30 [StorableClass] 34 31 public class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, 35 32 IGESymbolicRegressionSingleObjectiveEvaluator { 36 33 37 34 public const string EvaluatorParameterName = "Evaluator"; -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs
r10268 r10276 31 31 32 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.")] 33 [Item("Grammatical Evolution Symbolic Regression Problem (single objective)", 34 "Represents a single objective symbolic regression problem, implemented in Grammatical Evolution.")] 34 35 [StorableClass] 35 36 [Creatable("Problems")] … … 37 38 IRegressionProblem { 38 39 private const double PunishmentFactor = 10; 39 //private const int InitialMaximumTreeDepth = 8;40 40 private const int InitialMaximumTreeLength = 25; 41 41 private const string EstimationLimitsParameterName = "EstimationLimits"; 42 private const string EstimationLimitsParameterDescription = "The limits for the estimated value that can be returned by the symbolic regression model."; 42 private const string EstimationLimitsParameterDescription 43 = "The limits for the estimated value that can be returned by the symbolic regression model."; 43 44 44 45 #region parameter properties … … 69 70 ApplyLinearScalingParameter.Value.Value = true; 70 71 Maximization.Value = true; 71 //MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;72 72 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 73 73 -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisProblem.cs
r10268 r10276 25 25 using HeuristicLab.Problems.DataAnalysis; 26 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 27 using HeuristicLab.Problems.GrammaticalEvolution;28 27 29 28 namespace HeuristicLab.Problems.GrammaticalEvolution { 30 29 public interface IGESymbolicDataAnalysisProblem : IDataAnalysisProblem, IHeuristicOptimizationProblem { 30 31 31 IValueParameter<GESymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter { get; } 32 32 IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; } 33 //IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { get; }34 33 IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { get; } 35 //IFixedValueParameter<IntValue> MaximumFunctionDefinitionsParameter { get; }36 //IFixedValueParameter<IntValue> MaximumFunctionArgumentsParameter { get; }37 34 IFixedValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; } 38 35 IFixedValueParameter<IntRange> FitnessCalculationPartitionParameter { get; } … … 41 38 GESymbolicExpressionGrammar SymbolicExpressionTreeGrammar { get; set; } 42 39 ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { get; set; } 43 //IntValue MaximumSymbolicExpressionTreeDepth { get; }44 40 IntValue MaximumSymbolicExpressionTreeLength { get; } 45 //IntValue MaximumFunctionDefinitions { get; }46 //IntValue MaximumFunctionArguments { get; }47 41 PercentValue RelativeNumberOfEvaluatedSamples { get; } 48 42 IntRange FitnessCalculationPartition { get; } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisSingleObjectiveEvaluator.cs
r10263 r10276 20 20 #endregion 21 21 22 using System.Collections.Generic;23 using HeuristicLab.Core;24 using HeuristicLab.Encodings.IntegerVectorEncoding;25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;26 22 using HeuristicLab.Optimization; 27 23 using HeuristicLab.Problems.DataAnalysis;
Note: See TracChangeset
for help on using the changeset viewer.