Changeset 8864 for branches/HeuristicLab.Analysis.AlgorithmBehavior
- Timestamp:
- 10/30/12 20:47:07 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/CrossoverPerformanceAnalyzer.cs
r8797 r8864 21 21 22 22 23 using System; 23 24 using System.Collections.Generic; 24 25 using System.Linq; … … 34 35 [Item("CrossoverPerformanceAnalyzer", "An operator that analyzes the performance of crossovers.")] 35 36 [StorableClass] 36 public class CrossoverPerformanceAnalyzer : InitializableOperator , IAnalyzer{37 public class CrossoverPerformanceAnalyzer : InitializableOperator { 37 38 private const string ResultsParameterName = "Results"; 38 39 private const string GenerationsParameterName = "Generations"; 39 40 private const string SuccessfullCrossoversRowName = "Successfull Crossovers per Generation with CompFact "; 40 41 41 #region IAnalyzer Members42 public bool EnabledByDefault {43 get { return true; }44 }45 #endregion46 47 42 #region Parameter properties 48 43 public IValueLookupParameter<BoolValue> MaximizationParameter { 49 44 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 50 45 } 51 public IValue Parameter<ItemCollection<DoubleValue>> ComparisonFactorParameter {52 get { return (IValue Parameter<ItemCollection<DoubleValue>>)Parameters["ComparisonFactor"]; }46 public IValueLookupParameter<ItemCollection<DoubleValue>> ComparisonFactorParameter { 47 get { return (IValueLookupParameter<ItemCollection<DoubleValue>>)Parameters["ComparisonFactor"]; } 53 48 } 54 49 public ILookupParameter<ResultCollection> ResultsParameter { … … 85 80 86 81 [Storable] 87 private ScatterPlotHelper plotHelper, childDiversity Helper, parentDiversityHelper;82 private ScatterPlotHelper plotHelper, childDiversityToWorseParentHelper, childDiversityToBetterParentHelper, parentDiversityHelper, parentQualityHelper; 88 83 [Storable] 89 84 private DataTableHelper performanceHelper, successHelper, equalParentsHelper; … … 109 104 qualityPoints = new List<double>(original.qualityPoints); 110 105 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); 112 108 parentDiversityHelper = (ScatterPlotHelper)original.parentDiversityHelper.Clone(cloner); 109 parentQualityHelper = (ScatterPlotHelper)original.parentQualityHelper.Clone(cloner); 113 110 performanceHelper = (DataTableHelper)original.performanceHelper.Clone(cloner); 114 111 successHelper = (DataTableHelper)original.successHelper.Clone(cloner); … … 136 133 Parameters.Add(new LookupParameter<ItemCollection<IItem>>("Operators", "The operators and items that the problem provides to the algorithms.")); 137 134 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.")); 142 136 143 137 144 138 plotHelper = new ScatterPlotHelper(false, true); 145 childDiversityHelper = new ScatterPlotHelper(false, true); 139 childDiversityToWorseParentHelper = new ScatterPlotHelper(false, true); 140 childDiversityToBetterParentHelper = new ScatterPlotHelper(false, true); 146 141 parentDiversityHelper = new ScatterPlotHelper(false, true); 142 parentQualityHelper = new ScatterPlotHelper(false, true); 147 143 performanceHelper = new DataTableHelper(); 148 144 successHelper = new DataTableHelper(); … … 159 155 } 160 156 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 161 165 if (success == null) { 162 166 success = new int[ComparisonFactorParameter.Value.Count]; … … 164 168 165 169 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"); 167 172 parentDiversityHelper.InitializePlot(Results, "Parent Diversity", "Solution Index", "Diversity"); 173 parentQualityHelper.InitializePlot(Results, "Parent Quality Difference", "Solution Index", "Absolut Quality Difference"); 168 174 performanceHelper.InitializeChart(Results, "Average Crossover Performance", new string[] { "Average Crossover Performance per Generation" }); 169 175 equalParentsHelper.InitializeChart(Results, "Number of equal parents", new string[] { "Absolut number of equal parents" }); … … 179 185 Initialize(); 180 186 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(); 182 190 var qualityParent1 = ParentsQualityParameter.ActualValue.First().Value; 183 191 var qualityParent2 = ParentsQualityParameter.ActualValue.Last().Value; 192 var child = ChildParameter.ActualValue; 184 193 var qualityChild = QualityParameter.ActualValue.Value; 185 var child = ChildParameter.ActualValue; 186 var parent1 = ParentsParameter.ActualValue.First(); 187 var parent2 = ParentsParameter.ActualValue.Last(); 194 188 195 var parentDiversity = SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope.SubScopes.First(), ExecutionContext.Scope.SubScopes.Last()); 189 196 string curGenStr = GenerationsParameter.ActualValue.Value.ToString(); 190 197 191 198 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 192 219 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 199 220 qualityPoint = new Point2D<double>(cnt++, worseQuality - qualityChild); 200 221 qualityPoints.Add(qualityPoint.Y); … … 227 248 228 249 plotHelper.AddPoint(curGenStr, qualityPoint); 229 childDiversityHelper.AddPoint(curGenStr, diversityPointChild); 250 childDiversityToWorseParentHelper.AddPoint(curGenStr, childDiversityToWorseParent); 251 childDiversityToBetterParentHelper.AddPoint(curGenStr, childDiversityToBetterParent); 230 252 parentDiversityHelper.AddPoint(curGenStr, diversityPointParent); 253 parentQualityHelper.AddPoint(curGenStr, qualityPointParent); 231 254 } else { 232 255 Reset();
Note: See TracChangeset
for help on using the changeset viewer.