- Timestamp:
- 09/16/11 11:15:41 (13 years ago)
- Location:
- branches/GP.Grammar.Editor
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs
r6626 r6782 66 66 symbolsTreeView.Nodes.Clear(); 67 67 UpdateSymbolsTreeView(); 68 symbolsTreeView.ExpandAll(); 68 69 symbolsTreeView.CollapseAll(); 70 foreach (var node in IterateTreeNodes()) 71 if (node.Checked) node.Expand(); 72 69 73 allowedChildSymbolsControl.Grammar = Content; 70 74 allowedChildSymbolsControl.Symbol = null; -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs
r6626 r6782 270 270 271 271 private void Symbol_Changed(object sender, EventArgs e) { 272 if (suppressEvents) return;273 272 ClearCaches(); 274 273 OnChanged(); … … 276 275 277 276 private void GroupSymbol_Changed(object sender, EventArgs e) { 278 if (suppressEvents) return;279 suppressEvents = true;280 277 GroupSymbol groupSymbol = (GroupSymbol)sender; 281 278 foreach (ISymbol symbol in groupSymbol.Flatten()) 282 279 symbol.Enabled = groupSymbol.Enabled; 283 suppressEvents = false; 280 284 281 ClearCaches(); 285 282 OnChanged(); … … 330 327 331 328 private void GroupSymbol_ItemsAdded(object sender, CollectionItemsChangedEventArgs<ISymbol> e) { 332 suppressEvents = true;333 329 foreach (ISymbol symbol in e.Items) 334 330 if (!ContainsSymbol(symbol)) 335 331 AddSymbol(symbol); 336 suppressEvents = false;337 332 OnChanged(); 338 333 } 339 334 private void GroupSymbol_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<ISymbol> e) { 340 suppressEvents = true;341 335 foreach (ISymbol symbol in e.Items) 342 336 if (ContainsSymbol(symbol)) 343 337 RemoveSymbol(symbol); 344 suppressEvents = false;345 338 OnChanged(); 346 339 } 347 340 private void GroupSymbol_CollectionReset(object sender, CollectionItemsChangedEventArgs<ISymbol> e) { 348 suppressEvents = true;349 341 foreach (ISymbol symbol in e.Items) 350 342 if (!ContainsSymbol(symbol)) … … 353 345 if (ContainsSymbol(symbol)) 354 346 RemoveSymbol(symbol); 355 suppressEvents = false;356 347 OnChanged(); 357 348 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/GroupSymbol.cs
r6493 r6782 49 49 } 50 50 51 public override bool Enabled {52 get { return base.Enabled; }53 set { base.Enabled = value; }54 }55 56 51 [StorableConstructor] 57 52 private GroupSymbol(bool deserializing) : base(deserializing) { } -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs
r5854 r6782 62 62 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 63 63 64 var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar; 65 if (grammar != null) grammar.ConfigureAsDefaultClassificationGrammar(); 66 64 67 InitializeOperators(); 65 68 UpdateEstimationLimits(); -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r5854 r6782 60 60 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 61 61 62 var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar; 63 if(grammar != null) grammar.ConfigureAsDefaultClassificationGrammar(); 64 62 65 InitializeOperators(); 63 66 UpdateEstimationLimits(); -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs
r5854 r6782 66 66 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 67 67 68 var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar; 69 if (grammar != null) grammar.ConfigureAsDefaultRegressionGrammar(); 70 68 71 InitializeOperators(); 69 72 UpdateEstimationLimits(); -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r5854 r6782 62 62 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 63 63 64 var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar; 65 if (grammar != null) grammar.ConfigureAsDefaultRegressionGrammar(); 66 64 67 InitializeOperators(); 65 68 UpdateEstimationLimits(); -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r6337 r6782 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 29 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.")] 30 31 public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 private const string ArithmeticFunctionsName = "Arithmetic Functions"; 33 private const string TrigonometricFunctionsName = "Trigonometric Functions"; 34 private const string ExponentialFunctionsName = "Exponential and Logarithmic Functions"; 35 private const string RealValuedSymbolsName = "Real Valued Symbols"; 36 private const string TerminalsName = "Terminals"; 37 private const string PowerFunctionsName = "Power Functions"; 38 private const string ConditionsName = "Conditions"; 39 private const string ComparisonsName = "Comparisons"; 40 private const string BooleanOperatorsName = "Boolean Operators"; 41 private const string ConditionalSymbolsName = "ConditionalSymbols"; 42 private const string TimeSeriesSymbolsName = "Time Series Symbols"; 31 43 32 44 [StorableConstructor] … … 42 54 43 55 private void Initialize() { 56 #region symbol declaration 44 57 var add = new Addition(); 45 58 var sub = new Subtraction(); … … 52 65 var log = new Logarithm(); 53 66 var pow = new Power(); 54 pow.InitialFrequency = 0.0;55 67 var root = new Root(); 56 root.InitialFrequency = 0.0;57 68 var exp = new Exponential(); 58 69 var @if = new IfThenElse(); … … 62 73 var or = new Or(); 63 74 var not = new Not(); 75 var variableCondition = new VariableCondition(); 64 76 65 77 var timeLag = new TimeLag(); 66 timeLag.InitialFrequency = 0.0;67 78 var integral = new Integral(); 68 integral.InitialFrequency = 0.0;69 79 var derivative = new Derivative(); 70 derivative.InitialFrequency = 0.0;71 var variableCondition = new VariableCondition();72 variableCondition.InitialFrequency = 0.0;73 80 74 81 var constant = new Constant(); 75 82 constant.MinValue = -20; 76 83 constant.MaxValue = 20; 77 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();84 var variableSymbol = new Variable(); 78 85 var laggedVariable = new LaggedVariable(); 86 #endregion 79 87 80 laggedVariable.InitialFrequency = 0.0; 81 mean.InitialFrequency = 0.0; 88 #region group symbol declaration 89 var arithmeticSymbols = new GroupSymbol(ArithmeticFunctionsName, new List<ISymbol>() { add, sub, mul, div, mean }); 90 var trigonometricSymbols = new GroupSymbol(TrigonometricFunctionsName, new List<ISymbol>() { sin, cos, tan }); 91 var exponentialAndLogarithmicSymbols = new GroupSymbol(ExponentialFunctionsName, new List<ISymbol> { exp, log }); 92 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol }); 93 var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, terminalSymbols }); 82 94 83 /* 84 * Start = RealValueExpression 85 * 86 * RealValueExpression = 87 * "Variable" | 88 * "Constant" | 89 * BinaryOperator RealValueExpression RealValueExpression | 90 * UnaryOperator RealValueExpression | 91 * "IF" BooleanExpression RealValueExpression RealValueExpression | 92 * "VariableCondition" RealValueExpression RealValueExpression 93 * 94 * BinaryOperator = 95 * "+" | "-" | "*" | "/" | "Power" | "Root" 96 * 97 * UnaryOperator = 98 * "Sin" | "Cos" | "Tan" | "Log" | "Exp" 99 * 100 * BooleanExpression = 101 * "AND" BooleanExpression BooleanExpression | 102 * "OR" BooleanExpression BooleanExpression | 103 * "NOT" BooleanExpression | 104 * ">" RealValueExpression RealValueExpression | 105 * "<" RealValueExpression RealValueExpression 106 */ 95 var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { pow, root }); 107 96 108 var arithmeticSymbols = new GroupSymbol("Arithmetic Functions", new List<ISymbol>() { add, sub, mul, div});109 var trigonometricSymbols = new GroupSymbol("Trigonometric Functions", new List<ISymbol>() { sin, cos, tan});110 var powerSymbols = new GroupSymbol("Power Functions", new List<ISymbol> { pow, root });111 var exponentialAndLogarithmicSymbols = new GroupSymbol("Exponential and Logarithmic Functions", new List<ISymbol> { exp, log});112 var terminalSymbols = new GroupSymbol("Terminals", new List<ISymbol> { constant, variableSymbol }); 113 var realValuedSymbols = new GroupSymbol("Real valued Symbols",114 new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, powerSymbols, exponentialAndLogarithmicSymbols, terminalSymbols });97 var conditionSymbols = new GroupSymbol(ConditionsName, new List<ISymbol> { @if, variableCondition }); 98 var comparisonSymbols = new GroupSymbol(ComparisonsName, new List<ISymbol> { gt, lt }); 99 var booleanOperationSymbols = new GroupSymbol(BooleanOperatorsName, new List<ISymbol> { and, or, not }); 100 var conditionalSymbols = new GroupSymbol(ConditionalSymbolsName, new List<ISymbol> { conditionSymbols, comparisonSymbols, booleanOperationSymbols }); 101 102 var timeSeriesSymbols = new GroupSymbol(TimeSeriesSymbolsName, new List<ISymbol> { timeLag, integral, derivative, laggedVariable }); 103 #endregion 115 104 116 105 AddSymbol(realValuedSymbols); 106 AddSymbol(powerSymbols); 107 AddSymbol(conditionalSymbols); 108 AddSymbol(timeSeriesSymbols); 117 109 110 #region subtree count configuration 118 111 SetSubtreeCount(arithmeticSymbols, 2, 2); 119 112 SetSubtreeCount(trigonometricSymbols, 1, 1); … … 122 115 SetSubtreeCount(terminalSymbols, 0, 0); 123 116 117 SetSubtreeCount(@if, 3, 3); 118 SetSubtreeCount(variableCondition, 2, 2); 119 SetSubtreeCount(comparisonSymbols, 2, 2); 120 SetSubtreeCount(and, 2, 2); 121 SetSubtreeCount(or, 2, 2); 122 SetSubtreeCount(not, 1, 1); 123 124 SetSubtreeCount(timeLag, 1, 1); 125 SetSubtreeCount(integral, 1, 1); 126 SetSubtreeCount(derivative, 1, 1); 127 SetSubtreeCount(laggedVariable, 0, 0); 128 #endregion 129 130 #region alloed child symbols configuration 124 131 AddAllowedChildSymbol(StartSymbol, realValuedSymbols); 125 132 AddAllowedChildSymbol(DefunSymbol, realValuedSymbols); 133 126 134 AddAllowedChildSymbol(realValuedSymbols, realValuedSymbols); 135 AddAllowedChildSymbol(realValuedSymbols, powerSymbols); 136 AddAllowedChildSymbol(realValuedSymbols, conditionSymbols); 137 AddAllowedChildSymbol(realValuedSymbols, timeSeriesSymbols); 127 138 128 //var unaryBooleanFunctionSymbols = new List<Symbol>() { not }; 129 //var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and }; 130 //var relationalFunctionSymbols = new List<Symbol>() { gt, lt }; 131 //var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols); 139 AddAllowedChildSymbol(powerSymbols, variableSymbol, 0); 140 AddAllowedChildSymbol(powerSymbols, constant, 1); 132 141 133 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, pow, root, exp, @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable, variableCondition }; 142 AddAllowedChildSymbol(@if, comparisonSymbols, 0); 143 AddAllowedChildSymbol(@if, booleanOperationSymbols, 0); 144 AddAllowedChildSymbol(@if, conditionSymbols, 1); 145 AddAllowedChildSymbol(@if, realValuedSymbols, 1); 146 AddAllowedChildSymbol(@if, powerSymbols, 1); 147 AddAllowedChildSymbol(@if, timeSeriesSymbols, 1); 148 AddAllowedChildSymbol(@if, conditionSymbols, 2); 149 AddAllowedChildSymbol(@if, realValuedSymbols, 2); 150 AddAllowedChildSymbol(@if, powerSymbols, 2); 151 AddAllowedChildSymbol(@if, timeSeriesSymbols, 2); 134 152 135 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, timeLag, integral, derivative }; 136 var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition }; 153 AddAllowedChildSymbol(booleanOperationSymbols, comparisonSymbols); 154 AddAllowedChildSymbol(comparisonSymbols, realValuedSymbols); 155 AddAllowedChildSymbol(comparisonSymbols, powerSymbols); 156 AddAllowedChildSymbol(comparisonSymbols, conditionSymbols); 157 AddAllowedChildSymbol(comparisonSymbols, timeSeriesSymbols); 158 159 AddAllowedChildSymbol(variableCondition, realValuedSymbols); 160 AddAllowedChildSymbol(variableCondition, powerSymbols); 161 AddAllowedChildSymbol(variableCondition, conditionSymbols); 162 AddAllowedChildSymbol(variableCondition, timeSeriesSymbols); 137 163 138 164 165 AddAllowedChildSymbol(timeLag, realValuedSymbols); 166 AddAllowedChildSymbol(timeLag, powerSymbols); 167 AddAllowedChildSymbol(timeLag, conditionSymbols); 139 168 140 //var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable }; 141 //var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if }); 169 AddAllowedChildSymbol(integral, realValuedSymbols); 170 AddAllowedChildSymbol(integral, powerSymbols); 171 AddAllowedChildSymbol(integral, conditionSymbols); 142 172 173 AddAllowedChildSymbol(derivative, realValuedSymbols); 174 AddAllowedChildSymbol(derivative, powerSymbols); 175 AddAllowedChildSymbol(derivative, conditionSymbols); 176 #endregion 177 } 143 178 144 //foreach (var symb in allSymbols) 145 // AddSymbol(symb); 179 public void ConfigureAsDefaultRegressionGrammar() { 180 Symbols.Where(s => s is Average).First().Enabled = false; 181 Symbols.Where(s => s.Name == TrigonometricFunctionsName).First().Enabled = false; 182 Symbols.Where(s => s.Name == PowerFunctionsName).First().Enabled = false; 183 Symbols.Where(s => s.Name == ConditionalSymbolsName).First().Enabled = false; 184 Symbols.Where(s => s.Name == TimeSeriesSymbolsName).First().Enabled = false; 185 } 146 186 147 //foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) { 148 // SetSubtreeCount(unaryFun, 1, 1); 149 //} 150 //foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) { 151 // SetSubtreeCount(binaryFun, 2, 2); 152 //} 153 154 //foreach (var terminalSymbol in terminalSymbols) { 155 // SetSubtreeCount(terminalSymbol, 0, 0); 156 //} 157 158 //SetSubtreeCount(@if, 3, 3); 159 160 161 // allow only real-valued expressions as child of the start symbol 162 //foreach (var symb in realValuedSymbols) { 163 // AddAllowedChildSymbol(StartSymbol, symb); 164 // AddAllowedChildSymbol(DefunSymbol, symb); 165 //} 166 167 //foreach (var symb in unaryFunctionSymbols) { 168 // foreach (var childSymb in realValuedSymbols) { 169 // AddAllowedChildSymbol(symb, childSymb); 170 // } 171 //} 172 173 //foreach (var symb in binaryFunctionSymbols) { 174 // foreach (var childSymb in realValuedSymbols) { 175 // AddAllowedChildSymbol(symb, childSymb); 176 // } 177 //} 178 179 //foreach (var childSymb in booleanSymbols) { 180 // AddAllowedChildSymbol(@if, childSymb, 0); 181 //} 182 //foreach (var childSymb in realValuedSymbols) { 183 // AddAllowedChildSymbol(@if, childSymb, 1); 184 // AddAllowedChildSymbol(@if, childSymb, 2); 185 //} 186 187 //foreach (var symb in relationalFunctionSymbols) { 188 // foreach (var childSymb in realValuedSymbols) { 189 // AddAllowedChildSymbol(symb, childSymb); 190 // } 191 //} 192 //foreach (var symb in binaryBooleanFunctionSymbols) { 193 // foreach (var childSymb in booleanSymbols) { 194 // AddAllowedChildSymbol(symb, childSymb); 195 // } 196 //} 197 //foreach (var symb in unaryBooleanFunctionSymbols) { 198 // foreach (var childSymb in booleanSymbols) { 199 // AddAllowedChildSymbol(symb, childSymb); 200 // } 201 //} 187 public void ConfigureAsDefaultClassificationGrammar() { 188 Symbols.Where(s => s is Average).First().Enabled = false; 189 Symbols.Where(s => s.Name == TrigonometricFunctionsName).First().Enabled = false; 190 Symbols.Where(s => s.Name == ExponentialFunctionsName).First().Enabled = false; 191 Symbols.Where(s => s.Name == PowerFunctionsName).First().Enabled = false; 192 Symbols.Where(s => s.Name == TimeSeriesSymbolsName).First().Enabled = false; 202 193 } 203 194 }
Note: See TracChangeset
for help on using the changeset viewer.