Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11227


Ignore:
Timestamp:
07/29/14 02:17:14 (10 years ago)
Author:
bburlacu
Message:

#1772: Added storable attributes to all the tracking operators. Added an additional method in the genealogy analyzer which computes the relative reproductive success for each individual in the population as the ratio of its offspring which make it into the next generation.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/HeuristicLab.EvolutionTracking.Views-3.4.csproj

    r11197 r11227  
    105105    <Compile Include="Plugin.cs" />
    106106    <Compile Include="Properties\AssemblyInfo.cs" />
    107     <Compile Include="GenealogyGraphView.cs" />
     107    <Compile Include="GenealogyGraphView.cs">
     108      <SubType>UserControl</SubType>
     109    </Compile>
    108110    <Compile Include="GenealogyGraphView.Designer.cs">
    109111      <DependentUpon>GenealogyGraphView.cs</DependentUpon>
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs

    r11032 r11227  
    2121
    2222using System.Linq;
     23using HeuristicLab.Analysis;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3435  public class GenealogyAnalyzer<T> : SingleSuccessorOperator, IAnalyzer
    3536  where T : class,IItem {
     37    #region parameter names
    3638    private const string GenerationsParameterName = "Generations";
    3739    private const string ResultsParameterName = "Results";
     
    5355    private const string EnableManipulatorTrackingParameterName = "EnableManipulatorTracking";
    5456    private const string EnableSolutionCreatorTrackingParameterName = "EnableSolutionCreatorTracking"; // should always be enabled. maybe superfluous
     57    #endregion
    5558
    5659    #region parameter properties
     
    140143
    141144    public GenealogyAnalyzer() {
     145      #region add parameters
    142146      // the instrumented operators
    143147      Parameters.Add(new LookupParameter<ICrossover>(CrossoverParameterName, "The crossover operator."));
     
    157161      Parameters.Add(new ValueParameter<IManipulatorOperator<T>>(BeforeManipulatorOperatorParameterName));
    158162      Parameters.Add(new ValueParameter<IManipulatorOperator<T>>(AfterManipulatorOperatorParameterName));
     163      #endregion
    159164    }
    160165    public override IDeepCloneable Clone(Cloner cloner) {
     
    164169      : base(original, cloner) {
    165170    }
     171
     172    [StorableConstructor]
     173    protected GenealogyAnalyzer(bool deserializing) : base(deserializing) { }
     174
    166175    [StorableHook(HookType.AfterDeserialization)]
    167176    private void AfterDeserialization() {
     
    232241
    233242    public override IOperation Apply() {
    234       var population = PopulationParameter.ActualValue.ToList();
     243      var population = PopulationParameter.ActualValue;
    235244      var qualities = QualityParameter.ActualValue.ToList();
    236245
    237       int currentGeneration = GenerationsParameter.ActualValue.Value;
    238       if (currentGeneration == 0) {
     246      int generation = GenerationsParameter.ActualValue.Value;
     247      if (generation == 0) {
    239248        ConfigureTrackingOperators();
    240249
    241         for (int i = 0; i < population.Count; ++i) {
     250        for (int i = 0; i < population.Length; ++i) {
    242251          var individual = population[i];
    243           var vertex = new GenealogyGraphNode<T>(individual) { Rank = currentGeneration };
     252          var vertex = new GenealogyGraphNode<T>(individual) { Rank = generation };
    244253          GenealogyGraph.AddVertex(vertex);
    245254          // save the vertex id in the individual scope (so that we can identify graph indices)
     
    249258        int index = 0;
    250259        T elite = null;
    251         for (int i = 0; i < population.Count; ++i) {
     260        for (int i = 0; i < population.Length; ++i) {
    252261          if (GenealogyGraph.Contains(population[i])) {
    253262            elite = population[i];
    254263            index = i;
    255           }
    256           break;
    257         }
    258 
     264            break;
     265          }
     266        }
     267
     268        #region add elite in the graph and connect it with the previous elite
    259269        if (elite != null) {
    260270          var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetVertex(elite);
     
    264274
    265275          var vertex = new GenealogyGraphNode<T>(prevVertex.Content) {
    266             Rank = currentGeneration,
     276            Rank = generation,
    267277            Quality = prevVertex.Quality,
    268278            IsElite = false
     
    272282          // inject the graph node unique id to the scope
    273283          ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(vertex.Id);
    274 
    275284          GenealogyGraph.AddVertex(vertex);
    276 
    277285          GenealogyGraph.AddArc(prevVertex, vertex); // connect current elite with previous elite
    278286
     
    281289          }
    282290        }
     291        #endregion
     292
     293        ComputeSuccessRatios();
    283294      }
    284295      // update qualities
    285       for (int i = 0; i < population.Count; ++i) {
     296      for (int i = 0; i < population.Length; ++i) {
    286297        var vertex = (IGenealogyGraphNode)GenealogyGraph.GetVertex(population[i]);
    287298        vertex.Quality = qualities[i].Value;
     
    289300
    290301      // remove extra graph nodes (added by the instrumented operators in the case of offspring selection)
    291       var discardedOffspring = GenealogyGraph.Ranks[currentGeneration].Select(x => (T)x.Content).Except(population).ToList();
    292       foreach (var individual in discardedOffspring) {
    293         var vertex = GenealogyGraph.GetVertex(individual);
     302      var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Content).Except(population).ToList();
     303      foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetVertex(individual))) {
    294304        GenealogyGraph.RemoveVertex(vertex);
    295305      }
    296306
    297307      return base.Apply();
     308    }
     309
     310    private void ComputeSuccessRatios() {
     311      var population = PopulationParameter.ActualValue;
     312      var generation = GenerationsParameter.ActualValue.Value;
     313      // compute the weight of each genealogy graph node as the ratio (produced offspring) / (surviving offspring)
     314      foreach (var ind in population) {
     315        var v = (IGenealogyGraphNode)GenealogyGraph.GetVertex(ind);
     316        foreach (var p in v.Parents)
     317          p.Weight++;
     318      }
     319      foreach (var v in GenealogyGraph.Ranks[generation - 1]) {
     320        if (v.OutDegree > 0)
     321          v.Weight /= v.OutDegree;
     322      }
     323
     324      var results = ResultsParameter.ActualValue;
     325      DataTable table;
     326      if (!results.ContainsKey("Successful offspring ratio")) {
     327        table = new DataTable("Successful offspring ratio");
     328        results.Add(new Result("Successful offspring ratio", table));
     329        table.Rows.Add(new DataRow("Successful offspring ratio") { VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Columns, StartIndexZero = true } });
     330      } else {
     331        table = (DataTable)results["Successful offspring ratio"].Value;
     332      }
     333      var row = table.Rows["Successful offspring ratio"];
     334      row.Values.Replace(GenealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.Weight));
    298335    }
    299336  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/HeuristicLab.EvolutionTracking-3.4.csproj

    r10458 r11227  
    5656  </PropertyGroup>
    5757  <ItemGroup>
     58    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     59      <SpecificVersion>False</SpecificVersion>
     60      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
     61      <Private>False</Private>
     62    </Reference>
    5863    <Reference Include="HeuristicLab.Collections-3.3">
    5964      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/AfterCrossoverOperator.cs

    r10830 r11227  
    4545      return new AfterCrossoverOperator<T>(this, cloner);
    4646    }
     47    [StorableConstructor]
     48    protected AfterCrossoverOperator(bool deserializing) : base(deserializing) { }
    4749
    4850    public AfterCrossoverOperator() {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/AfterManipulatorOperator.cs

    r10830 r11227  
    4141      return new AfterManipulatorOperator<T>(this, cloner);
    4242    }
     43    [StorableConstructor]
     44    protected AfterManipulatorOperator(bool deserializing) : base(deserializing) { }
    4345
    4446    public AfterManipulatorOperator() {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs

    r10897 r11227  
    5454    }
    5555
     56    [StorableConstructor]
     57    protected BeforeCrossoverOperator(bool deserializing) : base(deserializing) { }
     58
    5659    public BeforeCrossoverOperator() {
    5760      Parameters.Add(new ScopeTreeLookupParameter<T>(ParentsParameterName));
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r11032 r11227  
    3030  [Item("AfterCrossoverOperator", "Performs an action after the crossover operator is applied.")]
    3131  public class BeforeManipulatorOperator<T> : EvolutionTrackingOperator<T>, IManipulatorOperator<T> where T : class,IItem {
    32 
    3332    private const string ChildParameterName = "Child";
    3433
     
    4342      return new BeforeManipulatorOperator<T>(this, cloner);
    4443    }
     44    [StorableConstructor]
     45    protected BeforeManipulatorOperator(bool deserializing) : base(deserializing) { }
    4546
    4647    public BeforeManipulatorOperator() {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/EvolutionTrackingOperator.cs

    r10650 r11227  
    2626using HeuristicLab.Optimization;
    2727using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
    2930namespace HeuristicLab.EvolutionTracking {
     31  [Item("EvolutionTrackingOperator", "A base operator which facilitates access to the genealogy graph.")]
     32  [StorableClass]
    3033  public class EvolutionTrackingOperator<T> : SingleSuccessorOperator where T : class,IItem {
    3134    // evolution tracking-related parameters
     
    6972      return new EvolutionTrackingOperator<T>(this, cloner);
    7073    }
     74    [StorableConstructor]
     75    protected EvolutionTrackingOperator(bool deserializing) : base(deserializing) { }
    7176  }
    7277}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisGenealogyAnalyzer.cs

    r10300 r11227  
    44using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    55
    6 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers {
     6namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     7  [Item("SymbolicDataAnalysisGenealogyAnalyzer", "")]
    78  [StorableClass]
    8   [Item("SymbolicDataAnalysisGenealogyAnalyzer", "")]
    99  public class SymbolicDataAnalysisGenealogyAnalyzer : GenealogyAnalyzer<ISymbolicExpressionTree> {
     10    public SymbolicDataAnalysisGenealogyAnalyzer() { }
     11
     12    [StorableConstructor]
     13    protected SymbolicDataAnalysisGenealogyAnalyzer(bool deserializing) : base(deserializing) { }
    1014  }
    1115}
Note: See TracChangeset for help on using the changeset viewer.