Changeset 7215 for branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers
- Timestamp:
- 12/20/11 13:54:57 (13 years ago)
- Location:
- branches/HeuristicLab.Hive.Azure
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive.Azure
- Property svn:ignore
-
old new 4 4 *.suo 5 5 *.vsp 6 Doxygen 6 7 Google.ProtocolBuffers-0.9.1.dll 7 8 HeuristicLab 3.3.5.1.ReSharper.user 8 9 HeuristicLab 3.3.6.0.ReSharper.user 9 10 HeuristicLab.4.5.resharper.user 11 HeuristicLab.ExtLibs.6.0.ReSharper.user 10 12 HeuristicLab.resharper.user 11 13 ProtoGen.exe … … 16 18 bin 17 19 protoc.exe 18 HeuristicLab.ExtLibs.6.0.ReSharper.user19 Doxygen
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeLengthAnalyzer.cs
r5809 r7215 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/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs
r6803 r7215 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/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs
r6978 r7215 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 23 using HeuristicLab.Analysis; … … 52 51 } 53 52 public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter { 54 get { 55 return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; 56 } 53 get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; } 57 54 } 58 55 public ValueLookupParameter<DataTableHistory> SymbolicExpressionTreeLengthsHistoryParameter { 59 get { 60 return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; 61 } 56 get { return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; } 62 57 } 63 58 public ValueLookupParameter<ResultCollection> ResultsParameter { … … 71 66 get { return (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 72 67 } 73 public LookupParameter<IntValue> UpdateCounterParameter {74 get { return ( LookupParameter<IntValue>)Parameters[UpdateCounterParameterName]; }68 public ValueParameter<IntValue> UpdateCounterParameter { 69 get { return (ValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; } 75 70 } 76 71 #endregion 72 73 #region Properties 74 public bool EnabledByDefault { 75 get { return true; } 76 } 77 public IntValue UpdateInterval { 78 get { return UpdateIntervalParameter.Value; } 79 } 80 public IntValue UpdateCounter { 81 get { return UpdateCounterParameter.Value; } 82 } 83 public BoolValue StoreHistory { 84 get { return StoreHistoryParameter.Value; } 85 } 86 #endregion 87 77 88 [StorableConstructor] 78 89 private SymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { } … … 91 102 Parameters.Add(new ValueLookupParameter<DataTableHistory>(SymbolicExpressionTreeLengthsHistoryParameterName, "The data table to store the symbolic expression tree lengths history.")); 92 103 Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored.")); 93 94 #region Add parameters for history95 104 Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false))); 96 105 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 100 UpdateCounterParameter.Hidden = true; 106 Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0))); 101 107 102 108 AfterDeserialization(); … … 112 118 Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1))); 113 119 } 114 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 } 120 if (Parameters.ContainsKey(UpdateCounterParameterName)) 121 Parameters.Remove(UpdateCounterParameterName); 122 Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0))); 123 124 SymbolicExpressionTreeLengthsParameter.Hidden = true; 125 SymbolicExpressionTreeLengthsHistoryParameter.Hidden = true; 126 ResultsParameter.Hidden = true; 127 UpdateCounterParameter.Hidden = true; 117 128 } 118 129 119 130 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 131 UpdateCounter.Value++; 128 132 // the analyzer runs periodically, every 'updateInterval' times 129 if ( updateCounter.Value == updateInterval) {130 updateCounter.Value = 0; // reset counter133 if (UpdateCounter.Value == UpdateInterval.Value) { 134 UpdateCounter.Value = 0; // reset counter 131 135 132 136 // compute all tree lengths and store them in the lengthsTable … … 136 140 // if the table was not created yet, we create it here 137 141 if (treeLengthsTable == null) { 138 treeLengthsTable = new DataTable(" Tree Length Values");142 treeLengthsTable = new DataTable("Histogram"); 139 143 SymbolicExpressionTreeLengthsParameter.ActualValue = treeLengthsTable; 140 144 } 141 145 142 146 // 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); 147 DataRow treeLengthsTableRow; 148 149 const string treeLengthsTableRowName = "Symbolic expression tree lengths"; 150 const string treeLengthsTableRowDesc = "The distribution of symbolic expression tree lengths"; 151 const string xAxisTitle = "Symbolic expression tree lengths"; 152 const string yAxisTitle = "Frequency / Number of tree individuals"; 153 154 var treeLengths = solutions.Select(s => (int)s.Length).ToList(); 155 156 int maxLength = treeLengths.Max(t => t); 157 int minLength = treeLengths.Min(t => t); 158 159 if (!treeLengthsTable.Rows.ContainsKey(treeLengthsTableRowName)) { 160 treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths.Select(x => (double)x)); 161 treeLengthsTable.Rows.Add(treeLengthsTableRow); 150 162 } else { 151 dataRow = treeLengthsTable.Rows["Tree Lengths"];152 dataRow.Values.Replace(treeLengths);163 treeLengthsTableRow = treeLengthsTable.Rows[treeLengthsTableRowName]; 164 treeLengthsTableRow.Values.Replace(treeLengths.Select(x => (double)x)); 153 165 } 154 166 155 167 double maximumAllowedTreeLength = ((LookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]).ActualValue.Value; 156 168 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; 169 treeLengthsTableRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 170 treeLengthsTableRow.VisualProperties.ExactBins = false; 171 172 int range = maxLength - minLength; 173 if (range == 0) range = 1; 174 // the following trick should result in an integer intervalWidth of 1,2,4,... 175 treeLengthsTableRow.VisualProperties.Bins = range; 176 177 if (maxLength <= 25) // [0,25] 178 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0; 179 else if (maxLength <= 100) // [26,100] 180 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 2.0; 181 else if (maxLength <= 250) // [101,250] 182 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 5.0; 170 183 else if (maxLength <= 500) // [251,500] 171 dataRow.VisualProperties.ScaleFactor = 1.0 / 10.0;184 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 10.0; 172 185 else 173 dataRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf] 186 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf] 187 188 treeLengthsTableRow.VisualProperties.IsVisibleInLegend = false; 174 189 175 190 // visual properties for the X-axis … … 178 193 treeLengthsTable.VisualProperties.XAxisMinimumFixedValue = 0.0; 179 194 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 trimmed195 treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed 181 196 else 182 197 treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1; 183 // visual properties for the Y-axis 198 treeLengthsTable.VisualProperties.XAxisTitle = xAxisTitle; 199 //visual properties for the Y-axis 184 200 treeLengthsTable.VisualProperties.YAxisMinimumAuto = false; 185 201 treeLengthsTable.VisualProperties.YAxisMaximumAuto = false; 186 202 treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0; 187 treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0); 203 int maxFreq = solutions.GroupBy(s => s.Length).Max(g => g.Count()); 204 if (maxFreq % 5 != 0) 205 maxFreq += (5 - maxFreq % 5); 206 double yAxisMaximumFixedValue = maxFreq; 207 208 treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue; 209 treeLengthsTable.VisualProperties.YAxisTitle = yAxisTitle; 188 210 189 211 var results = ResultsParameter.ActualValue; 190 212 191 if (!results.ContainsKey( "Tree Lengths")) {192 results.Add(new Result( "Tree Lengths", treeLengthsTable));213 if (!results.ContainsKey(treeLengthsTableRowName)) { 214 results.Add(new Result(treeLengthsTableRowName, treeLengthsTable)); 193 215 } else { 194 results[ "Tree Lengths"].Value = treeLengthsTable;216 results[treeLengthsTableRowName].Value = treeLengthsTable; 195 217 } 196 218 197 219 bool storeHistory = StoreHistoryParameter.Value.Value; 220 const string treeLengthHistoryTableName = "Tree lengths history"; 198 221 199 222 if (storeHistory) { 200 223 // store tree lengths for each generation 201 var historyDataRow = new DataRow("Tree Lengths " + results["Generations"].Value, "", dataRow.Values);224 var historyDataRow = new DataRow("Tree lengths", "", treeLengthsTableRow.Values); 202 225 historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 203 226 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"]); 227 historyDataRow.VisualProperties.Bins = range; 228 historyDataRow.VisualProperties.ScaleFactor = treeLengthsTableRow.VisualProperties.ScaleFactor; 229 historyDataRow.VisualProperties.IsVisibleInLegend = false; 230 var historyTable = new DataTable("Tree lengths"); 207 231 historyTable.Rows.Add(historyDataRow); 208 232 // visual properties for the X-axis … … 210 234 historyTable.VisualProperties.XAxisMaximumAuto = false; 211 235 historyTable.VisualProperties.XAxisMinimumFixedValue = 0.0; 212 if ( solutions.Max(s => s.Length)> maximumAllowedTreeLength + 1)236 if (maxLength > maximumAllowedTreeLength + 1) 213 237 historyTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed 214 238 else 215 239 historyTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1; 240 historyTable.VisualProperties.XAxisTitle = xAxisTitle; 216 241 // visual properties for the Y-axis 217 242 historyTable.VisualProperties.YAxisMinimumAuto = false; 218 243 historyTable.VisualProperties.YAxisMaximumAuto = false; 219 244 historyTable.VisualProperties.YAxisMinimumFixedValue = 0.0; 220 historyTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0); 245 historyTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue; 246 historyTable.VisualProperties.YAxisTitle = yAxisTitle; 221 247 222 248 var treeLengthsHistory = SymbolicExpressionTreeLengthsHistoryParameter.ActualValue; … … 228 254 treeLengthsHistory.Add(historyTable); 229 255 230 if (!results.ContainsKey( "Tree Lengths History")) {231 results.Add(new Result( "Tree Lengths History", treeLengthsHistory));256 if (!results.ContainsKey(treeLengthHistoryTableName)) { 257 results.Add(new Result(treeLengthHistoryTableName, treeLengthsHistory)); 232 258 } else { 233 results[ "Tree Lengths History"].Value = treeLengthsHistory;259 results[treeLengthHistoryTableName].Value = treeLengthsHistory; 234 260 } 235 261 } 236 262 } 237 238 263 return base.Apply(); 239 264 }
Note: See TracChangeset
for help on using the changeset viewer.