Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7832


Ignore:
Timestamp:
05/15/12 19:09:09 (13 years ago)
Author:
gkronber
Message:

#1847 added operator for replacing branches with semantically similar branches

Location:
branches/GP-MoveOperators
Files:
11 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r7802 r7832  
    162162    <Compile Include="Moves\ChangeNodeTypeMove.cs" />
    163163    <Compile Include="Moves\ChangeNodeTypeMoveMaker.cs" />
     164    <Compile Include="Moves\ChangeNodeTypeMoveSoftTabuCriterion.cs">
     165      <SubType>Code</SubType>
     166    </Compile>
    164167    <Compile Include="Moves\ChangeNodeTypeMultiMoveGenerator.cs" />
     168    <Compile Include="Moves\ReplaceBranchMoveTabuMaker.cs" />
     169    <Compile Include="Moves\ReplaceBranchMoveSoftTabuCriterion.cs" />
     170    <Compile Include="Moves\ReplaceBranchMoveMaker.cs" />
     171    <Compile Include="Moves\ReplaceBranchMove.cs" />
     172    <Compile Include="Moves\SymbolicExpressionTreeMoveAttribute.cs" />
    165173    <Compile Include="Moves\ShakeMultiMoveGenerator.cs" />
    166174    <Compile Include="Moves\ShakeMoveGenerator.cs" />
     175    <Compile Include="Moves\ChangeNodeTypeMoveHardTabuCriterion.cs" />
     176    <Compile Include="Moves\ChangeNodeTypeMoveTabuMaker.cs" />
     177    <Compile Include="Moves\ChangeNodeTypeMoveAbsoluteAttribute.cs" />
    167178    <Compile Include="Plugin.cs" />
    168179    <Compile Include="SymbolicExpressionGrammarBase.cs" />
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeMoveOperator.cs

    r7802 r7832  
    2525namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    2626  public interface ISymbolicExpressionTreeMoveOperator : ISymbolicExpressionTreeOperator, IMoveOperator {
    27     ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
     27    ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
    2828  }
    2929}
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ChangeNodeTypeMoveGenerator.cs

    r7802 r7832  
    3030
    3131namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    32   [Item("ChangeNodeTypeMoveGenerator", "Operator that generates moves for changing the symbol of a single symbolic expression tree node.")]
     32  [Item("ChangeNodeTypeExhaustiveMoveGenerator", "Operator that generates moves for changing the symbol of a single symbolic expression tree node.")]
    3333  [StorableClass]
    34   public class ChangeNodeTypeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, IMoveGenerator, IStochasticOperator {
     34  public class ChangeNodeTypeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, IExhaustiveMoveGenerator, IStochasticOperator {
    3535    public override bool CanChangeName {
    3636      get { return false; }
     
    3939      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    4040    }
    41     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    42       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
     41    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     42      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    4343    }
    4444    public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter {
     
    5555      : base() {
    5656      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
    57       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
     57      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
    5858      Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes."));
    5959      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
     
    6666
    6767    public override IOperation Apply() {
    68       SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
     68      var tree = SymbolicExpressionTreeParameter.ActualValue;
    6969      var moves = GenerateMoves(tree);
    7070      string moveParameterName = ChangeNodeTypeMoveParameter.ActualName;
     
    8282    }
    8383
    84     public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(SymbolicExpressionTree tree) {
     84    public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree) {
    8585      var g = tree.Root.Grammar;
    8686      return (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix()
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ChangeNodeTypeMoveMaker.cs

    r7802 r7832  
    4545      get { return (ILookupParameter<ChangeNodeTypeMove>)Parameters["ChangeNodeTypeMove"]; }
    4646    }
    47     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    48       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
     47    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     48      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    4949    }
    5050
     
    5757      Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The move to evaluate."));
    5858      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
    59       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree on which the move should be applied."));
     59      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree on which the move should be applied."));
    6060    }
    6161
     
    6666    public override IOperation Apply() {
    6767      ChangeNodeTypeMove move = ChangeNodeTypeMoveParameter.ActualValue;
    68       SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
     68      var tree = SymbolicExpressionTreeParameter.ActualValue;
    6969      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
    7070      DoubleValue quality = QualityParameter.ActualValue;
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ChangeNodeTypeMultiMoveGenerator.cs

    r7802 r7832  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    4645      set { SampleSizeParameter.Value = value; }
    4746    }
    48     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    49       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
     47    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     48      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    5049    }
    5150    public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter {
     
    6463      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
    6564
    66       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
     65      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
    6766      Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes."));
    6867      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
     
    7574
    7675    public override IOperation Apply() {
    77       SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
    78       var moves = ChangeNodeTypeMoveGenerator.GenerateMoves(tree).ToArray();
     76      var tree = SymbolicExpressionTreeParameter.ActualValue;
     77
     78
    7979      string moveParameterName = ChangeNodeTypeMoveParameter.ActualName;
    8080      var moveScopes = new List<Scope>();
     
    8282      int n = SampleSizeParameter.ActualValue.Value;
    8383
    84       var rand = Enumerable.Range(0, moves.Length).Select(i => random.NextDouble()).ToArray();
    85       Array.Sort(rand, moves);
    86       n = Math.Min(n, moves.Length);
     84      var moves = GenerateMoves(tree, random, n);
    8785
    88       foreach (var m in moves.Take(n)) {
     86      foreach (var m in moves) {
    8987        if (m.NewChild.HasLocalParameters)
    9088          m.NewChild.ResetLocalParameters(random);
     
    9694      return base.Apply();
    9795    }
     96
     97    public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree, IRandom random, int n) {
     98      int count = 0;
     99      var g = tree.Root.Grammar;
     100      var possibleChildren = (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix()
     101                              from i in Enumerable.Range(0, parent.SubtreeCount)
     102                              from s in g.GetAllowedChildSymbols(parent.Symbol, i)
     103                              where s.Enabled
     104                              where s.InitialFrequency > 0.0
     105                              let currentChild = parent.GetSubtree(i)
     106                              where s.MinimumArity >= currentChild.SubtreeCount
     107                              where s.MaximumArity <= currentChild.SubtreeCount
     108                              where (from j in Enumerable.Range(0, currentChild.SubtreeCount)
     109                                     let childOfChild = currentChild.GetSubtree(j)
     110                                     select g.IsAllowedChildSymbol(s, childOfChild.Symbol, j)).All(p => p)
     111                              select new { parent, i, s }).ToArray();
     112      if (possibleChildren.Length < n) n = possibleChildren.Length;
     113      while (count < n) {
     114        var selected = possibleChildren[random.Next(possibleChildren.Length)];
     115        yield return new ChangeNodeTypeMove(tree, selected.parent, selected.i, selected.s.CreateTreeNode());
     116        count++;
     117      }
     118    }
    98119  }
    99120}
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ShakeMoveGenerator.cs

    r7802 r7832  
    3030
    3131namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    32   [Item("ShakeMoveGenerator", "Operator that generates moves for shaking a single symbolic expression tree node.")]
     32  [Item("ShakeExhaustiveMoveGenerator", "Operator that generates moves for shaking a single symbolic expression tree node.")]
    3333  [StorableClass]
    34   public class ShakeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, IMoveGenerator, IStochasticOperator {
     34  public class ShakeMoveGenerator : SingleSuccessorOperator, ISymbolicExpressionTreeMoveOperator, IExhaustiveMoveGenerator, IStochasticOperator {
    3535    public override bool CanChangeName {
    3636      get { return false; }
     
    3939      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    4040    }
    41     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    42       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
     41    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     42      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    4343    }
    4444    public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter {
     
    5555      : base() {
    5656      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
    57       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
     57      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
    5858      Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes."));
    5959      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
     
    6666
    6767    public override IOperation Apply() {
    68       SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
     68      var tree = SymbolicExpressionTreeParameter.ActualValue;
    6969      var moves = GenerateMoves(tree);
    7070      string moveParameterName = ChangeNodeTypeMoveParameter.ActualName;
     
    8181    }
    8282
    83     public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(SymbolicExpressionTree tree) {
    84       var g = tree.Root.Grammar;
     83    public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree) {
    8584      return (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix()
    8685              from i in Enumerable.Range(0, parent.SubtreeCount)
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Moves/ShakeMultiMoveGenerator.cs

    r7802 r7832  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    4645      set { SampleSizeParameter.Value = value; }
    4746    }
    48     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    49       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
     47    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     48      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    5049    }
    5150    public ILookupParameter<ChangeNodeTypeMove> ChangeNodeTypeMoveParameter {
     
    6463      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
    6564
    66       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
     65      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
    6766      Parameters.Add(new LookupParameter<ChangeNodeTypeMove>("ChangeNodeTypeMove", "The moves that should be generated in subscopes."));
    6867      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
     
    7574
    7675    public override IOperation Apply() {
    77       SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
    78       var moves = ChangeNodeTypeMoveGenerator.GenerateMoves(tree).ToArray();
     76      var tree = SymbolicExpressionTreeParameter.ActualValue;
     77      var random = RandomParameter.ActualValue;
     78      int n = SampleSizeParameter.ActualValue.Value;
     79      var moves = ChangeNodeTypeMultiMoveGenerator.GenerateMoves(tree, random, n);
    7980      string moveParameterName = ChangeNodeTypeMoveParameter.ActualName;
    8081      var moveScopes = new List<Scope>();
    81       var random = RandomParameter.ActualValue;
    82       int n = SampleSizeParameter.ActualValue.Value;
    8382
    84       var rand = Enumerable.Range(0, moves.Length).Select(i => random.NextDouble()).ToArray();
    85       Array.Sort(rand, moves);
    86       n = Math.Min(n, moves.Length);
    87 
    88       foreach (var m in moves.Take(n)) {
     83      foreach (var m in moves) {
    8984        m.NewChild.ShakeLocalParameters(random, 1);
    9085        var moveScope = new Scope(moveScopes.Count.ToString());
     
    9590      return base.Apply();
    9691    }
     92
     93    public static IEnumerable<ChangeNodeTypeMove> GenerateMoves(ISymbolicExpressionTree tree, IRandom random, int n) {
     94      int count = 0;
     95      var g = tree.Root.Grammar;
     96      var possibleChildren = (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix()
     97                              from i in Enumerable.Range(0, parent.SubtreeCount)
     98                              let currentChild = parent.GetSubtree(i)
     99                              where currentChild.HasLocalParameters
     100                              select new { parent, i, currentChild }).ToArray();
     101      if (possibleChildren.Length < n) n = possibleChildren.Length;
     102      while (count < n) {
     103        var selected = possibleChildren[random.Next(possibleChildren.Length)];
     104        yield return new ChangeNodeTypeMove(tree, selected.parent, selected.i, (ISymbolicExpressionTreeNode)selected.currentChild.Clone());
     105        count++;
     106      }
     107    }
    97108  }
    98109}
  • branches/GP-MoveOperators/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs

    r7795 r7832  
    5353    protected SymbolicExpressionTreeNode(bool deserializing) { }
    5454    protected SymbolicExpressionTreeNode(SymbolicExpressionTreeNode original, Cloner cloner)
    55       : base() {
     55      : base(original, cloner) {
    5656      symbol = original.symbol; // symbols are reused
    5757      length = original.length;
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r7802 r7832  
    112112  </ItemGroup>
    113113  <ItemGroup>
     114    <Compile Include="ReplaceBranchMoveEvaluator.cs" />
    114115    <Compile Include="Interfaces\ISymbolicRegressionMoveEvaluator.cs" />
    115116    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />
    116117    <Compile Include="Plugin.cs" />
     118    <Compile Include="ReplaceBranchMultiMoveGenerator.cs" />
    117119    <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" />
    118120    <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" />
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionMoveEvaluator.cs

    r7802 r7832  
    6060    }
    6161
    62     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    63       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
     62    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     63      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    6464    }
    6565    [StorableConstructor]
     
    7474      Parameters.Add(new LookupParameter<IRegressionProblemData>("ProblemData", ""));
    7575      Parameters.Add(new LookupParameter<IntRange>("FitnessCalculationPartition", ""));
    76       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", ""));
     76      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", ""));
    7777    }
    7878
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r7802 r7832  
    197197
    198198    private void InitializeOperators() {
    199       Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeMoveOperator>());
    200199      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
    201200      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r7738 r7832  
    218218
    219219    private double AggregateEstimatedValues(IEnumerable<double> estimatedValues) {
    220       return estimatedValues.DefaultIfEmpty(double.NaN).Average();
     220      // return trimean
     221      var orderdValues = estimatedValues
     222        .Where(x => !double.IsNaN(x))
     223        .DefaultIfEmpty(0.0)
     224        .OrderBy(x => x)
     225        .ToArray();
     226      return (orderdValues[(int)Math.Floor(orderdValues.Length * 0.25)] +
     227              orderdValues[(int)Math.Floor(orderdValues.Length * 0.75)]) / 2.0;
    221228    }
    222229    #endregion
Note: See TracChangeset for help on using the changeset viewer.