Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8864


Ignore:
Timestamp:
10/30/12 20:47:07 (12 years ago)
Author:
ascheibe
Message:

#1886 added more analyzers for crossover performance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/CrossoverPerformanceAnalyzer.cs

    r8797 r8864  
    2121
    2222
     23using System;
    2324using System.Collections.Generic;
    2425using System.Linq;
     
    3435  [Item("CrossoverPerformanceAnalyzer", "An operator that analyzes the performance of crossovers.")]
    3536  [StorableClass]
    36   public class CrossoverPerformanceAnalyzer : InitializableOperator, IAnalyzer {
     37  public class CrossoverPerformanceAnalyzer : InitializableOperator {
    3738    private const string ResultsParameterName = "Results";
    3839    private const string GenerationsParameterName = "Generations";
    3940    private const string SuccessfullCrossoversRowName = "Successfull Crossovers per Generation with CompFact ";
    4041
    41     #region IAnalyzer Members
    42     public bool EnabledByDefault {
    43       get { return true; }
    44     }
    45     #endregion
    46 
    4742    #region Parameter properties
    4843    public IValueLookupParameter<BoolValue> MaximizationParameter {
    4944      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    5045    }
    51     public IValueParameter<ItemCollection<DoubleValue>> ComparisonFactorParameter {
    52       get { return (IValueParameter<ItemCollection<DoubleValue>>)Parameters["ComparisonFactor"]; }
     46    public IValueLookupParameter<ItemCollection<DoubleValue>> ComparisonFactorParameter {
     47      get { return (IValueLookupParameter<ItemCollection<DoubleValue>>)Parameters["ComparisonFactor"]; }
    5348    }
    5449    public ILookupParameter<ResultCollection> ResultsParameter {
     
    8580
    8681    [Storable]
    87     private ScatterPlotHelper plotHelper, childDiversityHelper, parentDiversityHelper;
     82    private ScatterPlotHelper plotHelper, childDiversityToWorseParentHelper, childDiversityToBetterParentHelper, parentDiversityHelper, parentQualityHelper;
    8883    [Storable]
    8984    private DataTableHelper performanceHelper, successHelper, equalParentsHelper;
     
    109104      qualityPoints = new List<double>(original.qualityPoints);
    110105      plotHelper = (ScatterPlotHelper)original.plotHelper.Clone(cloner);
    111       childDiversityHelper = (ScatterPlotHelper)original.childDiversityHelper.Clone(cloner);
     106      childDiversityToWorseParentHelper = (ScatterPlotHelper)original.childDiversityToWorseParentHelper.Clone(cloner);
     107      childDiversityToBetterParentHelper = (ScatterPlotHelper)original.childDiversityToBetterParentHelper.Clone(cloner);
    112108      parentDiversityHelper = (ScatterPlotHelper)original.parentDiversityHelper.Clone(cloner);
     109      parentQualityHelper = (ScatterPlotHelper)original.parentQualityHelper.Clone(cloner);
    113110      performanceHelper = (DataTableHelper)original.performanceHelper.Clone(cloner);
    114111      successHelper = (DataTableHelper)original.successHelper.Clone(cloner);
     
    136133      Parameters.Add(new LookupParameter<ItemCollection<IItem>>("Operators", "The operators and items that the problem provides to the algorithms."));
    137134      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, false otherwise"));
    138       Parameters.Add(new ValueParameter<ItemCollection<DoubleValue>>("ComparisonFactor", "Determines if the quality should be compared to the better parent (1.0), to the worse (0.0) or to any linearly interpolated value between them."));
    139       ComparisonFactorParameter.Value.Add(new DoubleValue(0));
    140       ComparisonFactorParameter.Value.Add(new DoubleValue(0.5));
    141       ComparisonFactorParameter.Value.Add(new DoubleValue(1));
     135      Parameters.Add(new ValueLookupParameter<ItemCollection<DoubleValue>>("ComparisonFactor", "Determines if the quality should be compared to the better parent (1.0), to the worse (0.0) or to any linearly interpolated value between them."));
    142136
    143137
    144138      plotHelper = new ScatterPlotHelper(false, true);
    145       childDiversityHelper = new ScatterPlotHelper(false, true);
     139      childDiversityToWorseParentHelper = new ScatterPlotHelper(false, true);
     140      childDiversityToBetterParentHelper = new ScatterPlotHelper(false, true);
    146141      parentDiversityHelper = new ScatterPlotHelper(false, true);
     142      parentQualityHelper = new ScatterPlotHelper(false, true);
    147143      performanceHelper = new DataTableHelper();
    148144      successHelper = new DataTableHelper();
     
    159155      }
    160156
     157      if (ComparisonFactorParameter.ActualValue == null) {
     158        ComparisonFactorParameter.Value = new ItemCollection<DoubleValue>();
     159        ComparisonFactorParameter.Value.Add(new DoubleValue(0));
     160        ComparisonFactorParameter.Value.Add(new DoubleValue(0.5));
     161        ComparisonFactorParameter.Value.Add(new DoubleValue(1));
     162        ComparisonFactorParameter.Value.Add(new DoubleValue(1.5));
     163      }
     164
    161165      if (success == null) {
    162166        success = new int[ComparisonFactorParameter.Value.Count];
     
    164168
    165169      plotHelper.InitializePlot(Results, "Crossover Performance", "Solution Index", "Absolut Quality Difference");
    166       childDiversityHelper.InitializePlot(Results, "Child Diversity", "Solution Index", "Diversity");
     170      childDiversityToWorseParentHelper.InitializePlot(Results, "Child Diversity to Worse Parent", "Solution Index", "Diversity");
     171      childDiversityToBetterParentHelper.InitializePlot(Results, "Child Diversity to Better Parent", "Solution Index", "Diversity");
    167172      parentDiversityHelper.InitializePlot(Results, "Parent Diversity", "Solution Index", "Diversity");
     173      parentQualityHelper.InitializePlot(Results, "Parent Quality Difference", "Solution Index", "Absolut Quality Difference");
    168174      performanceHelper.InitializeChart(Results, "Average Crossover Performance", new string[] { "Average Crossover Performance per Generation" });
    169175      equalParentsHelper.InitializeChart(Results, "Number of equal parents", new string[] { "Absolut number of equal parents" });
     
    179185      Initialize();
    180186
    181       Point2D<double> qualityPoint, diversityPointChild, diversityPointParent;
     187      Point2D<double> qualityPoint, childDiversityToWorseParent, childDiversityToBetterParent, diversityPointParent, qualityPointParent;
     188      var parent1 = ParentsParameter.ActualValue.First();
     189      var parent2 = ParentsParameter.ActualValue.Last();
    182190      var qualityParent1 = ParentsQualityParameter.ActualValue.First().Value;
    183191      var qualityParent2 = ParentsQualityParameter.ActualValue.Last().Value;
     192      var child = ChildParameter.ActualValue;
    184193      var qualityChild = QualityParameter.ActualValue.Value;
    185       var child = ChildParameter.ActualValue;
    186       var parent1 = ParentsParameter.ActualValue.First();
    187       var parent2 = ParentsParameter.ActualValue.Last();
     194
    188195      var parentDiversity = SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope.SubScopes.First(), ExecutionContext.Scope.SubScopes.Last());
    189196      string curGenStr = GenerationsParameter.ActualValue.Value.ToString();
    190197
    191198      diversityPointParent = new Point2D<double>(cnt, parentDiversity);
     199      qualityPointParent = new Point2D<double>(cnt, Math.Abs(qualityParent1 - qualityParent2));
     200
     201      if (qualityParent1 > qualityParent2) {
     202        if (MaximizationParameter.ActualValue.Value) {
     203          childDiversityToWorseParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.Last()));
     204          childDiversityToBetterParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.First()));
     205        } else {
     206          childDiversityToWorseParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.First()));
     207          childDiversityToBetterParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.Last()));
     208        }
     209      } else {
     210        if (MaximizationParameter.ActualValue.Value) {
     211          childDiversityToWorseParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.First()));
     212          childDiversityToBetterParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.Last()));
     213        } else {
     214          childDiversityToWorseParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.Last()));
     215          childDiversityToBetterParent = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.First()));
     216        }
     217      }
     218
    192219      double worseQuality = qualityParent1 > qualityParent2 ? qualityParent1 : qualityParent2;
    193       if (qualityParent1 > qualityParent2) {
    194         diversityPointChild = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.First()));
    195       } else {
    196         diversityPointChild = new Point2D<double>(cnt, SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope, ExecutionContext.Scope.SubScopes.Last()));
    197       }
    198 
    199220      qualityPoint = new Point2D<double>(cnt++, worseQuality - qualityChild);
    200221      qualityPoints.Add(qualityPoint.Y);
     
    227248
    228249        plotHelper.AddPoint(curGenStr, qualityPoint);
    229         childDiversityHelper.AddPoint(curGenStr, diversityPointChild);
     250        childDiversityToWorseParentHelper.AddPoint(curGenStr, childDiversityToWorseParent);
     251        childDiversityToBetterParentHelper.AddPoint(curGenStr, childDiversityToBetterParent);
    230252        parentDiversityHelper.AddPoint(curGenStr, diversityPointParent);
     253        parentQualityHelper.AddPoint(curGenStr, qualityPointParent);
    231254      } else {
    232255        Reset();
Note: See TracChangeset for help on using the changeset viewer.