Changeset 3541
- Timestamp:
- 04/27/10 11:44:36 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/DefaultSymbolicExpressionGrammar.cs
r3462 r3541 40 40 [Item("DefaultSymbolicExpressionGrammar", "Represents a grammar that defines the syntax of symbolic expression trees.")] 41 41 public class DefaultSymbolicExpressionGrammar : Item, ISymbolicExpressionGrammar { 42 [Storable] 42 43 #region properties for separation between implementation and persistence 44 [Storable] 45 private IEnumerable<KeyValuePair<string, int>> MinSubTreeCount { 46 get { return minSubTreeCount.AsEnumerable(); } 47 set { minSubTreeCount = value.ToDictionary(x => x.Key, x => x.Value); } 48 } 49 50 [Storable] 51 private IEnumerable<KeyValuePair<string, int>> MaxSubTreeCount { 52 get { return maxSubTreeCount.AsEnumerable(); } 53 set { maxSubTreeCount = value.ToDictionary(x => x.Key, x => x.Value); } 54 } 55 56 [Storable] 57 private IEnumerable<KeyValuePair<string, IEnumerable<IEnumerable<string>>>> AllowedChildSymbols { 58 get { 59 return (from parentEntry in allowedChildSymbols 60 let setEnumeration = parentEntry.Value.Select(set => set.AsEnumerable()).ToList() 61 select new KeyValuePair<string, IEnumerable<IEnumerable<string>>>(parentEntry.Key, setEnumeration)) 62 .ToList(); 63 } 64 set { 65 allowedChildSymbols = new Dictionary<string, List<HashSet<string>>>(); 66 foreach (var pair in value) { 67 allowedChildSymbols[pair.Key] = new List<HashSet<string>>(); 68 foreach (var entry in pair.Value) { 69 var hashSet = new HashSet<string>(); 70 foreach (string child in entry) { 71 hashSet.Add(child); 72 } 73 allowedChildSymbols[pair.Key].Add(hashSet); 74 } 75 } 76 } 77 } 78 [Storable] 79 private IEnumerable<KeyValuePair<string, Symbol>> AllSymbols { 80 get { return allSymbols.AsEnumerable(); } 81 set { allSymbols = value.ToDictionary(x => x.Key, x => x.Value); } 82 } 83 #endregion 84 43 85 private Dictionary<string, int> minSubTreeCount; 44 [Storable]45 86 private Dictionary<string, int> maxSubTreeCount; 46 [Storable]47 87 private Dictionary<string, List<HashSet<string>>> allowedChildSymbols; 48 [Storable]49 88 private Dictionary<string, Symbol> allSymbols; 89 [Storable] 90 private Symbol startSymbol; 50 91 51 92 public DefaultSymbolicExpressionGrammar() 52 93 : base() { 53 Reset(); 54 } 55 56 private void Initialize() { 57 startSymbol = new StartSymbol(); 58 AddSymbol(startSymbol); 59 SetMinSubtreeCount(startSymbol, 1); 60 SetMaxSubtreeCount(startSymbol, 1); 61 } 62 63 #region ISymbolicExpressionGrammar Members 64 65 private Symbol startSymbol; 66 public Symbol StartSymbol { 67 get { return startSymbol; } 68 set { startSymbol = value; } 69 } 70 71 protected void Reset() { 94 Clear(); 95 } 96 97 public void Clear() { 72 98 minSubTreeCount = new Dictionary<string, int>(); 73 99 maxSubTreeCount = new Dictionary<string, int>(); … … 77 103 cachedMaxExpressionLength = new Dictionary<string, int>(); 78 104 cachedMinExpressionDepth = new Dictionary<string, int>(); 79 Initialize(); 80 } 105 106 startSymbol = new StartSymbol(); 107 AddSymbol(startSymbol); 108 SetMinSubtreeCount(startSymbol, 1); 109 SetMaxSubtreeCount(startSymbol, 1); 110 } 111 112 #region ISymbolicExpressionGrammar Members 113 114 public Symbol StartSymbol { 115 get { return startSymbol; } 116 set { startSymbol = value; } 117 } 118 81 119 82 120 public void AddSymbol(Symbol symbol) { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs
r3484 r3541 40 40 set { 41 41 minFunctionDefinitions = value; 42 Reset();42 Initialize(); 43 43 } 44 44 } … … 49 49 set { 50 50 maxFunctionDefinitions = value; 51 Reset();51 Initialize(); 52 52 } 53 53 } … … 58 58 set { 59 59 minFunctionArguments = value; 60 Reset();60 Initialize(); 61 61 } 62 62 } … … 67 67 set { 68 68 maxFunctionArguments = value; 69 Reset();69 Initialize(); 70 70 } 71 71 } … … 83 83 } 84 84 85 [StorableHook(HookType.AfterDeserialization)] 86 private void AfterDeserializationHook() { 87 Reset(); 88 } 85 private void Initialize() { 86 base.Clear(); 89 87 90 private new void Reset() {91 base.Reset();92 Initialize();93 }94 95 private void Initialize() {96 88 // remove the start symbol of the default grammar 97 89 RemoveSymbol(StartSymbol); … … 107 99 SetMaxSubtreeCount(defunSymbol, 1); 108 100 109 // copy symbols from mainBranchGrammar 110 foreach (var symb in mainBranchGrammar.Symbols) { 111 AddSymbol(symb); 112 SetMinSubtreeCount(symb, mainBranchGrammar.GetMinSubtreeCount(symb)); 113 SetMaxSubtreeCount(symb, mainBranchGrammar.GetMaxSubtreeCount(symb)); 114 } 101 if (mainBranchGrammar != null) { 102 // copy symbols from mainBranchGrammar 103 foreach (var symb in mainBranchGrammar.Symbols) { 104 AddSymbol(symb); 105 SetMinSubtreeCount(symb, mainBranchGrammar.GetMinSubtreeCount(symb)); 106 SetMaxSubtreeCount(symb, mainBranchGrammar.GetMaxSubtreeCount(symb)); 107 } 115 108 116 // the start symbol of the mainBranchGrammar is allowed as the result producing branch117 SetAllowedChild(StartSymbol, mainBranchGrammar.StartSymbol, 0);109 // the start symbol of the mainBranchGrammar is allowed as the result producing branch 110 SetAllowedChild(StartSymbol, mainBranchGrammar.StartSymbol, 0); 118 111 119 // ADF branches maxFunctionDefinitions120 for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) {121 SetAllowedChild(StartSymbol, defunSymbol, argumentIndex);122 }112 // ADF branches maxFunctionDefinitions 113 for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) { 114 SetAllowedChild(StartSymbol, defunSymbol, argumentIndex); 115 } 123 116 124 // copy syntax constraints from mainBranchGrammar 125 foreach (var parent in mainBranchGrammar.Symbols) { 126 for (int i = 0; i < mainBranchGrammar.GetMaxSubtreeCount(parent); i++) { 127 foreach (var child in mainBranchGrammar.Symbols) { 128 if (mainBranchGrammar.IsAllowedChild(parent, child, i)) { 129 SetAllowedChild(parent, child, i); 117 // copy syntax constraints from mainBranchGrammar 118 foreach (var parent in mainBranchGrammar.Symbols) { 119 for (int i = 0; i < mainBranchGrammar.GetMaxSubtreeCount(parent); i++) { 120 foreach (var child in mainBranchGrammar.Symbols) { 121 if (mainBranchGrammar.IsAllowedChild(parent, child, i)) { 122 SetAllowedChild(parent, child, i); 123 } 130 124 } 131 125 } 132 126 } 133 }134 127 135 // every symbol of the mainBranchGrammar that is allowed as child of the start symbol is also allowed as direct child of defun 136 foreach (var symb in mainBranchGrammar.Symbols) { 137 if (mainBranchGrammar.IsAllowedChild(mainBranchGrammar.StartSymbol, symb, 0)) 138 SetAllowedChild(defunSymbol, symb, 0); 128 // every symbol of the mainBranchGrammar that is allowed as child of the start symbol is also allowed as direct child of defun 129 foreach (var symb in mainBranchGrammar.Symbols) { 130 if (mainBranchGrammar.IsAllowedChild(mainBranchGrammar.StartSymbol, symb, 0)) 131 SetAllowedChild(defunSymbol, symb, 0); 132 } 139 133 } 140 134 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs
r3486 r3541 36 36 public class SymbolicExpressionTreeNode : ICloneable { 37 37 [Storable] 38 private List<SymbolicExpressionTreeNode> subTrees;38 private IList<SymbolicExpressionTreeNode> subTrees; 39 39 [Storable] 40 40 private Symbol symbol; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs
r3513 r3541 50 50 get { return interpreter; } 51 51 } 52 private List<string> inputVariables; 52 53 [Storable] 53 private List<string> inputVariables;54 54 public IEnumerable<string> InputVariables { 55 55 get { return inputVariables.AsEnumerable(); } 56 set { 57 if (value != null) 58 inputVariables = new List<string>(value); 59 } 56 60 } 57 61 public SymbolicRegressionModel() : base() { } // for cloning -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Variable.cs
r3512 r3541 66 66 } 67 67 } 68 private List<string> variableNames; 68 69 [Storable] 69 private List<string> variableNames;70 70 public IEnumerable<string> VariableNames { 71 71 get { return variableNames; }
Note: See TracChangeset
for help on using the changeset viewer.