Changeset 6284
- Timestamp:
- 05/25/11 10:50:21 (14 years ago)
- Location:
- branches/GP.Grammar.Editor
- Files:
-
- 13 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj
r5809 r6284 93 93 </PropertyGroup> 94 94 <ItemGroup> 95 <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 96 <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 97 <Reference Include="HeuristicLab.Data.Views-3.3"> 98 <HintPath>..\..\HeuristicLab.Data.Views\3.3\bin\Debug\HeuristicLab.Data.Views-3.3.dll</HintPath> 99 </Reference> 100 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 101 <Reference Include="HeuristicLab.Visualization.ChartControlsExtensions-3.3"> 102 <HintPath>..\..\HeuristicLab.Visualization.ChartControlsExtensions\3.3\bin\Debug\HeuristicLab.Visualization.ChartControlsExtensions-3.3.dll</HintPath> 103 </Reference> 95 104 <Reference Include="System" /> 96 105 <Reference Include="System.Core"> … … 99 108 <Reference Include="System.Drawing" /> 100 109 <Reference Include="System.Windows.Forms" /> 110 <Reference Include="System.Windows.Forms.DataVisualization" /> 101 111 <Reference Include="System.Xml.Linq"> 102 112 <RequiredTargetFramework>3.5</RequiredTargetFramework> … … 109 119 </ItemGroup> 110 120 <ItemGroup> 121 <Compile Include="SymbolicExpressionGrammarEditorView.cs"> 122 <SubType>UserControl</SubType> 123 </Compile> 124 <Compile Include="SymbolicExpressionGrammarEditorView.Designer.cs"> 125 <DependentUpon>SymbolicExpressionGrammarEditorView.cs</DependentUpon> 126 </Compile> 111 127 <Compile Include="SymbolicExpressionGrammarView.cs"> 112 128 <SubType>UserControl</SubType> … … 171 187 <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project> 172 188 <Name>HeuristicLab.MainForm-3.3</Name> 189 </ProjectReference> 190 <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj"> 191 <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project> 192 <Name>HeuristicLab.Optimization.Views-3.3</Name> 173 193 </ProjectReference> 174 194 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> … … 198 218 <Install>true</Install> 199 219 </BootstrapperPackage> 220 </ItemGroup> 221 <ItemGroup> 222 <EmbeddedResource Include="SymbolicExpressionGrammarEditorView.resx"> 223 <DependentUpon>SymbolicExpressionGrammarEditorView.cs</DependentUpon> 224 </EmbeddedResource> 200 225 </ItemGroup> 201 226 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r6233 r6284 179 179 ReplaceWithMinimalTree(random, root, parent, argumentIndex); 180 180 } else { 181 var allowedSymbols = (from s in parent.Grammar. Symbols181 var allowedSymbols = (from s in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, argumentIndex) 182 182 where s.InitialFrequency > 0.0 183 where parent.Grammar.IsAllowedChildSymbol(parent.Symbol, s, argumentIndex) 184 where parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1 185 where parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength 183 where s.Fixed || parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1 184 where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength 186 185 select s) 187 186 .ToList(); -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r5916 r6284 96 96 int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0.Parent); 97 97 98 99 98 List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>(); 100 99 parent1.Root.ForEachNodePostfix((n) => { 101 if (n.GetLength() <= maxInsertedBranchLength && 102 n.GetDepth() <= maxInsertedBranchDepth && 103 IsMatchingPointType(crossoverPoint0, n)) 100 if (!n.Symbol.Fixed && 101 n.GetLength() <= maxInsertedBranchLength && 102 n.GetDepth() <= maxInsertedBranchDepth && 103 IsMatchingPointType(crossoverPoint0, n)) 104 104 allowedBranches.Add(n); 105 105 }); … … 158 158 List<CutPoint> leafCrossoverPoints = new List<CutPoint>(); 159 159 parent0.Root.ForEachNodePostfix((n) => { 160 if ( n.Subtrees.Any() && n != parent0.Root) {160 if (!n.Symbol.Fixed && n.Subtrees.Any() && n != parent0.Root) { 161 161 foreach (var child in n.Subtrees) { 162 162 if (child.GetLength() <= maxBranchLength && -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r5809 r6284 167 167 <Compile Include="Symbols\Argument.cs" /> 168 168 <Compile Include="Symbols\ArgumentTreeNode.cs" /> 169 <Compile Include="Symbols\GroupSymbol.cs" /> 169 170 <Compile Include="Symbols\StartSymbol.cs" /> 170 171 <Compile Include="Symbols\InvokeFunction.cs" /> -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbol.cs
r5809 r6284 27 27 ISymbolicExpressionTreeNode CreateTreeNode(); 28 28 double InitialFrequency { get; set; } 29 bool Fixed { get; set; } 29 30 30 31 event EventHandler Changed; -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs
r6233 r6284 35 35 bool ReadOnly { get; set; } 36 36 event EventHandler ReadOnlyChanged; 37 38 void AddSymbol(ISymbol symbol); 39 void RemoveSymbol(ISymbol symbol); 40 41 void AddAllowedChildSymbol(ISymbol parent, ISymbol child); 42 void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex); 43 void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child); 44 void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex); 45 46 void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount); 37 47 } 38 48 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammarBase.cs
r5809 r6284 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Core; … … 41 42 int GetMaximumExpressionLength(ISymbol start); 42 43 int GetMinimumExpressionDepth(ISymbol start); 44 45 event EventHandler Changed; 43 46 } 44 47 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs
r6233 r6284 160 160 } 161 161 162 #region IStatefulItem 162 #region IStatefulItem methods 163 163 void IStatefulItem.InitializeState() { } 164 164 void IStatefulItem.ClearState() { … … 166 166 } 167 167 #endregion 168 169 #region ISymbolicExpressionGrammar methods 170 void ISymbolicExpressionGrammar.AddSymbol(ISymbol symbol) { 171 if (ReadOnly) throw new InvalidOperationException(); 172 base.AddSymbol(symbol); 173 } 174 void ISymbolicExpressionGrammar.RemoveSymbol(ISymbol symbol) { 175 if (ReadOnly) throw new InvalidOperationException(); 176 base.RemoveSymbol(symbol); 177 } 178 179 void ISymbolicExpressionGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child) { 180 if (ReadOnly) throw new InvalidOperationException(); 181 base.AddAllowedChildSymbol(parent, child); 182 } 183 void ISymbolicExpressionGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) { 184 if (ReadOnly) throw new InvalidOperationException(); 185 base.AddAllowedChildSymbol(parent, child, argumentIndex); 186 } 187 void ISymbolicExpressionGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) { 188 if (ReadOnly) throw new InvalidOperationException(); 189 base.RemoveAllowedChildSymbol(parent, child); 190 } 191 void ISymbolicExpressionGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) { 192 if (ReadOnly) throw new InvalidOperationException(); 193 base.RemoveAllowedChildSymbol(parent, child, argumentIndex); 194 } 195 196 void ISymbolicExpressionGrammar.SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) { 197 if (ReadOnly) throw new InvalidOperationException(); 198 base.SetSubtreeCount(symbol, minimumSubtreeCount, maximumSubtreeCount); 199 } 200 #endregion 168 201 } 169 202 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r6233 r6284 93 93 cachedMinExpressionDepth = new Dictionary<string, int>(); 94 94 95 96 95 symbols = original.symbols.ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value)); 97 96 symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>(original.symbolSubtreeCount); … … 128 127 symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0)); 129 128 ClearCaches(); 129 OnChanged(); 130 130 } 131 131 … … 133 133 symbol.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging); 134 134 symbol.NameChanged += new EventHandler(Symbol_NameChanged); 135 symbol.Changed += new EventHandler(Symbol_Changed); 135 136 } 136 137 private void DeregisterSymbolEvents(ISymbol symbol) { 137 138 symbol.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging); 138 139 symbol.NameChanged -= new EventHandler(Symbol_NameChanged); 140 symbol.Changed -= new EventHandler(Symbol_Changed); 139 141 } 140 142 … … 179 181 180 182 ClearCaches(); 183 OnChanged(); 184 } 185 186 private void Symbol_Changed(object sende, EventArgs e) { 187 ClearCaches(); 188 OnChanged(); 181 189 } 182 190 … … 200 208 DeregisterSymbolEvents(symbol); 201 209 ClearCaches(); 210 OnChanged(); 202 211 } 203 212 … … 217 226 childSymbols.Add(child.Name); 218 227 ClearCaches(); 228 OnChanged(); 219 229 } 220 230 … … 231 241 childSymbols.Add(child.Name); 232 242 ClearCaches(); 243 OnChanged(); 233 244 } 234 245 … … 236 247 List<string> childSymbols; 237 248 if (allowedChildSymbols.TryGetValue(child.Name, out childSymbols)) { 238 if (allowedChildSymbols[parent.Name].Remove(child.Name)) 249 if (allowedChildSymbols[parent.Name].Remove(child.Name)) { 239 250 ClearCaches(); 251 OnChanged(); 252 } 240 253 } 241 254 } … … 245 258 List<string> childSymbols; 246 259 if (allowedChildSymbolsPerIndex.TryGetValue(key, out childSymbols)) { 247 if (allowedChildSymbolsPerIndex[key].Remove(child.Name)) 260 if (allowedChildSymbolsPerIndex[key].Remove(child.Name)) { 248 261 ClearCaches(); 262 OnChanged(); 263 } 249 264 } 250 265 } … … 258 273 symbolSubtreeCount[symbol.Name] = Tuple.Create(minimumSubtreeCount, maximumSubtreeCount); 259 274 ClearCaches(); 275 OnChanged(); 260 276 } 261 277 #endregion … … 304 320 result = result.Union(temp); 305 321 306 return result.Select(x => GetSymbol(x)) ;322 return result.Select(x => GetSymbol(x)).Where(s => !s.InitialFrequency.IsAlmost(0.0)); 307 323 } 308 324 … … 313 329 return symbolSubtreeCount[symbol.Name].Item2; 314 330 } 315 316 331 317 332 private void ClearCaches() { … … 369 384 return temp; 370 385 } 386 387 public event EventHandler Changed; 388 protected virtual void OnChanged() { 389 var handler = Changed; 390 if (handler != null) Changed(this, EventArgs.Empty); 391 } 371 392 #endregion 372 393 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Symbol.cs
r6233 r6284 42 42 } 43 43 } 44 45 [Storable(DefaultValue = false)] 46 private bool @fixed; 47 public bool Fixed { 48 get { return @fixed; } 49 set { 50 if (value != @fixed) { 51 @fixed = value; 52 OnChanged(EventArgs.Empty); 53 } 54 } 55 } 56 44 57 public override bool CanChangeName { 45 58 get { return !(this is IReadOnlySymbol); } … … 55 68 : base(original, cloner) { 56 69 initialFrequency = original.initialFrequency; 70 @fixed = original.@fixed; 57 71 } 58 72 … … 60 74 : base(name, description) { 61 75 initialFrequency = 1.0; 76 @fixed = false; 62 77 } 63 78 … … 68 83 #region events 69 84 public event EventHandler Changed; 70 protected v oid OnChanged(EventArgs e) {85 protected virtual void OnChanged(EventArgs e) { 71 86 EventHandler handlers = Changed; 72 87 if (handlers != null) -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/MwDruGrammar.cs
r6179 r6284 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 28 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 30 [StorableClass] 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 : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {31 [Item("MwDruGrammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")] 32 public class MwDruGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 33 33 34 [StorableConstructor] 34 protected TypeCoherentExpressionGrammar(bool deserializing) : base(deserializing) { }35 protected TypeCoherentExpressionGrammar(TypeCoherentExpressionGrammar original, Cloner cloner) : base(original, cloner) { }36 public TypeCoherentExpressionGrammar()37 : base(ItemAttribute.GetName(typeof( TypeCoherentExpressionGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {35 protected MwDruGrammar(bool deserializing) : base(deserializing) { } 36 protected MwDruGrammar(MwDruGrammar original, Cloner cloner) : base(original, cloner) { } 37 public MwDruGrammar() 38 : base(ItemAttribute.GetName(typeof(MwDruGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) { 38 39 Initialize(); 39 40 } 40 41 public override IDeepCloneable Clone(Cloner cloner) { 41 return new TypeCoherentExpressionGrammar(this, cloner);42 return new MwDruGrammar(this, cloner); 42 43 } 44 45 private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable ggDru; 46 private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable flamTmp; 43 47 44 48 private void Initialize() { … … 47 51 var mul = new Multiplication(); 48 52 var div = new Division(); 49 var mean = new Average();50 var sin = new Sine();51 var cos = new Cosine();52 var tan = new Tangent();53 53 var log = new Logarithm(); 54 var pow = new Power();55 pow.InitialFrequency = 0.0;56 var root = new Root();57 root.InitialFrequency = 0.0;58 54 var exp = new Exponential(); 59 var @if = new IfThenElse();60 var gt = new GreaterThan();61 var lt = new LessThan();62 var and = new And();63 var or = new Or();64 var not = new Not();65 66 var timeLag = new TimeLag();67 timeLag.InitialFrequency = 0.0;68 var integral = new Integral();69 integral.InitialFrequency = 0.0;70 var derivative = new Derivative();71 derivative.InitialFrequency = 0.0;72 var variableCondition = new VariableCondition();73 variableCondition.InitialFrequency = 0.0;74 55 75 56 var constant = new Constant(); … … 77 58 constant.MaxValue = 20; 78 59 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 79 var laggedVariable = new LaggedVariable();80 60 81 laggedVariable.InitialFrequency = 0.0; 82 mean.InitialFrequency = 0.0; 61 var fixedAdd1 = new Addition(); 62 fixedAdd1.Name = "fixed Addition 1"; 63 fixedAdd1.Fixed = true; 83 64 84 /* 85 * Start = RealValueExpression 86 * 87 * RealValueExpression = 88 * "Variable" | 89 * "Constant" | 90 * BinaryOperator RealValueExpression RealValueExpression | 91 * UnaryOperator RealValueExpression | 92 * "IF" BooleanExpression RealValueExpression RealValueExpression | 93 * "VariableCondition" RealValueExpression RealValueExpression 94 * 95 * BinaryOperator = 96 * "+" | "-" | "*" | "/" | "Power" 97 * 98 * UnaryOperator = 99 * "Sin" | "Cos" | "Tan" | "Log" | "Exp" 100 * 101 * BooleanExpression = 102 * "AND" BooleanExpression BooleanExpression | 103 * "OR" BooleanExpression BooleanExpression | 104 * "NOT" BooleanExpression | 105 * ">" RealValueExpression RealValueExpression | 106 * "<" RealValueExpression RealValueExpression 107 */ 65 var fixedAdd2 = new Addition(); 66 fixedAdd2.Name = "fixed Addition 2"; 67 fixedAdd2.Fixed = true; 108 68 109 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 }; 69 var fixedMul = new Multiplication(); 70 fixedMul.Name = "fixed Multiplication"; 71 fixedMul.Fixed = true; 110 72 111 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, timeLag, integral, derivative }; 112 var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition }; 73 ggDru = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 74 ggDru.Name = "fixed Variable GGDru"; 75 ggDru.Fixed = true; 76 ggDru.VariableNames = new List<string>() { "GGDRU" }; 77 ggDru.WeightManipulatorMu = 1; 78 ggDru.WeightManipulatorSigma = 0; 79 ggDru.WeightMu = 1; 80 ggDru.WeightSigma = 0; 81 ggDru.MultiplicativeWeightManipulatorSigma = 0; 82 ggDru.Changed += new EventHandler(ggDru_Changed); 113 83 114 var unaryBooleanFunctionSymbols = new List<Symbol>() { not }; 115 var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and }; 116 var relationalFunctionSymbols = new List<Symbol>() { gt, lt }; 117 var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable }; 118 var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if }); 119 var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols); 84 flamTmp = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 85 flamTmp.Name = "fixed Variable FlamTmp"; 86 flamTmp.Fixed = true; 87 flamTmp.VariableNames = new List<string>() { "FLAMTMP" }; 88 flamTmp.WeightManipulatorMu = 1; 89 flamTmp.WeightManipulatorSigma = 0; 90 flamTmp.WeightMu = 1; 91 flamTmp.WeightSigma = 0; 92 flamTmp.MultiplicativeWeightManipulatorSigma = 0; 93 flamTmp.Changed += new EventHandler(flamTmp_Changed); 94 95 var c273 = new Constant(); 96 c273.Name = "fixed Constant 273"; 97 c273.Fixed = true; 98 c273.MinValue = 273; 99 c273.MaxValue = 273; 100 c273.ManipulatorMu = 0; 101 c273.ManipulatorSigma = 0; 102 c273.MultiplicativeManipulatorSigma = 0; 103 104 var allSymbols = new List<Symbol>() 105 { add, sub, mul, div, log, exp, constant, variableSymbol, 106 fixedAdd1,fixedAdd2,fixedMul,ggDru,flamTmp,c273}; 107 108 var unaryFunctionSymbols = new List<Symbol>() { log, exp }; 109 var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div }; 110 111 var terminalSymbols = new List<Symbol>() { variableSymbol, constant }; 112 var fixedTerminalSymbols = new List<Symbol>() { ggDru, flamTmp, c273 }; 113 var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols); 120 114 121 115 foreach (var symb in allSymbols) 122 116 AddSymbol(symb); 123 124 foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) { 117 foreach (var terminalSymbol in terminalSymbols) { 118 SetSubtreeCount(terminalSymbol, 0, 0); 119 } 120 foreach (var terminalSymbol in fixedTerminalSymbols) { 121 SetSubtreeCount(terminalSymbol, 0, 0); 122 } 123 foreach (var unaryFun in unaryFunctionSymbols) { 125 124 SetSubtreeCount(unaryFun, 1, 1); 126 125 } 127 foreach (var binaryFun in binaryFunctionSymbols .Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {126 foreach (var binaryFun in binaryFunctionSymbols) { 128 127 SetSubtreeCount(binaryFun, 2, 2); 129 128 } 130 129 131 foreach (var terminalSymbol in terminalSymbols) {132 SetSubtreeCount(terminalSymbol, 0, 0);133 }130 SetSubtreeCount(fixedAdd1, 3, 3); 131 SetSubtreeCount(fixedMul, 3, 3); 132 SetSubtreeCount(fixedAdd2, 2, 2); 134 133 135 SetSubtreeCount(@if, 3, 3);134 AddAllowedChildSymbol(StartSymbol, fixedAdd1); 136 135 136 AddAllowedChildSymbol(fixedAdd1, fixedMul, 0); 137 AddAllowedChildSymbol(fixedAdd1, ggDru, 1); 138 foreach (var symb in unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols)) 139 AddAllowedChildSymbol(fixedAdd1, symb, 2); 137 140 138 // allow only real-valued expressions as child of the start symbol 139 foreach (var symb in realValuedSymbols) { 140 AddAllowedChildSymbol(StartSymbol, symb); 141 AddAllowedChildSymbol(DefunSymbol, symb); 142 } 141 AddAllowedChildSymbol(fixedMul, constant, 0); 142 AddAllowedChildSymbol(fixedMul, fixedAdd2, 1); 143 foreach (var symb in realValuedSymbols) 144 AddAllowedChildSymbol(fixedMul, symb, 2); 145 146 AddAllowedChildSymbol(fixedAdd2, c273, 0); 147 AddAllowedChildSymbol(fixedAdd2, flamTmp, 1); 143 148 144 149 foreach (var symb in unaryFunctionSymbols) { … … 153 158 } 154 159 } 160 } 155 161 156 foreach (var childSymb in booleanSymbols) { 157 AddAllowedChildSymbol(@if, childSymb, 0); 158 } 159 foreach (var childSymb in realValuedSymbols) { 160 AddAllowedChildSymbol(@if, childSymb, 1); 161 AddAllowedChildSymbol(@if, childSymb, 2); 162 } 162 private void flamTmp_Changed(object sender, System.EventArgs e) { 163 if (flamTmp.VariableNames.Count() != 1 || flamTmp.VariableNames.ElementAt(0) != "FLAMTMP") 164 flamTmp.VariableNames = new List<string>() { "FLAMTMP" }; 165 } 163 166 164 foreach (var symb in relationalFunctionSymbols) { 165 foreach (var childSymb in realValuedSymbols) { 166 AddAllowedChildSymbol(symb, childSymb); 167 } 168 } 169 foreach (var symb in binaryBooleanFunctionSymbols) { 170 foreach (var childSymb in booleanSymbols) { 171 AddAllowedChildSymbol(symb, childSymb); 172 } 173 } 174 foreach (var symb in unaryBooleanFunctionSymbols) { 175 foreach (var childSymb in booleanSymbols) { 176 AddAllowedChildSymbol(symb, childSymb); 177 } 178 } 167 private void ggDru_Changed(object sender, System.EventArgs e) { 168 if (ggDru.VariableNames.Count() != 1 || ggDru.VariableNames.ElementAt(0) != "GGDRU") 169 ggDru.VariableNames = new List<string>() { "GGDRU" }; 179 170 } 180 171 } -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/Poly10Grammar.cs
r6179 r6284 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 29 [StorableClass] 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 : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {30 [Item("Poly10Grammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")] 31 public class Poly10Grammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 32 33 33 [StorableConstructor] 34 protected TypeCoherentExpressionGrammar(bool deserializing) : base(deserializing) { }35 protected TypeCoherentExpressionGrammar(TypeCoherentExpressionGrammar original, Cloner cloner) : base(original, cloner) { }36 public TypeCoherentExpressionGrammar()37 : base(ItemAttribute.GetName(typeof( TypeCoherentExpressionGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {34 protected Poly10Grammar(bool deserializing) : base(deserializing) { } 35 protected Poly10Grammar(Poly10Grammar original, Cloner cloner) : base(original, cloner) { } 36 public Poly10Grammar() 37 : base(ItemAttribute.GetName(typeof(Poly10Grammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) { 38 38 Initialize(); 39 39 } 40 40 public override IDeepCloneable Clone(Cloner cloner) { 41 return new TypeCoherentExpressionGrammar(this, cloner);41 return new Poly10Grammar(this, cloner); 42 42 } 43 43 … … 47 47 var mul = new Multiplication(); 48 48 var div = new Division(); 49 var mean = new Average();50 var sin = new Sine();51 var cos = new Cosine();52 var tan = new Tangent();53 var log = new Logarithm();54 var pow = new Power();55 pow.InitialFrequency = 0.0;56 var root = new Root();57 root.InitialFrequency = 0.0;58 var exp = new Exponential();59 var @if = new IfThenElse();60 var gt = new GreaterThan();61 var lt = new LessThan();62 var and = new And();63 var or = new Or();64 var not = new Not();65 66 var timeLag = new TimeLag();67 timeLag.InitialFrequency = 0.0;68 var integral = new Integral();69 integral.InitialFrequency = 0.0;70 var derivative = new Derivative();71 derivative.InitialFrequency = 0.0;72 var variableCondition = new VariableCondition();73 variableCondition.InitialFrequency = 0.0;74 49 75 50 var constant = new Constant(); 76 constant.MinValue = -20;77 constant.MaxValue = 20;78 51 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 79 var laggedVariable = new LaggedVariable();80 52 81 laggedVariable.InitialFrequency = 0.0; 82 mean.InitialFrequency = 0.0; 53 var fixedAdd1 = new Addition(); 54 fixedAdd1.Name = "fixed Addition1"; 55 fixedAdd1.Fixed = true; 83 56 84 /* 85 * Start = RealValueExpression 86 * 87 * RealValueExpression = 88 * "Variable" | 89 * "Constant" | 90 * BinaryOperator RealValueExpression RealValueExpression | 91 * UnaryOperator RealValueExpression | 92 * "IF" BooleanExpression RealValueExpression RealValueExpression | 93 * "VariableCondition" RealValueExpression RealValueExpression 94 * 95 * BinaryOperator = 96 * "+" | "-" | "*" | "/" | "Power" 97 * 98 * UnaryOperator = 99 * "Sin" | "Cos" | "Tan" | "Log" | "Exp" 100 * 101 * BooleanExpression = 102 * "AND" BooleanExpression BooleanExpression | 103 * "OR" BooleanExpression BooleanExpression | 104 * "NOT" BooleanExpression | 105 * ">" RealValueExpression RealValueExpression | 106 * "<" RealValueExpression RealValueExpression 107 */ 57 var fixedAdd2 = new Addition(); 58 fixedAdd2.Name = "fixed Addition2"; 59 fixedAdd2.Fixed = true; 108 60 109 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 }; 61 var fixedAdd3 = new Addition(); 62 fixedAdd3.Name = "fixed Addition3"; 63 fixedAdd3.Fixed = true; 110 64 111 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, timeLag, integral, derivative }; 112 var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition }; 65 var fixedMul1 = new Multiplication(); 66 fixedMul1.Name = "fixed Multiplication1"; 67 fixedMul1.Fixed = true; 113 68 114 var unaryBooleanFunctionSymbols = new List<Symbol>() { not }; 115 var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and }; 116 var relationalFunctionSymbols = new List<Symbol>() { gt, lt }; 117 var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable }; 118 var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if }); 119 var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols); 69 var fixedMul2 = new Multiplication(); 70 fixedMul2.Name = "fixed Multiplication2"; 71 fixedMul2.Fixed = true; 72 73 74 #region fixed variables 75 var x1 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 76 x1.Name = "fixed X1"; 77 x1.VariableNames = new List<string>() { "x1" }; 78 x1.Fixed = true; 79 80 81 var x2 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 82 x2.Name = "fixed X2"; 83 x2.VariableNames = new List<string>() { "x2" }; 84 x2.Fixed = true; 85 86 var x3 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 87 x3.Name = "fixed X3"; 88 x3.VariableNames = new List<string>() { "x3" }; 89 x3.Fixed = true; 90 91 var x4 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 92 x4.Name = "fixed X4"; 93 x4.VariableNames = new List<string>() { "x4" }; 94 x4.Fixed = true; 95 96 var x5 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 97 x5.Name = "fixed X5"; 98 x5.VariableNames = new List<string>() { "x5" }; 99 x5.Fixed = true; 100 101 var x6 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 102 x6.Name = "fixed X6"; 103 x6.VariableNames = new List<string>() { "x6" }; 104 x6.Fixed = true; 105 106 var x7 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 107 x7.Name = "fixed X7"; 108 x7.VariableNames = new List<string>() { "x7" }; 109 x7.Fixed = true; 110 111 var x8 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 112 x8.Name = "fixed X8"; 113 x8.VariableNames = new List<string>() { "x8" }; 114 x8.Fixed = true; 115 116 var x9 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 117 x9.Name = "fixed X9"; 118 x9.VariableNames = new List<string>() { "x9" }; 119 x9.Fixed = true; 120 121 var x10 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 122 x10.Name = "fixed X10"; 123 x10.VariableNames = new List<string>() { "x10" }; 124 x10.Fixed = true; 125 #endregion 126 127 var fixedTerminalSymbols = new List<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>() { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 }; 128 var allSymbols = new List<Symbol>() 129 { add, sub, mul, div, constant, variableSymbol, 130 fixedAdd1,fixedMul1,fixedMul2}.Union(fixedTerminalSymbols); 131 132 var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div }; 133 var terminalSymbols = new List<Symbol>() { variableSymbol, constant }; 134 var realValuedSymbols = binaryFunctionSymbols.Concat(terminalSymbols); 120 135 121 136 foreach (var symb in allSymbols) 122 137 AddSymbol(symb); 123 124 foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) { 125 SetSubtreeCount(unaryFun, 1, 1); 138 foreach (var terminalSymbol in terminalSymbols.Union(fixedTerminalSymbols)) { 139 SetSubtreeCount(terminalSymbol, 0, 0); 126 140 } 127 foreach (var binaryFun in binaryFunctionSymbols .Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {141 foreach (var binaryFun in binaryFunctionSymbols) { 128 142 SetSubtreeCount(binaryFun, 2, 2); 129 143 } 144 SetSubtreeCount(fixedAdd1, 3, 3); 145 SetSubtreeCount(fixedMul1, 3, 3); 146 SetSubtreeCount(fixedMul2, 3, 3); 130 147 131 foreach (var terminalSymbol in terminalSymbols) { 132 SetSubtreeCount(terminalSymbol, 0, 0); 148 AddAllowedChildSymbol(StartSymbol, fixedAdd1); 149 foreach (var symb in realValuedSymbols) { 150 AddAllowedChildSymbol(fixedAdd1, symb, 0); 133 151 } 134 152 135 SetSubtreeCount(@if, 3, 3); 153 AddAllowedChildSymbol(fixedAdd1, fixedMul1, 1); 154 AddAllowedChildSymbol(fixedAdd1, fixedMul2, 2); 136 155 137 156 138 // allow only real-valued expressions as child of the start symbol 139 foreach (var symb in realValuedSymbols) { 140 AddAllowedChildSymbol(StartSymbol, symb); 141 AddAllowedChildSymbol(DefunSymbol, symb); 142 } 157 AddAllowedChildSymbol(fixedMul1, x1, 0); 158 AddAllowedChildSymbol(fixedMul1, x7, 1); 159 AddAllowedChildSymbol(fixedMul1, x9, 2); 143 160 144 foreach (var symb in unaryFunctionSymbols) { 145 foreach (var childSymb in realValuedSymbols) { 146 AddAllowedChildSymbol(symb, childSymb); 147 } 148 } 161 AddAllowedChildSymbol(fixedMul2, x3, 0); 162 AddAllowedChildSymbol(fixedMul2, x6, 1); 163 AddAllowedChildSymbol(fixedMul2, x10, 2); 149 164 150 165 foreach (var symb in binaryFunctionSymbols) { … … 153 168 } 154 169 } 155 156 foreach (var childSymb in booleanSymbols) {157 AddAllowedChildSymbol(@if, childSymb, 0);158 }159 foreach (var childSymb in realValuedSymbols) {160 AddAllowedChildSymbol(@if, childSymb, 1);161 AddAllowedChildSymbol(@if, childSymb, 2);162 }163 164 foreach (var symb in relationalFunctionSymbols) {165 foreach (var childSymb in realValuedSymbols) {166 AddAllowedChildSymbol(symb, childSymb);167 }168 }169 foreach (var symb in binaryBooleanFunctionSymbols) {170 foreach (var childSymb in booleanSymbols) {171 AddAllowedChildSymbol(symb, childSymb);172 }173 }174 foreach (var symb in unaryBooleanFunctionSymbols) {175 foreach (var childSymb in booleanSymbols) {176 AddAllowedChildSymbol(symb, childSymb);177 }178 }179 170 } 180 171 } -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r6135 r6284 123 123 <Compile Include="Formatters\SymbolicDataAnalysisExpressionLatexFormatter.cs" /> 124 124 <Compile Include="Formatters\SymbolicDataAnalysisExpressionMATLABFormatter.cs" /> 125 <Compile Include="Grammars\Poly10Grammar.cs" /> 126 <Compile Include="Grammars\MwDruGrammar.cs" /> 125 127 <Compile Include="Interfaces\ISymbolicDataAnalysisBoundedOperator.cs" /> 126 128 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionTreeInterpreter.cs" /> -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r6135 r6284 190 190 SymbolicExpressionTreeGrammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value; 191 191 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) { 192 varSymbol.VariableNames = ProblemData.AllowedInputVariables;192 if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables; 193 193 } 194 194 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) { 195 varSymbol.VariableNames = ProblemData.AllowedInputVariables;195 if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables; 196 196 } 197 197 } -
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs
r5809 r6284 126 126 } 127 127 128 protected override void OnChanged(EventArgs e) { 129 if (@Fixed) { 130 weightManipulatorMu = 1; 131 weightManipulatorSigma = 0; 132 weightMu = 1; 133 weightSigma = 0; 134 multiplicativeWeightManipulatorSigma = 0; 135 } 136 base.OnChanged(e); 137 } 138 128 139 public override ISymbolicExpressionTreeNode CreateTreeNode() { 129 140 return new VariableTreeNode(this);
Note: See TracChangeset
for help on using the changeset viewer.