Changeset 7213 for branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Timestamp:
- 12/20/11 11:45:18 (13 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj
r6866 r7213 176 176 </ItemGroup> 177 177 <ItemGroup> 178 <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj"> 179 <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project> 180 <Name>HeuristicLab.Analysis-3.3</Name> 181 <Private>False</Private> 182 </ProjectReference> 183 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 184 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> 185 <Name>HeuristicLab.Collections-3.3</Name> 186 <Private>False</Private> 187 </ProjectReference> 188 <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj"> 189 <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project> 190 <Name>HeuristicLab.Common.Resources-3.3</Name> 191 <Private>False</Private> 192 </ProjectReference> 193 <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj"> 194 <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project> 195 <Name>HeuristicLab.Common-3.3</Name> 196 <Private>False</Private> 197 </ProjectReference> 198 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 199 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> 200 <Name>HeuristicLab.Core-3.3</Name> 201 <Private>False</Private> 202 </ProjectReference> 203 <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj"> 204 <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project> 205 <Name>HeuristicLab.Data-3.3</Name> 206 <Private>False</Private> 207 </ProjectReference> 208 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> 209 <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project> 210 <Name>HeuristicLab.Operators-3.3</Name> 211 <Private>False</Private> 212 </ProjectReference> 213 <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj"> 214 <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project> 215 <Name>HeuristicLab.Optimization.Operators-3.3</Name> 216 <Private>False</Private> 217 </ProjectReference> 218 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 219 <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project> 220 <Name>HeuristicLab.Optimization-3.3</Name> 221 <Private>False</Private> 222 </ProjectReference> 223 <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj"> 224 <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project> 225 <Name>HeuristicLab.Parameters-3.3</Name> 226 <Private>False</Private> 227 </ProjectReference> 228 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj"> 229 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project> 230 <Name>HeuristicLab.Persistence-3.3</Name> 231 <Private>False</Private> 232 </ProjectReference> 233 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 234 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> 235 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 236 <Private>False</Private> 237 </ProjectReference> 238 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj"> 239 <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project> 240 <Name>HeuristicLab.Random-3.3</Name> 241 <Private>False</Private> 242 </ProjectReference> 178 <Reference Include="HeuristicLab.Analysis-3.3"> 179 <HintPath>..\..\bin\HeuristicLab.Analysis-3.3.dll</HintPath> 180 <Private>False</Private> 181 </Reference> 182 <Reference Include="HeuristicLab.Collections-3.3"> 183 <HintPath>..\..\bin\HeuristicLab.Collections-3.3.dll</HintPath> 184 <Private>False</Private> 185 </Reference> 186 <Reference Include="HeuristicLab.Common.Resources-3.3"> 187 <HintPath>..\..\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath> 188 <Private>False</Private> 189 </Reference> 190 <Reference Include="HeuristicLab.Common-3.3"> 191 <HintPath>..\..\bin\HeuristicLab.Common-3.3.dll</HintPath> 192 <Private>False</Private> 193 </Reference> 194 <Reference Include="HeuristicLab.Core-3.3"> 195 <HintPath>..\..\bin\HeuristicLab.Core-3.3.dll</HintPath> 196 <Private>False</Private> 197 </Reference> 198 <Reference Include="HeuristicLab.Data-3.3"> 199 <HintPath>..\..\bin\HeuristicLab.Data-3.3.dll</HintPath> 200 <Private>False</Private> 201 </Reference> 202 <Reference Include="HeuristicLab.Operators-3.3"> 203 <HintPath>..\..\bin\HeuristicLab.Operators-3.3.dll</HintPath> 204 <Private>False</Private> 205 </Reference> 206 <Reference Include="HeuristicLab.Optimization.Operators-3.3"> 207 <HintPath>..\..\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath> 208 <Private>False</Private> 209 </Reference> 210 <Reference Include="HeuristicLab.Optimization-3.3"> 211 <HintPath>..\..\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 212 <Private>False</Private> 213 </Reference> 214 <Reference Include="HeuristicLab.Parameters-3.3"> 215 <HintPath>..\..\bin\HeuristicLab.Parameters-3.3.dll</HintPath> 216 <Private>False</Private> 217 </Reference> 218 <Reference Include="HeuristicLab.Persistence-3.3"> 219 <HintPath>..\..\bin\HeuristicLab.Persistence-3.3.dll</HintPath> 220 <Private>False</Private> 221 </Reference> 222 <Reference Include="HeuristicLab.PluginInfrastructure-3.3"> 223 <HintPath>..\..\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 224 <Private>False</Private> 225 </Reference> 226 <Reference Include="HeuristicLab.Random-3.3"> 227 <HintPath>..\..\bin\HeuristicLab.Random-3.3.dll</HintPath> 228 <Private>False</Private> 229 </Reference> 243 230 </ItemGroup> 244 231 <ItemGroup> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeLengthAnalyzer.cs
r5809 r7213 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.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs
r6803 r7213 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.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs
r6978 r7213 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 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
r7076 r7213 148 148 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 149 149 150 var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0).ToList(); 151 150 152 for (var i = 0; i != arity; ++i) { 151 var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol, i).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0);153 var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList(); 152 154 var selectedSymbol = possibleSymbols.SelectRandom(random); 153 155 var tree = selectedSymbol.CreateTreeNode(); … … 158 160 // Only iterate over the non-terminal nodes (those which have arity > 0) 159 161 // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode 160 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) !=0))162 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)) 161 163 RecursiveGrowFull(random, subTree, 2, maxDepth); 162 164 } … … 168 170 throw new ArgumentException("Cannot grow node of arity zero. Expected a function node."); 169 171 172 var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList(); ; 173 170 174 for (var i = 0; i != arity; ++i) { 171 var possibleSymbols = root.Grammar.GetAllowedChildSymbols(root.Symbol, i); 172 possibleSymbols = possibleSymbols.Where(s => s.InitialFrequency > 0.0 && 173 root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth && 174 root.Grammar.GetMaximumExpressionDepth(s) > maxDepth - currentDepth); 175 var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) && 176 root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth && 177 root.Grammar.GetMaximumExpressionDepth(s) > maxDepth - currentDepth).ToList(); 178 if (!possibleSymbols.Any()) 179 throw new InvalidOperationException("No symbols are available for the tree."); 175 180 176 177 if (!possibleSymbols.Any()) throw new InvalidOperationException("No symbols are available for the tree.");178 181 var selectedSymbol = possibleSymbols.SelectRandom(random); 179 182 var tree = selectedSymbol.CreateTreeNode(); … … 182 185 } 183 186 184 foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) !=0))187 foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)) 185 188 RecursiveGrowFull(random, subTree, currentDepth + 1, maxDepth); 186 189 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs
r7076 r7213 146 146 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 147 147 148 var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList(); 148 149 149 150 for (var i = 0; i != arity; ++i) { 150 var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol, i).Where(s => s.InitialFrequency > 0.0);151 var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList(); 151 152 var selectedSymbol = possibleSymbols.SelectRandom(random); 152 153 var tree = selectedSymbol.CreateTreeNode(); … … 157 158 // Only iterate over the non-terminal nodes (those which have arity > 0) 158 159 // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode 159 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) !=0))160 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)) 160 161 RecursiveGrow(random, subTree, 2, maxDepth); 161 162 } … … 166 167 throw new ArgumentException("Cannot grow node of arity zero. Expected a function node."); 167 168 169 var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList(); 170 168 171 for (var i = 0; i != arity; ++i) { 169 var possibleSymbols = root.Grammar.GetAllowedChildSymbols(root.Symbol, i); 170 possibleSymbols = possibleSymbols.Where(s => s.InitialFrequency > 0.0 && 171 root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth); 172 if (!possibleSymbols.Any()) throw new InvalidOperationException("No symbols are available for the tree."); 172 var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) && root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth).ToList(); 173 if (!possibleSymbols.Any()) 174 throw new InvalidOperationException("No symbols are available for the tree."); 173 175 var selectedSymbol = possibleSymbols.SelectRandom(random); 174 176 var tree = selectedSymbol.CreateTreeNode(); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTree.cs
r5809 r7213 31 31 [Item("SymbolicExpressionTree", "Represents a symbolic expression tree.")] 32 32 public class SymbolicExpressionTree : Item, ISymbolicExpressionTree { 33 public override ImageItemImage {33 public static new Image StaticItemImage { 34 34 get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; } 35 35 }
Note: See TracChangeset
for help on using the changeset viewer.