Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7481


Ignore:
Timestamp:
02/17/12 14:25:51 (13 years ago)
Author:
mkommend
Message:

#1682: Corrected gp-crossover code.

  • Changed ISymbolicExpressionTreeCrossover
  • Corrected SubtreeCrossover
  • Updated MultiSymbolicDataAnalysisCrossover
Location:
branches/HeuristicLab.Crossovers
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r7477 r7481  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 using HeuristicLab.PluginInfrastructure;
    3130
    3231namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    3736  /// until a valid configuration is found.
    3837  /// </summary> 
    39   [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")]
    40   [NonDiscoverableType]
     38  [Item("SubtreeSwappingCrossover", "An operator which performs subtree swapping crossover.")]
    4139  [StorableClass]
    4240  public class SubtreeCrossover : SymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator {
     
    4442    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    4543    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    46     private const string SymbolicDataAnalysisEvaluationPartitionParameterName = "EvaluationPartition";
    4744
    4845    #region Parameter Properties
     
    5552    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    5653      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    57     }
    58     public IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter {
    59       get { return (IValueLookupParameter<IntRange>)Parameters[SymbolicDataAnalysisEvaluationPartitionParameterName]; }
    6054    }
    6155    #endregion
     
    7973      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    8074      Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9)));
    81       Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
    8275    }
    8376
     
    8679    }
    8780
    88     protected override ISymbolicExpressionTree Cross(IRandom random,
     81    public override ISymbolicExpressionTree Crossover(IRandom random,
    8982      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    9083      return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,
    9184        MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    92     }
    93 
    94     public ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    95       return Cross(random, parent0, parent1);
    9685    }
    9786
  • branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs

    r7259 r7481  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Parameters;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    6665        throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators.");
    6766
    68       ISymbolicExpressionTree result = Cross(Random, Parents[0], Parents[1]);
     67      ISymbolicExpressionTree result = Crossover(Random, Parents[0], Parents[1]);
    6968
    7069      Child = result;
     
    7271    }
    7372
    74     protected abstract ISymbolicExpressionTree Cross(IRandom random,
    75       ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
     73    public abstract ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    7674  }
    7775}
  • branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCrossover.cs

    r7259 r7481  
    3030    ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter { get; }
    3131    ILookupParameter<ISymbolicExpressionTree> ChildParameter { get; }
     32    ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    3233  }
    3334}
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs

    r7476 r7481  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Collections;
     
    3534
    3635namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Crossovers {
    37   public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicDataAnalysisExpressionCrossover<T>>,
     36  [Item("MultiSymbolicDataAnalysisExpressionCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
     37  public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>,
    3838    ISymbolicDataAnalysisExpressionCrossover<T>,
    3939    ISymbolicExpressionTreeSizeConstraintOperator,
     
    9797      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
    9898
    99       var list = (from type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicDataAnalysisExpressionCrossover<T>))
    100                   where this.GetType().Assembly == type.Assembly
    101                   where !typeof(IMultiOperator<ISymbolicDataAnalysisExpressionCrossover<T>>).IsAssignableFrom(type)
    102                   select (ISymbolicDataAnalysisExpressionCrossover<T>)Activator.CreateInstance(type)).ToList();
     99      var list = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeCrossover>().ToList();
     100      var dataAnalysisCrossovers = from type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicDataAnalysisExpressionCrossover<T>))
     101                                   where this.GetType().Assembly == type.Assembly
     102                                   where !typeof(IMultiOperator<ISymbolicExpressionTreeCrossover>).IsAssignableFrom(type)
     103                                   select (ISymbolicDataAnalysisExpressionCrossover<T>)Activator.CreateInstance(type);
     104      list.AddRange(dataAnalysisCrossovers);
    103105
    104       var checkedItemList = new CheckedItemList<ISymbolicDataAnalysisExpressionCrossover<T>>();
     106      var checkedItemList = new CheckedItemList<ISymbolicExpressionTreeCrossover>();
    105107      checkedItemList.AddRange(list.OrderBy(op => op.Name));
    106108      Operators = checkedItemList.AsReadOnly();
    107       Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicDataAnalysisExpressionCrossover<T>>>(Operators.CheckedItems));
    108       Name = "MultiCrossover";
     109      Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeCrossover>>(Operators.CheckedItems));
    109110    }
    110111
     
    137138    }
    138139
    139     protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicDataAnalysisExpressionCrossover<T>>> e) {
     140    protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeCrossover>> e) {
    140141      base.Operators_ItemsReplaced(sender, e);
    141142      ParameterizeCrossovers();
    142143    }
    143144
    144     protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicDataAnalysisExpressionCrossover<T>>> e) {
     145    protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeCrossover>> e) {
    145146      base.Operators_ItemsAdded(sender, e);
    146147      ParameterizeCrossovers();
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs

    r7476 r7481  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
    2827using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    4444      return new SymbolicDataAnalysisExpressionContextAwareCrossover<T>(this, cloner);
    4545    }
    46     protected override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
     46    public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    4747      if (this.ExecutionContext == null)
    4848        throw new InvalidOperationException("ExecutionContext not set.");
     
    5252
    5353      return Cross(random, parent0, parent1, this.ExecutionContext, evaluator, problemData, rows, MaximumSymbolicExpressionTreeDepth.Value, MaximumSymbolicExpressionTreeLength.Value);
    54     }
    55 
    56     public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    57       return Cross(random, parent0, parent1);
    5854    }
    5955
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionCrossover.cs

    r7476 r7481  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Text;
     25using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Data;
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Common;
    3231using HeuristicLab.Random;
    3332
     
    150149      return rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);
    151150    }
    152 
    153     protected abstract override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    154     public abstract ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    155151  }
    156152}
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs

    r7476 r7481  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Data;
    3029using HeuristicLab.Parameters;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6464    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicDataAnalysisExpressionDepthConstrainedCrossover<T>(this, cloner); }
    6565
    66     protected override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
     66    public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    6767      return Cross(random, parent0, parent1, MaximumSymbolicExpressionTreeDepth.Value, MaximumSymbolicExpressionTreeLength.Value, DepthRange.Value);
    6868    }
    6969
    70     public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    71       return Cross(random, parent0, parent1);
    72     }
    7370
    7471    /// <summary>
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs

    r7476 r7481  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
    2827using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    4444      return new SymbolicDataAnalysisExpressionDeterministicBestCrossover<T>(this, cloner);
    4545    }
    46     protected override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
     46    public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    4747      if (this.ExecutionContext == null)
    4848        throw new InvalidOperationException("ExecutionContext not set.");
     
    5454    }
    5555
    56     public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    57       return Cross(random, parent0, parent1);
    58     }
    5956    /// <summary>
    6057    /// Takes two parent individuals P0 and P1.
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs

    r7476 r7481  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
    2827using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3838    public SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover()
    3939      : base() {
    40       Name = "ProbabilisticFunctionalCrossover";
    4140    }
    4241    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover<T>(this, cloner); }
    4342
    44     protected override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
     43    public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    4544      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    4645      List<int> rows = GenerateRowsToEvaluate().ToList();
     
    4847      return Cross(random, parent0, parent1, interpreter, problemData,
    4948                   rows, MaximumSymbolicExpressionTreeDepth.Value, MaximumSymbolicExpressionTreeLength.Value);
    50     }
    51 
    52     public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    53       return Cross(random, parent0, parent1);
    5449    }
    5550
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs

    r7476 r7481  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HeuristicLab.Common;
     25using HeuristicLab.Core;
     26using HeuristicLab.Data;
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2428using HeuristicLab.Parameters;
    2529using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Common;
    27 using HeuristicLab.Core;
    28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Data;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    5757    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicDataAnalysisExpressionSemanticSimilarityCrossover<T>(this, cloner); }
    5858
    59     protected override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
     59    public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    6060      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    6161      List<int> rows = GenerateRowsToEvaluate().ToList();
    6262      T problemData = ProblemDataParameter.ActualValue;
    6363      return Cross(random, parent0, parent1, interpreter, problemData, rows, MaximumSymbolicExpressionTreeDepth.Value, MaximumSymbolicExpressionTreeLength.Value, SemanticSimilarityRange);
    64     }
    65 
    66     public override ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    67       return Cross(random, parent0, parent1);
    6864    }
    6965
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r7477 r7481  
    175175    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs" />
    176176    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" />
    177     <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSizefairCrossover.cs" />
    178177    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" />
    179178    <Compile Include="Plugin.cs" />
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionCrossover.cs

    r7477 r7481  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Core;
     23using HeuristicLab.Data;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    25 using HeuristicLab.Parameters;
    26 using HeuristicLab.Data;
    2725
    2826namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2927  public interface ISymbolicDataAnalysisExpressionCrossover<T> : ISymbolicExpressionTreeCrossover {
    3028    IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter { get; }
    31     ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    3229  }
    3330}
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r7477 r7481  
    3232using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3333using HeuristicLab.PluginInfrastructure;
    34 using HeuristicLab.Problems.DataAnalysis.Symbolic.Crossovers;
    3534
    3635namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
Note: See TracChangeset for help on using the changeset viewer.