Changeset 7344 for branches/gp-crossover/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers
- Timestamp:
- 01/17/12 15:18:03 (13 years ago)
- Location:
- branches/gp-crossover/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gp-crossover/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeLengthAnalyzer.cs
r5809 r7344 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 1Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 43 43 private const string MaxTreeLengthParameterName = "Maximal symbolic expression tree length"; 44 44 private const string ResultsParameterName = "Results"; 45 46 public bool EnabledByDefault { 47 get { return true; } 48 } 45 49 46 50 #region parameter properties -
branches/gp-crossover/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs
r6803 r7344 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 1Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 59 59 #endregion 60 60 #region properties 61 public virtual bool EnabledByDefault { 62 get { return true; } 63 } 61 64 public BoolValue AggregrateSymbolsWithDifferentSubtreeCount { 62 65 get { return AggregateSymbolsWithDifferentSubtreeCountParameter.Value; } -
branches/gp-crossover/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs
r6978 r7344 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 1Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using System; 32 33 33 34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 52 53 } 53 54 public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter { 54 get { 55 return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; 56 } 55 get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; } 57 56 } 58 57 public ValueLookupParameter<DataTableHistory> SymbolicExpressionTreeLengthsHistoryParameter { 59 get { 60 return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; 61 } 58 get { return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; } 62 59 } 63 60 public ValueLookupParameter<ResultCollection> ResultsParameter { … … 71 68 get { return (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 72 69 } 73 public LookupParameter<IntValue> UpdateCounterParameter {74 get { return ( LookupParameter<IntValue>)Parameters[UpdateCounterParameterName]; }70 public ValueParameter<IntValue> UpdateCounterParameter { 71 get { return (ValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; } 75 72 } 76 73 #endregion 74 75 #region Properties 76 public bool EnabledByDefault { 77 get { return true; } 78 } 79 public IntValue UpdateInterval { 80 get { return UpdateIntervalParameter.Value; } 81 } 82 public IntValue UpdateCounter { 83 get { return UpdateCounterParameter.Value; } 84 } 85 public BoolValue StoreHistory { 86 get { return StoreHistoryParameter.Value; } 87 } 88 #endregion 89 77 90 [StorableConstructor] 78 91 private SymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { } 79 92 private SymbolicExpressionTreeLengthAnalyzer(SymbolicExpressionTreeLengthAnalyzer original, Cloner cloner) 80 93 : base(original, cloner) { 81 AfterDeserialization();82 94 } 83 95 public override IDeepCloneable Clone(Cloner cloner) { … … 91 103 Parameters.Add(new ValueLookupParameter<DataTableHistory>(SymbolicExpressionTreeLengthsHistoryParameterName, "The data table to store the symbolic expression tree lengths history.")); 92 104 Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored.")); 93 94 #region Add parameters for history95 105 Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false))); 96 106 Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1))); 97 Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter")); 98 #endregion 99 107 Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0))); 108 109 SymbolicExpressionTreeLengthsParameter.Hidden = true; 110 SymbolicExpressionTreeLengthsHistoryParameter.Hidden = true; 111 ResultsParameter.Hidden = true; 100 112 UpdateCounterParameter.Hidden = true; 101 102 AfterDeserialization();103 113 } 104 114 … … 112 122 Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1))); 113 123 } 124 //necessary code to correct UpdateCounterParameter - type was changed from LookupParameter to ValueParameter 125 if (Parameters.ContainsKey(UpdateCounterParameterName) && (Parameters[UpdateCounterParameterName] is LookupParameter<IntValue>)) 126 Parameters.Remove(UpdateCounterParameterName); 114 127 if (!Parameters.ContainsKey(UpdateCounterParameterName)) { 115 Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter")); 116 } 117 } 128 Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0))); 129 UpdateCounterParameter.Hidden = true; 130 } 131 } 132 133 #region IStatefulItem members 134 public override void InitializeState() { 135 base.InitializeState(); 136 UpdateCounter.Value = 0; 137 } 138 public override void ClearState() { 139 base.ClearState(); 140 UpdateCounter.Value = 0; 141 } 142 #endregion 118 143 119 144 public override IOperation Apply() { 120 int updateInterval = UpdateIntervalParameter.Value.Value; 121 IntValue updateCounter = UpdateCounterParameter.ActualValue; 122 // if the counter doesn't exist yet, we initialize it here with the current update interval 123 if (updateCounter == null) { 124 updateCounter = new IntValue(updateInterval); 125 UpdateCounterParameter.ActualValue = updateCounter; 126 } else updateCounter.Value++; 127 145 UpdateCounter.Value++; 128 146 // the analyzer runs periodically, every 'updateInterval' times 129 if ( updateCounter.Value == updateInterval) {130 updateCounter.Value = 0; // reset counter147 if (UpdateCounter.Value == UpdateInterval.Value) { 148 UpdateCounter.Value = 0; // reset counter 131 149 132 150 // compute all tree lengths and store them in the lengthsTable … … 136 154 // if the table was not created yet, we create it here 137 155 if (treeLengthsTable == null) { 138 treeLengthsTable = new DataTable(" Tree Length Values");156 treeLengthsTable = new DataTable("Histogram"); 139 157 SymbolicExpressionTreeLengthsParameter.ActualValue = treeLengthsTable; 140 158 } 141 159 142 160 // data table which stores tree length values 143 DataRow dataRow; 144 145 var treeLengths = solutions.Select(s => (double)s.Length); 146 147 if (!treeLengthsTable.Rows.ContainsKey("Tree Lengths")) { 148 dataRow = new DataRow("Tree Lengths", "", treeLengths); 149 treeLengthsTable.Rows.Add(dataRow); 161 DataRow treeLengthsTableRow; 162 163 const string treeLengthsTableRowName = "Symbolic expression tree lengths"; 164 const string treeLengthsTableRowDesc = "The distribution of symbolic expression tree lengths"; 165 const string xAxisTitle = "Symbolic expression tree lengths"; 166 const string yAxisTitle = "Frequency / Number of tree individuals"; 167 168 var treeLengths = solutions.Select(s => (int)s.Length).ToList(); 169 170 int maxLength = treeLengths.Max(t => t); 171 int minLength = treeLengths.Min(t => t); 172 173 if (!treeLengthsTable.Rows.ContainsKey(treeLengthsTableRowName)) { 174 treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths.Select(x => (double)x)); 175 treeLengthsTable.Rows.Add(treeLengthsTableRow); 150 176 } else { 151 dataRow = treeLengthsTable.Rows["Tree Lengths"];152 dataRow.Values.Replace(treeLengths);177 treeLengthsTableRow = treeLengthsTable.Rows[treeLengthsTableRowName]; 178 treeLengthsTableRow.Values.Replace(treeLengths.Select(x => (double)x)); 153 179 } 154 180 155 181 double maximumAllowedTreeLength = ((LookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]).ActualValue.Value; 156 182 157 dataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 158 dataRow.VisualProperties.ExactBins = false; 159 160 // the following trick should result in an intervalWidth of 1,2,4,... (an int value) 161 dataRow.VisualProperties.Bins = solutions.Max(s => s.Length) - solutions.Min(s => s.Length); 162 163 int maxLength = solutions.Max(s => s.Length); 164 if (maxLength <= 25) // [0,25] 165 dataRow.VisualProperties.ScaleFactor = 1.0; 166 else if (maxLength <= 100) // [26,100]) 167 dataRow.VisualProperties.ScaleFactor = 1.0 / 2.0; 168 else if (maxLength <= 250) // [100,250] 169 dataRow.VisualProperties.ScaleFactor = 1.0 / 5.0; 183 treeLengthsTableRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 184 treeLengthsTableRow.VisualProperties.ExactBins = false; 185 186 int range = maxLength - minLength; 187 if (range == 0) range = 1; 188 // the following trick should result in an integer intervalWidth of 1,2,4,... 189 treeLengthsTableRow.VisualProperties.Bins = range; 190 191 if (maxLength <= 25) // [0,25] 192 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0; 193 else if (maxLength <= 100) // [26,100] 194 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 2.0; 195 else if (maxLength <= 250) // [101,250] 196 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 5.0; 170 197 else if (maxLength <= 500) // [251,500] 171 dataRow.VisualProperties.ScaleFactor = 1.0 / 10.0;198 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 10.0; 172 199 else 173 dataRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf] 200 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf] 201 202 treeLengthsTableRow.VisualProperties.IsVisibleInLegend = false; 174 203 175 204 // visual properties for the X-axis … … 178 207 treeLengthsTable.VisualProperties.XAxisMinimumFixedValue = 0.0; 179 208 if (maxLength > maximumAllowedTreeLength + 1) 180 treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = solutions.Max(s => s.Length)+ 1; // +1 so the histogram column for the maximum length won't get trimmed209 treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed 181 210 else 182 211 treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1; 183 // visual properties for the Y-axis 212 treeLengthsTable.VisualProperties.XAxisTitle = xAxisTitle; 213 //visual properties for the Y-axis 184 214 treeLengthsTable.VisualProperties.YAxisMinimumAuto = false; 185 215 treeLengthsTable.VisualProperties.YAxisMaximumAuto = false; 186 216 treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0; 187 treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0); 217 int maxFreq = (int)Math.Round(solutions.GroupBy(s => s.Length).Max(g => g.Count()) / treeLengthsTableRow.VisualProperties.ScaleFactor); 218 if (maxFreq % 5 != 0) 219 maxFreq += (5 - maxFreq % 5); 220 double yAxisMaximumFixedValue = maxFreq; 221 222 treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue; 223 treeLengthsTable.VisualProperties.YAxisTitle = yAxisTitle; 188 224 189 225 var results = ResultsParameter.ActualValue; 190 226 191 if (!results.ContainsKey( "Tree Lengths")) {192 results.Add(new Result( "Tree Lengths", treeLengthsTable));227 if (!results.ContainsKey(treeLengthsTableRowName)) { 228 results.Add(new Result(treeLengthsTableRowName, treeLengthsTable)); 193 229 } else { 194 results[ "Tree Lengths"].Value = treeLengthsTable;230 results[treeLengthsTableRowName].Value = treeLengthsTable; 195 231 } 196 232 197 233 bool storeHistory = StoreHistoryParameter.Value.Value; 234 const string treeLengthHistoryTableName = "Tree lengths history"; 198 235 199 236 if (storeHistory) { 200 // store tree lengths for each generation201 var historyDataRow = new DataRow("Tree Lengths " + results["Generations"].Value, "", dataRow.Values);202 historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;203 historyDataRow.VisualProperties.ExactBins = false;204 historyDataRow.VisualProperties.Bins = solutions.Max(s => s.Length) - solutions.Min(s => s.Length);205 historyDataRow.VisualProperties.ScaleFactor = dataRow.VisualProperties.ScaleFactor;206 var historyTable = new DataTable("Lengths Table " + results["Generations"]);207 historyTable.Rows.Add(historyDataRow);208 // visual properties for the X-axis209 historyTable.VisualProperties.XAxisMinimumAuto = false;210 historyTable.VisualProperties.XAxisMaximumAuto = false;211 historyTable.VisualProperties.XAxisMinimumFixedValue = 0.0;212 if (solutions.Max(s => s.Length) > maximumAllowedTreeLength + 1)213 historyTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed214 else215 historyTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;216 // visual properties for the Y-axis217 historyTable.VisualProperties.YAxisMinimumAuto = false;218 historyTable.VisualProperties.YAxisMaximumAuto = false;219 historyTable.VisualProperties.YAxisMinimumFixedValue = 0.0;220 historyTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0);221 222 237 var treeLengthsHistory = SymbolicExpressionTreeLengthsHistoryParameter.ActualValue; 223 238 if (treeLengthsHistory == null) { … … 225 240 SymbolicExpressionTreeLengthsHistoryParameter.ActualValue = treeLengthsHistory; 226 241 } 227 228 treeLengthsHistory.Add(historyTable); 229 230 if (!results.ContainsKey("Tree Lengths History")) { 231 results.Add(new Result("Tree Lengths History", treeLengthsHistory)); 242 treeLengthsHistory.Add((DataTable)treeLengthsTable.Clone()); 243 244 if (!results.ContainsKey(treeLengthHistoryTableName)) { 245 results.Add(new Result(treeLengthHistoryTableName, treeLengthsHistory)); 232 246 } else { 233 results[ "Tree Lengths History"].Value = treeLengthsHistory;247 results[treeLengthHistoryTableName].Value = treeLengthsHistory; 234 248 } 235 249 } 236 250 } 237 238 251 return base.Apply(); 239 252 } -
branches/gp-crossover/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthCalculator.cs
r5809 r7344 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 1Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab.
Note: See TracChangeset
for help on using the changeset viewer.