Changeset 8797 for branches/HeuristicLab.Analysis.AlgorithmBehavior
- Timestamp:
- 10/11/12 17:17:36 (12 years ago)
- 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 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.PermutationEncoding; 29 using HeuristicLab.Operators;30 29 using HeuristicLab.Optimization; 31 30 using HeuristicLab.Parameters; … … 35 34 [Item("CrossoverPerformanceAnalyzer", "An operator that analyzes the performance of crossovers.")] 36 35 [StorableClass] 37 public class CrossoverPerformanceAnalyzer : SingleSuccessorOperator, IAnalyzer {36 public class CrossoverPerformanceAnalyzer : InitializableOperator, IAnalyzer { 38 37 private const string ResultsParameterName = "Results"; 39 38 private const string GenerationsParameterName = "Generations"; 39 private const string SuccessfullCrossoversRowName = "Successfull Crossovers per Generation with CompFact "; 40 40 41 41 #region IAnalyzer Members … … 46 46 47 47 #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 } 48 54 public ILookupParameter<ResultCollection> ResultsParameter { 49 55 get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; } … … 85 91 private int cnt = 0; 86 92 [Storable] 87 private int success = 0;93 private int[] success; 88 94 [Storable] 89 95 private int lastGeneration = 0; … … 98 104 : base(original, cloner) { 99 105 cnt = original.cnt; 100 success = original.success;106 success = (int[])original.success.Clone(); 101 107 lastGeneration = original.lastGeneration; 102 108 equalParents = original.equalParents; … … 129 135 Parameters.Add(new ValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator")); 130 136 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 131 143 132 144 plotHelper = new ScatterPlotHelper(false, true); … … 142 154 } 143 155 144 p ublic override IOperation Apply() {156 protected override void InitializeAction() { 145 157 if (SimilarityCalculatorParameter.Value == null) { 146 158 SimilarityCalculatorParameter.Value = OperatorsParameter.ActualValue.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault(); 159 } 160 161 if (success == null) { 162 success = new int[ComparisonFactorParameter.Value.Count]; 147 163 } 148 164 … … 150 166 childDiversityHelper.InitializePlot(Results, "Child Diversity", "Solution Index", "Diversity"); 151 167 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(); 156 180 157 181 Point2D<double> qualityPoint, diversityPointChild, diversityPointParent; 158 182 var qualityParent1 = ParentsQualityParameter.ActualValue.First().Value; 159 183 var qualityParent2 = ParentsQualityParameter.ActualValue.Last().Value; 184 var qualityChild = QualityParameter.ActualValue.Value; 160 185 var child = ChildParameter.ActualValue; 161 186 var parent1 = ParentsParameter.ActualValue.First(); … … 163 188 var parentDiversity = SimilarityCalculatorParameter.Value.CalculateSolutionSimilarity(ExecutionContext.Scope.SubScopes.First(), ExecutionContext.Scope.SubScopes.Last()); 164 189 string curGenStr = GenerationsParameter.ActualValue.Value.ToString(); 165 166 190 167 191 diversityPointParent = new Point2D<double>(cnt, parentDiversity); … … 173 197 } 174 198 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); 179 200 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 } 180 209 181 210 if (parentDiversity == 1.0) { … … 188 217 189 218 performanceHelper.AddPoint(avg); 190 successHelper.AddPoint(success);191 219 equalParentsHelper.AddPoint(equalParents); 220 221 for (int i = 0; i < compFactsArray.Length; i++) { 222 successHelper.AddPoint(SuccessfullCrossoversRowName + compFactsArray[i].Value.ToString(), success[i]); 223 } 192 224 193 225 Reset(); … … 206 238 private void Reset() { 207 239 cnt = 0; 208 success = 0;240 success = new int[ComparisonFactorParameter.Value.Count]; 209 241 lastGeneration = GenerationsParameter.ActualValue.Value; 210 242 qualityPoints.Clear(); -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DataTableHelper.cs
r8515 r8797 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 35 36 private string chartName; 36 37 [Storable] 37 private string dataRowName;38 private string[] dataRowNames; 38 39 [Storable] 39 private DataRow dtRow;40 DataTable dt; 40 41 41 42 [StorableConstructor] … … 49 50 } 50 51 51 public void InitializeChart(ResultCollection results, string chartName, string dataRowName) {52 public void InitializeChart(ResultCollection results, string chartName, string[] dataRowNames) { 52 53 if (!results.ContainsKey(chartName)) { 53 54 this.resultsCol = results; 54 55 this.chartName = chartName; 55 this.dataRowName = dataRowName;56 this.dataRowNames = dataRowNames; 56 57 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 60 65 results.Add(new Result(chartName, dt)); 61 66 } 62 67 } 63 68 69 public void AddPoint(string dataRow, double point) { 70 dt.Rows[dataRow].Values.Add(point); 71 } 72 64 73 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); 66 76 } 67 77 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DuplicateSolutionsAnalyzer.cs
r8722 r8797 87 87 SimilarityCalculatorParameter.Value = OperatorsParameter.ActualValue.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault(); 88 88 } 89 chartingHelper.InitializeChart(Results, "Duplicate Solutions", "Duplicate Solutions per Generation");89 chartingHelper.InitializeChart(Results, "Duplicate Solutions", new string[] { "Duplicate Solutions per Generation" }); 90 90 91 91 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 120 120 <Compile Include="AfterCrossoverCombinedOperator.cs" /> 121 121 <Compile Include="AfterMutationCombinedOperator.cs" /> 122 <Compile Include="InitializableOperator.cs" /> 122 123 <Compile Include="PathRelinkerPerformanceAnalyzer.cs" /> 123 124 <Compile Include="VariableRemover.cs" /> … … 137 138 <Compile Include="Properties\AssemblyInfo.cs" /> 138 139 <Compile Include="VariableDuplicator.cs" /> 140 <Compile Include="WeightedParentsQualityComparer.cs" /> 139 141 </ItemGroup> 140 142 <ItemGroup> -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/MutationPerformanceAnalyzer.cs
r8739 r8797 31 31 using HeuristicLab.Parameters; 32 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 using HeuristicLab.Problems.TravelingSalesman;34 33 35 34 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers { … … 145 144 qualityPlotHelper.InitializePlot(Results, "Mutation Quality", "Solution Index", "Absolut Quality Difference"); 146 145 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" }); 148 147 149 148 Scope permutationBeforeScope = new Scope(); -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/PathRelinkerPerformanceAnalyzer.cs
r8663 r8797 164 164 parentDiversityHelper.InitializePlot(Results, "Parent Diversity", "Solution Index", "Diversity"); 165 165 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" }); 169 169 170 170 Point2D<double> qualityPoint, diversityPointChild, diversityPointParent; -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/ScatterPlotHelper.cs
r8515 r8797 85 85 dataTableHelper = new DataTableHelper(); 86 86 } 87 dataTableHelper.InitializeChart(results, chartName + " Chart", yAxisTitle);87 dataTableHelper.InitializeChart(results, chartName + " Chart", new string[] { yAxisTitle }); 88 88 } 89 89
Note: See TracChangeset
for help on using the changeset viewer.