Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/11/12 17:17:36 (12 years ago)
Author:
ascheibe
Message:

#1886 added a comparison factor parameter to the crossover analyzer so that it can be defined what a successful crossover is

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3
Files:
2 added
7 edited

Legend:

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

    r8739 r8797  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.PermutationEncoding;
    29 using HeuristicLab.Operators;
    3029using HeuristicLab.Optimization;
    3130using HeuristicLab.Parameters;
     
    3534  [Item("CrossoverPerformanceAnalyzer", "An operator that analyzes the performance of crossovers.")]
    3635  [StorableClass]
    37   public class CrossoverPerformanceAnalyzer : SingleSuccessorOperator, IAnalyzer {
     36  public class CrossoverPerformanceAnalyzer : InitializableOperator, IAnalyzer {
    3837    private const string ResultsParameterName = "Results";
    3938    private const string GenerationsParameterName = "Generations";
     39    private const string SuccessfullCrossoversRowName = "Successfull Crossovers per Generation with CompFact ";
    4040
    4141    #region IAnalyzer Members
     
    4646
    4747    #region Parameter properties
     48    public IValueLookupParameter<BoolValue> MaximizationParameter {
     49      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     50    }
     51    public IValueParameter<ItemCollection<DoubleValue>> ComparisonFactorParameter {
     52      get { return (IValueParameter<ItemCollection<DoubleValue>>)Parameters["ComparisonFactor"]; }
     53    }
    4854    public ILookupParameter<ResultCollection> ResultsParameter {
    4955      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
     
    8591    private int cnt = 0;
    8692    [Storable]
    87     private int success = 0;
     93    private int[] success;
    8894    [Storable]
    8995    private int lastGeneration = 0;
     
    98104      : base(original, cloner) {
    99105      cnt = original.cnt;
    100       success = original.success;
     106      success = (int[])original.success.Clone();
    101107      lastGeneration = original.lastGeneration;
    102108      equalParents = original.equalParents;
     
    129135      Parameters.Add(new ValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator"));
    130136      Parameters.Add(new LookupParameter<ItemCollection<IItem>>("Operators", "The operators and items that the problem provides to the algorithms."));
     137      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));
     142
    131143
    132144      plotHelper = new ScatterPlotHelper(false, true);
     
    142154    }
    143155
    144     public override IOperation Apply() {
     156    protected override void InitializeAction() {
    145157      if (SimilarityCalculatorParameter.Value == null) {
    146158        SimilarityCalculatorParameter.Value = OperatorsParameter.ActualValue.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
     159      }
     160
     161      if (success == null) {
     162        success = new int[ComparisonFactorParameter.Value.Count];
    147163      }
    148164
     
    150166      childDiversityHelper.InitializePlot(Results, "Child Diversity", "Solution Index", "Diversity");
    151167      parentDiversityHelper.InitializePlot(Results, "Parent Diversity", "Solution Index", "Diversity");
    152 
    153       performanceHelper.InitializeChart(Results, "Average Crossover Performance", "Average Crossover Performance per Generation");
    154       successHelper.InitializeChart(Results, "Successfull Crossovers", "Successfull Crossovers per Generation");
    155       equalParentsHelper.InitializeChart(Results, "Number of equal parents", "Absolut number of equal parents");
     168      performanceHelper.InitializeChart(Results, "Average Crossover Performance", new string[] { "Average Crossover Performance per Generation" });
     169      equalParentsHelper.InitializeChart(Results, "Number of equal parents", new string[] { "Absolut number of equal parents" });
     170
     171      List<string> successfullCXRowNames = new List<string>();
     172      foreach (var value in ComparisonFactorParameter.Value) {
     173        successfullCXRowNames.Add(SuccessfullCrossoversRowName + value.Value.ToString());
     174      }
     175      successHelper.InitializeChart(Results, "Successfull Crossovers", successfullCXRowNames.ToArray());
     176    }
     177
     178    public override IOperation Apply() {
     179      Initialize();
    156180
    157181      Point2D<double> qualityPoint, diversityPointChild, diversityPointParent;
    158182      var qualityParent1 = ParentsQualityParameter.ActualValue.First().Value;
    159183      var qualityParent2 = ParentsQualityParameter.ActualValue.Last().Value;
     184      var qualityChild = QualityParameter.ActualValue.Value;
    160185      var child = ChildParameter.ActualValue;
    161186      var parent1 = ParentsParameter.ActualValue.First();
     
    163188      var parentDiversity = SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope.SubScopes.First(), ExecutionContext.Scope.SubScopes.Last());
    164189      string curGenStr = GenerationsParameter.ActualValue.Value.ToString();
    165 
    166190
    167191      diversityPointParent = new Point2D<double>(cnt, parentDiversity);
     
    173197      }
    174198
    175       qualityPoint = new Point2D<double>(cnt++, worseQuality - QualityParameter.ActualValue.Value);
    176       if ((worseQuality - QualityParameter.ActualValue.Value) > 0) {
    177         success++;
    178       }
     199      qualityPoint = new Point2D<double>(cnt++, worseQuality - qualityChild);
    179200      qualityPoints.Add(qualityPoint.Y);
     201
     202      //track successfull cx
     203      var compFactsArray = ComparisonFactorParameter.Value.ToArray();
     204      for (int i = 0; i < compFactsArray.Length; i++) {
     205        if (WeightedParentsQualityComparer.Compare(qualityChild, qualityParent1, qualityParent2, compFactsArray[i].Value, MaximizationParameter.ActualValue.Value)) {
     206          success[i]++;
     207        }
     208      }
    180209
    181210      if (parentDiversity == 1.0) {
     
    188217
    189218          performanceHelper.AddPoint(avg);
    190           successHelper.AddPoint(success);
    191219          equalParentsHelper.AddPoint(equalParents);
     220
     221          for (int i = 0; i < compFactsArray.Length; i++) {
     222            successHelper.AddPoint(SuccessfullCrossoversRowName + compFactsArray[i].Value.ToString(), success[i]);
     223          }
    192224
    193225          Reset();
     
    206238    private void Reset() {
    207239      cnt = 0;
    208       success = 0;
     240      success = new int[ComparisonFactorParameter.Value.Count];
    209241      lastGeneration = GenerationsParameter.ActualValue.Value;
    210242      qualityPoints.Clear();
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DataTableHelper.cs

    r8515 r8797  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3536    private string chartName;
    3637    [Storable]
    37     private string dataRowName;
     38    private string[] dataRowNames;
    3839    [Storable]
    39     private DataRow dtRow;
     40    DataTable dt;
    4041
    4142    [StorableConstructor]
     
    4950    }
    5051
    51     public void InitializeChart(ResultCollection results, string chartName, string dataRowName) {
     52    public void InitializeChart(ResultCollection results, string chartName, string[] dataRowNames) {
    5253      if (!results.ContainsKey(chartName)) {
    5354        this.resultsCol = results;
    5455        this.chartName = chartName;
    55         this.dataRowName = dataRowName;
     56        this.dataRowNames = dataRowNames;
    5657
    57         DataTable dt = new DataTable(chartName);
    58         dtRow = new DataRow(dataRowName);
    59         dt.Rows.Add(dtRow);
     58        dt = new DataTable(chartName);
     59
     60        foreach (string dataRowName in dataRowNames) {
     61          DataRow dtRow = new DataRow(dataRowName);
     62          dt.Rows.Add(dtRow);
     63        }
     64
    6065        results.Add(new Result(chartName, dt));
    6166      }
    6267    }
    6368
     69    public void AddPoint(string dataRow, double point) {
     70      dt.Rows[dataRow].Values.Add(point);
     71    }
     72
    6473    public void AddPoint(double point) {
    65       dtRow.Values.Add(point);
     74      // assume that there is only 1 row and therefore the name doesn't have to be provided
     75      dt.Rows[dataRowNames[0]].Values.Add(point);
    6676    }
    6777  }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DuplicateSolutionsAnalyzer.cs

    r8722 r8797  
    8787        SimilarityCalculatorParameter.Value = OperatorsParameter.ActualValue.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
    8888      }
    89       chartingHelper.InitializeChart(Results, "Duplicate Solutions", "Duplicate Solutions per Generation");
     89      chartingHelper.InitializeChart(Results, "Duplicate Solutions", new string[] { "Duplicate Solutions per Generation" });
    9090
    9191      var similarities = SimilarityCalculatorParameter.Value.CalculateSolutionCrowdSimilarity(ExecutionContext.Scope);
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj

    r8711 r8797  
    120120    <Compile Include="AfterCrossoverCombinedOperator.cs" />
    121121    <Compile Include="AfterMutationCombinedOperator.cs" />
     122    <Compile Include="InitializableOperator.cs" />
    122123    <Compile Include="PathRelinkerPerformanceAnalyzer.cs" />
    123124    <Compile Include="VariableRemover.cs" />
     
    137138    <Compile Include="Properties\AssemblyInfo.cs" />
    138139    <Compile Include="VariableDuplicator.cs" />
     140    <Compile Include="WeightedParentsQualityComparer.cs" />
    139141  </ItemGroup>
    140142  <ItemGroup>
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/MutationPerformanceAnalyzer.cs

    r8739 r8797  
    3131using HeuristicLab.Parameters;
    3232using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    33 using HeuristicLab.Problems.TravelingSalesman;
    3433
    3534namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
     
    145144        qualityPlotHelper.InitializePlot(Results, "Mutation Quality", "Solution Index", "Absolut Quality Difference");
    146145        diversityPlotHelper.InitializePlot(Results, "Mutation Diversity", "Solution Index", "Diversity");
    147         avgDataTableHelper.InitializeChart(Results, "Average Mutation Performance", "Average Mutation Performance per Generation");
     146        avgDataTableHelper.InitializeChart(Results, "Average Mutation Performance", new string[] { "Average Mutation Performance per Generation" });
    148147
    149148        Scope permutationBeforeScope = new Scope();
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/PathRelinkerPerformanceAnalyzer.cs

    r8663 r8797  
    164164      parentDiversityHelper.InitializePlot(Results, "Parent Diversity", "Solution Index", "Diversity");
    165165
    166       performanceHelper.InitializeChart(Results, "Average Crossover Performance", "Average Crossover Performance per Generation");
    167       successHelper.InitializeChart(Results, "Successfull Crossovers", "Successfull Crossovers per Generation");
    168       equalParentsHelper.InitializeChart(Results, "Number of equal parents", "Absolut number of equal parents");
     166      performanceHelper.InitializeChart(Results, "Average Crossover Performance", new string[] { "Average Crossover Performance per Generation" });
     167      successHelper.InitializeChart(Results, "Successfull Crossovers", new string[] { "Successfull Crossovers per Generation" });
     168      equalParentsHelper.InitializeChart(Results, "Number of equal parents", new string[] { "Absolut number of equal parents" });
    169169
    170170      Point2D<double> qualityPoint, diversityPointChild, diversityPointParent;
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/ScatterPlotHelper.cs

    r8515 r8797  
    8585          dataTableHelper = new DataTableHelper();
    8686        }
    87         dataTableHelper.InitializeChart(results, chartName + " Chart", yAxisTitle);
     87        dataTableHelper.InitializeChart(results, chartName + " Chart", new string[] { yAxisTitle });
    8888      }
    8989
Note: See TracChangeset for help on using the changeset viewer.