Changeset 10276


Ignore:
Timestamp:
01/04/14 12:23:59 (6 years ago)
Author:
sawinkle
Message:

#2109:
Refactoring:

  • Removed recursive version of mapping in /Mappers/DepthFirstMapper.cs, because only the iterative one is used.
  • Removed unused using statements and unused commented code.
Location:
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs

    r10229 r10276  
    6565      tree.Root = rootNode;
    6666
    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 
    7467      MapDepthFirstIteratively(startNode, genotype, grammar,
    7568                               genotype.Length, new MersenneTwister());
    7669      return tree;
    77     }
    78 
    79 
    80     /// <summary>
    81     /// Genotype-to-Phenotype mapper (recursive depth-first approach).
    82     /// Appends maximum allowed children (non-terminal symbols) to
    83     /// <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 nodes
    87     /// (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 null
    104       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 yet
    110           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       }
    13370    }
    13471
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisProblem.cs

    r10268 r10276  
    5151    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
    5252    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    53     //private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    5453    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    55     //private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions";
    56     //private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments";
    5754    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
    5855    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
     
    9087      get { return (IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
    9188    }
    92     //public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    93     //  get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    94     //}
    9589    public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    9690      get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    9791    }
    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     //}
    10492    public IFixedValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
    10593      get { return (IFixedValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
     
    143131    }
    144132
    145     //public IntValue MaximumSymbolicExpressionTreeDepth {
    146     //  get { return MaximumSymbolicExpressionTreeDepthParameter.Value; }
    147     //}
    148133    public IntValue MaximumSymbolicExpressionTreeLength {
    149134      get { return MaximumSymbolicExpressionTreeLengthParameter.Value; }
    150135    }
    151     //public IntValue MaximumFunctionDefinitions {
    152     //  get { return MaximumFunctionDefinitionsParameter.Value; }
    153     //}
    154     //public IntValue MaximumFunctionArguments {
    155     //  get { return MaximumFunctionArgumentsParameter.Value; }
    156     //}
     136
    157137    public PercentValue RelativeNumberOfEvaluatedSamples {
    158138      get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
     
    186166      Parameters.Add(new ValueParameter<GESymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription));
    187167      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, SymoblicExpressionTreeInterpreterParameterDescription));
    188       //Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, MaximumSymbolicExpressionTreeDepthParameterDescription));
    189168      Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, MaximumSymbolicExpressionTreeLengthParameterDescription));
    190       //Parameters.Add(new FixedValueParameter<IntValue>(MaximumFunctionDefinitionsParameterName, MaximumFunctionDefinitionsParameterDescription));
    191       //Parameters.Add(new FixedValueParameter<IntValue>(MaximumFunctionArgumentsParameterName, MaximumFunctionArgumentsParameterDescription));
    192169      Parameters.Add(new FixedValueParameter<IntRange>(FitnessCalculationPartitionParameterName, FitnessCalculationPartitionParameterDescription));
    193170      Parameters.Add(new FixedValueParameter<IntRange>(ValidationPartitionParameterName, ValidationPartitionParameterDescription));
     
    199176
    200177      SymbolicExpressionTreeInterpreterParameter.Hidden = true;
    201       //MaximumFunctionArgumentsParameter.Hidden = true;
    202       //MaximumFunctionDefinitionsParameter.Hidden = true;
    203178      ApplyLinearScalingParameter.Hidden = true;
    204179
     
    232207    private void InitializeOperators() {
    233208      Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>().OfType<IOperator>());
    234       // Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());
    235209      Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
    236210      Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
     
    246220
    247221      RegisterGrammarHandler();
    248 
    249       //MaximumFunctionArguments.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    250       //MaximumFunctionDefinitions.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    251       //MaximumSymbolicExpressionTreeDepth.ValueChanged += new EventHandler(MaximumSymbolicExpressionTreeDepth_ValueChanged);
    252222    }
    253223
     
    263233    }
    264234
    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 
    275235    protected override void OnEvaluatorChanged() {
    276236      base.OnEvaluatorChanged();
     
    304264        op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
    305265      }
    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       */
    316266      foreach (var op in operators.OfType<IGESymbolicDataAnalysisEvaluator<T>>()) {
    317267        op.ProblemDataParameter.ActualName = ProblemDataParameterName;
     
    354304        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    355305      }
    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       */
    365306    }
    366307
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveEvaluator.cs

    r10263 r10276  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Data;
    26 using HeuristicLab.Encodings.IntegerVectorEncoding;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2825using HeuristicLab.Parameters;
    2926using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3027using HeuristicLab.Problems.DataAnalysis;
    31 using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3228
    3329namespace HeuristicLab.Problems.GrammaticalEvolution {
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicExpressionGrammar.cs

    r10268 r10276  
    2828using HeuristicLab.Problems.DataAnalysis.Symbolic;
    2929using HeuristicLab.Random;
    30 using Variable = HeuristicLab.Core.Variable;
    3130
    3231namespace HeuristicLab.Problems.GrammaticalEvolution {
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs

    r10263 r10276  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    25 using HeuristicLab.Encodings.IntegerVectorEncoding;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2724using HeuristicLab.Parameters;
    2825using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3330  [StorableClass]
    3431  public class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>,
    35                                                                        IGESymbolicRegressionSingleObjectiveEvaluator {
     32                                                              IGESymbolicRegressionSingleObjectiveEvaluator {
    3633
    3734    public const string EvaluatorParameterName = "Evaluator";
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs

    r10268 r10276  
    3131
    3232namespace 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.")]
    3435  [StorableClass]
    3536  [Creatable("Problems")]
     
    3738                                                            IRegressionProblem {
    3839    private const double PunishmentFactor = 10;
    39     //private const int InitialMaximumTreeDepth = 8;
    4040    private const int InitialMaximumTreeLength = 25;
    4141    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.";
    4344
    4445    #region parameter properties
     
    6970      ApplyLinearScalingParameter.Value.Value = true;
    7071      Maximization.Value = true;
    71       //MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
    7272      MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
    7373
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisProblem.cs

    r10268 r10276  
    2525using HeuristicLab.Problems.DataAnalysis;
    2626using HeuristicLab.Problems.DataAnalysis.Symbolic;
    27 using HeuristicLab.Problems.GrammaticalEvolution;
    2827
    2928namespace HeuristicLab.Problems.GrammaticalEvolution {
    3029  public interface IGESymbolicDataAnalysisProblem : IDataAnalysisProblem, IHeuristicOptimizationProblem {
     30
    3131    IValueParameter<GESymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter { get; }
    3232    IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; }
    33     //IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { get; }
    3433    IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { get; }
    35     //IFixedValueParameter<IntValue> MaximumFunctionDefinitionsParameter { get; }
    36     //IFixedValueParameter<IntValue> MaximumFunctionArgumentsParameter { get; }
    3734    IFixedValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; }
    3835    IFixedValueParameter<IntRange> FitnessCalculationPartitionParameter { get; }
     
    4138    GESymbolicExpressionGrammar SymbolicExpressionTreeGrammar { get; set; }
    4239    ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { get; set; }
    43     //IntValue MaximumSymbolicExpressionTreeDepth { get; }
    4440    IntValue MaximumSymbolicExpressionTreeLength { get; }
    45     //IntValue MaximumFunctionDefinitions { get; }
    46     //IntValue MaximumFunctionArguments { get; }
    4741    PercentValue RelativeNumberOfEvaluatedSamples { get; }
    4842    IntRange FitnessCalculationPartition { get; }
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisSingleObjectiveEvaluator.cs

    r10263 r10276  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using HeuristicLab.Core;
    24 using HeuristicLab.Encodings.IntegerVectorEncoding;
    25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2622using HeuristicLab.Optimization;
    2723using HeuristicLab.Problems.DataAnalysis;
Note: See TracChangeset for help on using the changeset viewer.