- Timestamp:
- 12/05/11 15:02:42 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs
r6978 r7124 52 52 } 53 53 public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter { 54 get { 55 return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; 56 } 54 get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; } 57 55 } 58 56 public ValueLookupParameter<DataTableHistory> SymbolicExpressionTreeLengthsHistoryParameter { 59 get { 60 return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; 61 } 57 get { return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; } 62 58 } 63 59 public ValueLookupParameter<ResultCollection> ResultsParameter { … … 75 71 } 76 72 #endregion 73 77 74 [StorableConstructor] 78 75 private SymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { } … … 91 88 Parameters.Add(new ValueLookupParameter<DataTableHistory>(SymbolicExpressionTreeLengthsHistoryParameterName, "The data table to store the symbolic expression tree lengths history.")); 92 89 Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored.")); 93 94 #region Add parameters for history95 90 Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false))); 96 91 Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1))); 97 92 Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter")); 98 #endregion99 93 100 94 UpdateCounterParameter.Hidden = true; … … 136 130 // if the table was not created yet, we create it here 137 131 if (treeLengthsTable == null) { 138 treeLengthsTable = new DataTable(" Tree Length Values");132 treeLengthsTable = new DataTable("Histogram"); 139 133 SymbolicExpressionTreeLengthsParameter.ActualValue = treeLengthsTable; 140 134 } 141 135 142 136 // data table which stores tree length values 143 DataRow dataRow; 137 DataRow treeLengthsTableRow; 138 139 const string treeLengthsTableRowName = "Symbolic expression tree lengths"; 140 const string treeLengthsTableRowDesc = "The distribution of symbolic expression tree lengths"; 141 const string xAxisTitle = "Symbolic expression tree lengths"; 142 const string yAxisTitle = "Frequency / Number of tree individuals"; 144 143 145 144 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); 145 int maxLength = solutions.Max(s => s.Length); 146 int minLength = solutions.Min(s => s.Length); 147 148 if (!treeLengthsTable.Rows.ContainsKey(treeLengthsTableRowName)) { 149 treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths); 150 treeLengthsTable.Rows.Add(treeLengthsTableRow); 150 151 } else { 151 dataRow = treeLengthsTable.Rows["Tree Lengths"];152 dataRow.Values.Replace(treeLengths);152 treeLengthsTableRow = treeLengthsTable.Rows[treeLengthsTableRowName]; 153 treeLengthsTableRow.Values.Replace(treeLengths); 153 154 } 154 155 155 156 double maximumAllowedTreeLength = ((LookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]).ActualValue.Value; 156 157 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; 158 treeLengthsTableRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 159 treeLengthsTableRow.VisualProperties.ExactBins = false; 160 161 // the following trick should result in an integer intervalWidth of 1,2,4,... 162 treeLengthsTableRow.VisualProperties.Bins = maxLength - minLength; 163 164 if (maxLength <= 25) // [0,25] 165 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0; 166 166 else if (maxLength <= 100) // [26,100]) 167 dataRow.VisualProperties.ScaleFactor = 1.0 / 2.0;167 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 2.0; 168 168 else if (maxLength <= 250) // [100,250] 169 dataRow.VisualProperties.ScaleFactor = 1.0 / 5.0;169 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 5.0; 170 170 else if (maxLength <= 500) // [251,500] 171 dataRow.VisualProperties.ScaleFactor = 1.0 / 10.0;171 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 10.0; 172 172 else 173 dataRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf] 173 treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf] 174 175 treeLengthsTableRow.VisualProperties.IsVisibleInLegend = false; 174 176 175 177 // visual properties for the X-axis … … 178 180 treeLengthsTable.VisualProperties.XAxisMinimumFixedValue = 0.0; 179 181 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 trimmed182 treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed 181 183 else 182 184 treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1; 185 treeLengthsTable.VisualProperties.XAxisTitle = xAxisTitle; 183 186 // visual properties for the Y-axis 184 187 treeLengthsTable.VisualProperties.YAxisMinimumAuto = false; … … 186 189 treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0; 187 190 treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0); 191 treeLengthsTable.VisualProperties.YAxisTitle = yAxisTitle; 188 192 189 193 var results = ResultsParameter.ActualValue; 190 194 191 if (!results.ContainsKey( "Tree Lengths")) {192 results.Add(new Result( "Tree Lengths", treeLengthsTable));195 if (!results.ContainsKey(treeLengthsTableRowName)) { 196 results.Add(new Result(treeLengthsTableRowName, treeLengthsTable)); 193 197 } else { 194 results[ "Tree Lengths"].Value = treeLengthsTable;198 results[treeLengthsTableRowName].Value = treeLengthsTable; 195 199 } 196 200 197 201 bool storeHistory = StoreHistoryParameter.Value.Value; 202 const string treeLengthHistoryTableName = "Tree lengths history"; 203 const string treeLengthHistoryRowPrefix = "Tree lengths "; 204 int currentGeneration = ((IntValue)results["Generations"].Value).Value; 198 205 199 206 if (storeHistory) { 200 207 // store tree lengths for each generation 201 var historyDataRow = new DataRow( "Tree Lengths " + results["Generations"].Value, "", dataRow.Values);208 var historyDataRow = new DataRow(treeLengthHistoryRowPrefix + currentGeneration, "Symbolic expression tree lengths at generation " + currentGeneration, treeLengthsTableRow.Values); 202 209 historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 203 210 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"]);211 historyDataRow.VisualProperties.Bins = maxLength - minLength; 212 historyDataRow.VisualProperties.ScaleFactor = treeLengthsTableRow.VisualProperties.ScaleFactor; 213 var historyTable = new DataTable(); 207 214 historyTable.Rows.Add(historyDataRow); 208 215 // visual properties for the X-axis … … 210 217 historyTable.VisualProperties.XAxisMaximumAuto = false; 211 218 historyTable.VisualProperties.XAxisMinimumFixedValue = 0.0; 212 if ( solutions.Max(s => s.Length)> maximumAllowedTreeLength + 1)219 if (maxLength > maximumAllowedTreeLength + 1) 213 220 historyTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed 214 221 else 215 222 historyTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1; 223 historyTable.VisualProperties.XAxisTitle = xAxisTitle; 216 224 // visual properties for the Y-axis 217 225 historyTable.VisualProperties.YAxisMinimumAuto = false; … … 219 227 historyTable.VisualProperties.YAxisMinimumFixedValue = 0.0; 220 228 historyTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0); 229 historyTable.VisualProperties.YAxisTitle = yAxisTitle; 221 230 222 231 var treeLengthsHistory = SymbolicExpressionTreeLengthsHistoryParameter.ActualValue; … … 228 237 treeLengthsHistory.Add(historyTable); 229 238 230 if (!results.ContainsKey( "Tree Lengths History")) {231 results.Add(new Result( "Tree Lengths History", treeLengthsHistory));239 if (!results.ContainsKey(treeLengthHistoryTableName)) { 240 results.Add(new Result(treeLengthHistoryTableName, treeLengthsHistory)); 232 241 } else { 233 results[ "Tree Lengths History"].Value = treeLengthsHistory;242 results[treeLengthHistoryTableName].Value = treeLengthsHistory; 234 243 } 235 244 } 236 245 } 237 238 246 return base.Apply(); 239 247 }
Note: See TracChangeset
for help on using the changeset viewer.