Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5014


Ignore:
Timestamp:
12/03/10 14:11:02 (13 years ago)
Author:
mkommend
Message:

Corrected SubTreeCrossover and ReplaceBranchManipulation to handle MaxExpressionDepth correctly. Additionally MaxExpressionDepth < 3 is not allowed.
(ticket #1315).

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs

    r4722 r5014  
    6666      SymbolicExpressionTreeNode crossoverPoint0;
    6767      int replacedSubtreeIndex;
    68       SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeSize - 1, maxTreeHeight - 1, out crossoverPoint0, out replacedSubtreeIndex);
     68      SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeSize, maxTreeHeight, out crossoverPoint0, out replacedSubtreeIndex);
    6969
    7070      // calculate the max size and height that the inserted branch can have
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ReplaceBranchManipulation.cs

    r4722 r5014  
    5353                               from subtree in parent.SubTrees
    5454                               select new { Parent = parent, Node = subtree, Index = parent.SubTrees.IndexOf(subtree) }).SelectRandom(random);
     55
     56      int maxSize = maxTreeSize - symbolicExpressionTree.Size + manipulationPoint.Node.GetSize();
     57      int maxHeight = maxTreeHeight - symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight();
    5558      // find possible symbols for the node (also considering the existing branches below it)
    56       var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index)
     59      var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index, maxHeight)
    5760                           select symbol;
     61      if (allowedSymbols.Count() <= 1) return;
    5862
    59       if (allowedSymbols.Count() <= 1) {
    60         return;
    61       }
    62       var oldBranch = manipulationPoint.Node;
    63       int oldBranchSize = manipulationPoint.Node.GetSize();
    64 
    65       var seedSymbol = SelectRandomSymbol(random, allowedSymbols);
    66 
    67       // replace the old node with the new node
     63      var seedSymbol = SelectRandomSymbol(random, allowedSymbols);  // replace the old node with the new node
    6864      var seedNode = seedSymbol.CreateTreeNode();
    6965      if (seedNode.HasLocalParameters)
     
    7268      manipulationPoint.Parent.RemoveSubTree(manipulationPoint.Index);
    7369      manipulationPoint.Parent.InsertSubTree(manipulationPoint.Index, seedNode);
    74       int maxSize = Math.Max(oldBranchSize, seedNode.Grammar.GetMinExpressionLength(seedNode.Symbol)) * 2;
    75       var bla = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxSize, 0, 0);
     70      seedNode = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxHeight, 0, 0);
    7671      success = true;
    7772    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r4722 r5014  
    178178      return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex));
    179179    }
     180    public IEnumerable<Symbol> GetAllowedSymbols(int argumentIndex, int maxExpressionDepth) {
     181      return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex) && Grammar.GetMinExpressionDepth(s) <= maxExpressionDepth);
     182    }
     183
    180184    public int GetMinSubtreeCount() {
    181185      return Grammar.GetMinSubtreeCount(Symbol);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs

    r4801 r5014  
    156156      : base(original, cloner) {
    157157      operators = original.operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
     158      RegisterParameterValueEvents();
    158159      RegisterParameterEvents();
    159       RegisterParameterValueEvents();
    160160    }
    161161    public SymbolicRegressionProblemBase()
     
    171171      Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("FunctionTreeGrammar", "The grammar that should be used for symbolic regression models.", globalGrammar));
    172172      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the symbolic expression.", new IntValue(100)));
    173       Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the symbolic expression.", new IntValue(10)));
     173      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the symbolic expression. The minimum depth needed for the algorithm is 3 because two levels are reserved for the ProgramRoot and the Start symbol.", new IntValue(10)));
    174174      Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));
    175175      Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));
     
    182182      UpdateEstimationLimits();
    183183      InitializeOperators();
     184      RegisterParameterValueEvents();
    184185      RegisterParameterEvents();
    185       RegisterParameterValueEvents();
    186     }
    187 
    188     private void RegisterParameterValueEvents() {
     186    }
     187
     188    private void RegisterParameterEvents() {
    189189      MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
    190190      MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
     191      MaxExpressionDepthParameter.ValueChanged += new EventHandler(MaxExpressionDepthParameter_ValueChanged);
    191192      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    192193      FunctionTreeGrammarParameter.ValueChanged += new EventHandler(FunctionTreeGrammarParameter_ValueChanged);
    193     }
    194 
    195     private void RegisterParameterEvents() {
     194      SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
     195    }
     196
     197    private void RegisterParameterValueEvents() {
    196198      MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    197199      MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    198       SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
     200      MaxExpressionDepthParameter.Value.ValueChanged += new EventHandler(MaxExpressionDepthParameterValue_ValueChanged);
    199201    }
    200202
     
    252254      OnArchitectureParameterChanged(e);
    253255    }
     256
     257    private void MaxExpressionDepthParameter_ValueChanged(object sender, EventArgs e) {
     258      MaxExpressionDepthParameterValue_ValueChanged(sender, e);
     259      MaxExpressionDepthParameter.Value.ValueChanged += MaxExpressionDepthParameterValue_ValueChanged;
     260    }
     261    private void MaxExpressionDepthParameterValue_ValueChanged(object sender, EventArgs e) {
     262      if (MaxExpressionDepth != null && MaxExpressionDepth.Value < 3)
     263        MaxExpressionDepth.Value = 3;
     264    }
    254265    #endregion
    255266
     
    261272      if (operators == null) InitializeOperators();
    262273      #endregion
     274      RegisterParameterValueEvents();
    263275      RegisterParameterEvents();
    264       RegisterParameterValueEvents();
    265276    }
    266277
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/EstimatedValuesView.cs

    r4068 r5014  
    4747      InitializeComponent();
    4848      matrixView = new StringConvertibleMatrixView();
     49      matrixView.ShowRowsAndColumnsTextBox = false;
     50      matrixView.ShowStatisticalInformation = false;
    4951      matrixView.Dock = DockStyle.Fill;
    5052      this.Controls.Add(matrixView);
     
    8284        DoubleMatrix matrix = null;
    8385        if (Content != null) {
    84           double[,] values =
    85           MatrixExtensions<double>.Create(
    86             Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable.Value),
    87             Content.EstimatedValues.ToArray());
     86          double[,] values = new double[Content.ProblemData.Dataset.Rows, 4];
     87
     88          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable.Value);
     89          double[] estimated = Content.EstimatedValues.ToArray();
     90          for (int row = 0; row < target.Length; row++) {
     91            values[row, 0] = target[row];
     92            values[row, 1] = estimated[row];
     93            values[row, 2] = estimated[row] - target[row];
     94            values[row, 3] = estimated[row] / target[row] - 1;
     95          }
     96
    8897          matrix = new DoubleMatrix(values);
    89           matrix.ColumnNames = new string[] { "Original", "Estimated" };
     98          matrix.ColumnNames = new string[] { "Original", "Estimated", "Error", "Rel. Error" };
    9099        }
    91100        matrixView.Content = matrix;
Note: See TracChangeset for help on using the changeset viewer.