Changeset 5686 for branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Timestamp:
- 03/15/11 13:34:38 (13 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs
r5580 r5686 29 29 [StorableClass] 30 30 [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")] 31 public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {31 public class ArithmeticExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 32 33 33 [StorableConstructor] … … 59 59 60 60 foreach (var funSymb in functionSymbols) { 61 SetMinSubtreeCount(funSymb, 1); 62 SetMaxSubtreeCount(funSymb, 3); 61 SetSubtreeCount(funSymb, 1, 3); 63 62 } 64 SetMinSubtreeCount(constant, 0); 65 SetMaxSubtreeCount(constant, 0); 66 SetMinSubtreeCount(variableSymbol, 0); 67 SetMaxSubtreeCount(variableSymbol, 0); 63 SetSubtreeCount(constant, 0, 0); 64 SetSubtreeCount(variableSymbol, 0, 0); 68 65 69 66 // allow each symbol as child of the start symbol 70 67 foreach (var symb in allSymbols) { 71 SetAllowedChild(StartSymbol, symb, 0);68 AddAllowedChildSymbol(StartSymbol, symb); 72 69 } 73 70 74 71 // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0) 75 foreach (var parent in allSymbols) { 76 for (int i = 0; i < GetMaxSubtreeCount(parent); i++) 77 foreach (var child in allSymbols) { 78 SetAllowedChild(parent, child, i); 79 } 72 foreach (var parent in functionSymbols) { 73 foreach (var child in allSymbols) 74 AddAllowedChildSymbol(parent, child); 80 75 } 81 76 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs
r5580 r5686 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 29 30 [StorableClass] 30 31 [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")] 31 public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {32 public class FullFunctionalExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 33 [StorableConstructor] 33 34 protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { } … … 92 93 93 94 foreach (var funSymb in functionSymbols) { 94 SetMinSubtreeCount(funSymb, 1); 95 SetMaxSubtreeCount(funSymb, 3); 95 SetSubtreeCount(funSymb, 1, 3); 96 96 } 97 97 foreach (var funSymb in unaryFunctionSymbols) { 98 SetMinSubtreeCount(funSymb, 1); 99 SetMaxSubtreeCount(funSymb, 1); 98 SetSubtreeCount(funSymb, 1, 1); 100 99 } 101 100 foreach (var funSymb in binaryFunctionSymbols) { 102 SetMinSubtreeCount(funSymb, 2); 103 SetMaxSubtreeCount(funSymb, 2); 101 SetSubtreeCount(funSymb, 2, 2); 102 } 103 foreach (var terminalSymbol in terminalSymbols) { 104 SetSubtreeCount(terminalSymbol, 0, 0); 104 105 } 105 106 106 foreach (var terminalSymbol in terminalSymbols) { 107 SetMinSubtreeCount(terminalSymbol, 0); 108 SetMaxSubtreeCount(terminalSymbol, 0); 109 } 110 111 SetMinSubtreeCount(@if, 3); 112 SetMaxSubtreeCount(@if, 3); 107 SetSubtreeCount(@if, 3, 3); 113 108 114 109 115 110 // allow each symbol as child of the start symbol 116 111 foreach (var symb in allSymbols) { 117 SetAllowedChild(StartSymbol, symb, 0);112 AddAllowedChildSymbol(StartSymbol, symb); 118 113 } 119 114 120 115 // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0) 121 foreach (var parent in allSymbols) { 122 for (int i = 0; i < GetMaxSubtreeCount(parent); i++) 123 foreach (var child in allSymbols) { 124 SetAllowedChild(parent, child, i); 125 } 116 foreach (var parent in allSymbols.Except(terminalSymbols)) { 117 foreach (var child in allSymbols) 118 AddAllowedChildSymbol(parent, child); 126 119 } 127 120 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r5580 r5686 29 29 [StorableClass] 30 30 [Item("TypeCoherentExpressionGrammar", "Represents a grammar for functional expressions in which special syntactic constraints are enforced so that boolean and real-valued expressions are not mixed.")] 31 public class TypeCoherentExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {31 public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 32 33 33 [StorableConstructor] … … 123 123 124 124 foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) { 125 SetMinSubtreeCount(unaryFun, 1); 126 SetMaxSubtreeCount(unaryFun, 1); 125 SetSubtreeCount(unaryFun, 1, 1); 127 126 } 128 127 foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) { 129 SetMinSubtreeCount(binaryFun, 2); 130 SetMaxSubtreeCount(binaryFun, 2); 128 SetSubtreeCount(binaryFun, 2, 2); 131 129 } 132 130 133 131 foreach (var terminalSymbol in terminalSymbols) { 134 SetMinSubtreeCount(terminalSymbol, 0); 135 SetMaxSubtreeCount(terminalSymbol, 0); 132 SetSubtreeCount(terminalSymbol, 0, 0); 136 133 } 137 134 138 SetMinSubtreeCount(@if, 3); 139 SetMaxSubtreeCount(@if, 3); 135 SetSubtreeCount(@if, 3, 3); 140 136 141 137 142 138 // allow only real-valued expressions as child of the start symbol 143 139 foreach (var symb in realValuedSymbols) { 144 SetAllowedChild(StartSymbol, symb, 0);140 AddAllowedChildSymbol(StartSymbol, symb); 145 141 } 146 142 147 143 foreach (var symb in unaryFunctionSymbols) { 148 144 foreach (var childSymb in realValuedSymbols) { 149 SetAllowedChild(symb, childSymb, 0);145 AddAllowedChildSymbol(symb, childSymb); 150 146 } 151 147 } … … 153 149 foreach (var symb in binaryFunctionSymbols) { 154 150 foreach (var childSymb in realValuedSymbols) { 155 SetAllowedChild(symb, childSymb, 0); 156 SetAllowedChild(symb, childSymb, 1); 151 AddAllowedChildSymbol(symb, childSymb); 157 152 } 158 153 } 159 154 160 155 foreach (var childSymb in booleanSymbols) { 161 SetAllowedChild(@if, childSymb, 0);156 AddAllowedChildSymbol(@if, childSymb, 0); 162 157 } 163 158 foreach (var childSymb in realValuedSymbols) { 164 SetAllowedChild(@if, childSymb, 1);165 SetAllowedChild(@if, childSymb, 2);159 AddAllowedChildSymbol(@if, childSymb, 1); 160 AddAllowedChildSymbol(@if, childSymb, 2); 166 161 } 167 162 168 163 foreach (var symb in relationalFunctionSymbols) { 169 164 foreach (var childSymb in realValuedSymbols) { 170 SetAllowedChild(symb, childSymb, 0); 171 SetAllowedChild(symb, childSymb, 1); 165 AddAllowedChildSymbol(symb, childSymb); 172 166 } 173 167 } 174 168 foreach (var symb in binaryBooleanFunctionSymbols) { 175 169 foreach (var childSymb in booleanSymbols) { 176 SetAllowedChild(symb, childSymb, 0); 177 SetAllowedChild(symb, childSymb, 1); 170 AddAllowedChildSymbol(symb, childSymb); 178 171 } 179 172 } 180 173 foreach (var symb in unaryBooleanFunctionSymbols) { 181 174 foreach (var childSymb in booleanSymbols) { 182 SetAllowedChild(symb, childSymb, 0);175 AddAllowedChildSymbol(symb, childSymb); 183 176 } 184 177 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisGrammar.cs
r5514 r5686 23 23 24 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 25 public interface ISymbolicDataAnalysisGrammar : ISymbolicExpression TreeGrammar {25 public interface ISymbolicDataAnalysisGrammar : ISymbolicExpressionGrammar { 26 26 } 27 27 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r5574 r5686 25 25 using System.Linq; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Problems.DataAnalysis.Symbolic;28 27 using HeuristicLab.Random; 29 28 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 59 58 var twister = new MersenneTwister(31415); 60 59 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); 61 var grammar = new GlobalSymbolicExpressionGrammar(new FullFunctionalExpressionGrammar());62 grammar.Max FunctionArguments = 0;63 grammar.Max FunctionDefinitions = 0;64 grammar.Min FunctionArguments = 0;65 grammar.Min FunctionDefinitions = 0;60 var grammar = new FullFunctionalExpressionGrammar(); 61 grammar.MaximumFunctionArguments = 0; 62 grammar.MaximumFunctionDefinitions = 0; 63 grammar.MinimumFunctionArguments = 0; 64 grammar.MinimumFunctionDefinitions = 0; 66 65 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); 67 66 double[] estimation = new double[Rows]; … … 78 77 var twister = new MersenneTwister(31415); 79 78 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); 80 var grammar = new GlobalSymbolicExpressionGrammar(new ArithmeticExpressionGrammar());81 grammar.Max FunctionArguments = 0;82 grammar.Max FunctionDefinitions = 0;83 grammar.Min FunctionArguments = 0;84 grammar.Min FunctionDefinitions = 0;79 var grammar = new ArithmeticExpressionGrammar(); 80 grammar.MaximumFunctionArguments = 0; 81 grammar.MaximumFunctionDefinitions = 0; 82 grammar.MinimumFunctionArguments = 0; 83 grammar.MinimumFunctionDefinitions = 0; 85 84 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); 86 85 double[] estimation = new double[Rows]; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/Util.cs
r5624 r5686 45 45 46 46 47 public static ISymbolicExpressionTree[] CreateRandomTrees(MersenneTwister twister, Dataset dataset, ISymbolicExpression TreeGrammar grammar, int popSize) {47 public static ISymbolicExpressionTree[] CreateRandomTrees(MersenneTwister twister, Dataset dataset, ISymbolicExpressionGrammar grammar, int popSize) { 48 48 return CreateRandomTrees(twister, dataset, grammar, popSize, 1, 200, 3, 3); 49 49 } 50 50 51 public static ISymbolicExpressionTree[] CreateRandomTrees(MersenneTwister twister, Dataset dataset, ISymbolicExpression TreeGrammar grammar,51 public static ISymbolicExpressionTree[] CreateRandomTrees(MersenneTwister twister, Dataset dataset, ISymbolicExpressionGrammar grammar, 52 52 int popSize, int minSize, int maxSize, 53 53 int maxFunctionDefinitions, int maxFunctionArguments) { … … 57 57 ISymbolicExpressionTree[] randomTrees = new ISymbolicExpressionTree[popSize]; 58 58 for (int i = 0; i < randomTrees.Length; i++) { 59 randomTrees[i] = ProbabilisticTreeCreator.Create(twister, grammar, maxSize, 10 , maxFunctionDefinitions, maxFunctionArguments);59 randomTrees[i] = ProbabilisticTreeCreator.Create(twister, grammar, maxSize, 10); 60 60 } 61 61 return randomTrees;
Note: See TracChangeset
for help on using the changeset viewer.