Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/16/16 15:39:03 (9 years ago)
Author:
bburlacu
Message:

#1772: Fixed the way operator improvement is calculated so it also works when a diversification strategy is applied (introducing multiple intermediate vertices between parent and child). Minor code refactoring in the diversification operators. Fixed very small typo in the BeforeManipulatorOperator.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisGeneticOperatorImprovementAnalyzer.cs

    r13495 r13527  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Analysis;
     
    103104      var populationSize = population.Length;
    104105
    105       var vertices = population.Select(graph.GetByContent).ToList();
     106      //      var vertices = population.Select(graph.GetByContent).ToList();
     107      var crossoverChildren = new List<IGenealogyGraphNode<ISymbolicExpressionTree>>();
     108      var mutationChildren = new List<IGenealogyGraphNode<ISymbolicExpressionTree>>();
     109      var vertices = graph.Vertices.Where(x => x.Rank > generation - 1);
     110      foreach (var v in vertices) {
     111        if (v.InDegree == 2) {
     112          crossoverChildren.Add(v);
     113        } else {
     114          var parent = v.Parents.First();
     115          // mutation is always preceded by mutation
     116          // so the parent vertex should have an intermediate rank
     117          // otherwise, it is the previos generation elite
     118          if (parent.Rank.IsAlmost(generation - 1) && parent.IsElite)
     119            continue;
     120          mutationChildren.Add(v);
     121        }
     122      }
    106123      DataTable table;
    107124      #region crossover improvement
     
    118135        table = (DataTable)Results["Crossover improvement"].Value;
    119136      }
    120       var crossoverChildren = vertices.Where(x => x.InDegree == 2).ToList();
    121       if (CountIntermediateChildren)
    122         crossoverChildren.AddRange(vertices.Where(x => x.InDegree == 1).Select(v => v.Parents.First()).Where(p => p.Rank.IsAlmost(generation - 0.5))); // add intermediate children
    123137
    124138      var avgCrossoverParentQuality = crossoverChildren.SelectMany(x => x.Parents).Average(x => x.Quality);
     
    148162      }
    149163
    150       var mutationChildren = vertices.Where(x => x.InDegree == 1).ToList();
    151 
    152164      var avgMutationParentQuality = mutationChildren.SelectMany(x => x.Parents).Average(x => x.Quality);
    153165      var avgMutationChildQuality = mutationChildren.Average(x => x.Quality);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r13482 r13527  
    322322    <Compile Include="Tracking\SchemaDiversification\SchemaEvaluator.cs" />
    323323    <Compile Include="Tracking\SchemaDiversification\SchemaCreator.cs" />
    324     <Compile Include="Tracking\SchemaDiversification\UpdateEstimatedValuesOperator.cs" />
     324    <Compile Include="Tracking\SchemaDiversification\UpdateQualityOperator.cs" />
    325325    <Compile Include="Tracking\SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs" />
    326326    <Compile Include="Tracking\SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/DiversificationStatisticsOperator.cs

    r13496 r13527  
    6767    }
    6868
     69    public override void InitializeState() {
     70      base.InitializeState();
     71      evaluatedSolutionsTracker = 0;
     72    }
     73
    6974    public override void ClearState() {
     75      base.ClearState();
    7076      evaluatedSolutionsTracker = 0;
    71       base.ClearState();
    7277    }
    7378
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs

    r13496 r13527  
    111111    #endregion
    112112
    113     private UpdateEstimatedValuesOperator updateEstimatedValuesOperator;
     113    private UpdateQualityOperator updateQualityOperator;
    114114    private DiversificationStatisticsOperator diversificationStatisticsOperator;
    115115
     
    182182
    183183      var updateEstimatedValues = new OperationCollection { Parallel = true };
    184       if (updateEstimatedValuesOperator == null)
    185         updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator();
     184      if (updateQualityOperator == null)
     185        updateQualityOperator = new UpdateQualityOperator();
    186186
    187187      foreach (var s in ExecutionContext.Scope.SubScopes.Where(s => !s.Variables.ContainsKey("EstimatedValues"))) {
    188         updateEstimatedValues.Add(ExecutionContext.CreateChildOperation(updateEstimatedValuesOperator, s));
     188        updateEstimatedValues.Add(ExecutionContext.CreateChildOperation(updateQualityOperator, s));
    189189      }
    190190
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs

    r13496 r13527  
    143143    };
    144144
     145    [Storable]
    145146    public ISymbolicExpressionTree Schema { get; set; }
    146147
    147148    [Storable]
    148     private readonly UpdateEstimatedValuesOperator updateEstimatedValuesOperator;
     149    private readonly UpdateQualityOperator updateQualityOperator;
    149150
    150151    [StorableHook(HookType.AfterDeserialization)]
     
    156157    public SchemaEvaluator() {
    157158      qm = new QueryMatch(comp) { MatchParents = true };
    158       this.updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator();
     159      this.updateQualityOperator = new UpdateQualityOperator();
    159160      #region add parameters
    160161      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SchemaParameterName, "The current schema to be evaluated"));
     
    185186
    186187    protected SchemaEvaluator(SchemaEvaluator original, Cloner cloner) : base(original, cloner) {
    187       this.comp = original.comp == null ? new SymbolicExpressionTreeNodeEqualityComparer {
    188         MatchConstantValues = false,
    189         MatchVariableWeights = false,
    190         MatchVariableNames = true
    191       } : (ISymbolicExpressionTreeNodeEqualityComparer)original.comp.Clone();
     188      this.comp = new SymbolicExpressionTreeNodeEqualityComparer();
    192189      this.qm = new QueryMatch(comp) { MatchParents = original.qm?.MatchParents ?? true };
    193       this.updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator();
     190      this.updateQualityOperator = new UpdateQualityOperator();
     191      Schema = original.Schema;
    194192    }
    195193
     
    295293      foreach (var ind in individualsToReplace) {
    296294        var mutatorOp = ExecutionContext.CreateChildOperation(mutator, ind);
    297         var updateOp = ExecutionContext.CreateChildOperation(updateEstimatedValuesOperator, ind);
     295        var updateOp = ExecutionContext.CreateChildOperation(updateQualityOperator, ind);
    298296        mutationOc.Add(mutatorOp);
    299297        updateEstimatedValues.Add(updateOp);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateQualityOperator.cs

    r13526 r13527  
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    33   [Item("UpdateEstimatedValuesOperator", "Put the estimated values of the tree in the scope to be used by the phenotypic similarity calculator")]
     33  [Item("UpdateQualityOperator", "Put the estimated values of the tree in the scope to be used by the phenotypic similarity calculator")]
    3434  [StorableClass]
    35   public class UpdateEstimatedValuesOperator : EvolutionTrackingOperator<ISymbolicExpressionTree> {
     35  public class UpdateQualityOperator : EvolutionTrackingOperator<ISymbolicExpressionTree> {
    3636    private const string ProblemDataParameterName = "ProblemData";
    3737    private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter";
     
    5656    }
    5757
    58     public UpdateEstimatedValuesOperator() {
     58    public UpdateQualityOperator() {
    5959      Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName));
    6060      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName));
     
    6565
    6666    [StorableConstructor]
    67     protected UpdateEstimatedValuesOperator(bool deserializing) : base(deserializing) { }
     67    protected UpdateQualityOperator(bool deserializing) : base(deserializing) { }
    6868
    69     protected UpdateEstimatedValuesOperator(UpdateEstimatedValuesOperator original, Cloner cloner) : base(original, cloner) {
     69    protected UpdateQualityOperator(UpdateQualityOperator original, Cloner cloner) : base(original, cloner) {
    7070    }
    7171
    7272    public override IDeepCloneable Clone(Cloner cloner) {
    73       return new UpdateEstimatedValuesOperator(this, cloner);
     73      return new UpdateQualityOperator(this, cloner);
    7474    }
    7575
     
    110110
    111111      ((DoubleValue)variables["Quality"].Value).Value = r2;
     112      GenealogyGraph.GetByContent(tree).Quality = r2;
    112113
    113114      var scaleEstimatedValues = ScaleEstimatedValuesParameter.ActualValue;
Note: See TracChangeset for help on using the changeset viewer.