Changeset 15975
- Timestamp:
- 06/28/18 16:56:41 (6 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
r15974 r15975 24 24 public Symbol StartSymbol { get; private set; } 25 25 26 public Hasher<int> Hasher { get; }26 public Hasher<int> Hasher { get; private set; } 27 27 28 28 #region Symbols … … 77 77 public Grammar(string[] variables) : this(variables, Enum.GetValues(typeof(GrammarRule)).Cast<GrammarRule>()) { } 78 78 79 [StorableConstructor] 80 protected Grammar(bool deserializing) { 81 InitTreeParser(); 82 } 83 79 84 protected Grammar(Grammar original, Cloner cloner) : base(original, cloner) { 80 85 infixExpressionFormatter = cloner.Clone(original.infixExpressionFormatter); … … 83 88 VarTerminals = original.VarTerminals.Select(cloner.Clone).ToList(); 84 89 85 Var = cloner.Clone(original.Var);86 Expr = cloner.Clone(original.Expr);87 Term = cloner.Clone(original.Term);88 Factor = cloner.Clone(original.Factor);89 LogFactor = cloner.Clone(original.LogFactor);90 ExpFactor = cloner.Clone(original.ExpFactor);91 SinFactor = cloner.Clone(original.SinFactor);92 SimpleExpr = cloner.Clone(original.SimpleExpr);93 SimpleTerm = cloner.Clone(original.SimpleTerm);94 InvExpr = cloner.Clone(original.InvExpr);95 InvTerm = cloner.Clone(original.InvTerm);96 97 Addition = cloner.Clone(original.Addition);98 Multiplication = cloner.Clone(original.Multiplication);99 Log = cloner.Clone(original.Log);100 Exp = cloner.Clone(original.Exp);101 Sin = cloner.Clone(original.Sin);102 Inv = cloner.Clone(original.Inv);103 Const = cloner.Clone(original.Const);90 Var = (NonterminalSymbol)cloner.Clone(original.Var); 91 Expr = (NonterminalSymbol)cloner.Clone(original.Expr); 92 Term = (NonterminalSymbol)cloner.Clone(original.Term); 93 Factor = (NonterminalSymbol)cloner.Clone(original.Factor); 94 LogFactor = (NonterminalSymbol)cloner.Clone(original.LogFactor); 95 ExpFactor = (NonterminalSymbol)cloner.Clone(original.ExpFactor); 96 SinFactor = (NonterminalSymbol)cloner.Clone(original.SinFactor); 97 SimpleExpr = (NonterminalSymbol)cloner.Clone(original.SimpleExpr); 98 SimpleTerm = (NonterminalSymbol)cloner.Clone(original.SimpleTerm); 99 InvExpr = (NonterminalSymbol)cloner.Clone(original.InvExpr); 100 InvTerm = (NonterminalSymbol)cloner.Clone(original.InvTerm); 101 102 Addition = (TerminalSymbol)cloner.Clone(original.Addition); 103 Multiplication = (TerminalSymbol)cloner.Clone(original.Multiplication); 104 Log = (TerminalSymbol)cloner.Clone(original.Log); 105 Exp = (TerminalSymbol)cloner.Clone(original.Exp); 106 Sin = (TerminalSymbol)cloner.Clone(original.Sin); 107 Inv = (TerminalSymbol)cloner.Clone(original.Inv); 108 Const = (TerminalSymbol)cloner.Clone(original.Const); 104 109 105 110 StartSymbol = Expr; … … 240 245 public double EvaluatePhrase(SymbolString s, IRegressionProblemData problemData, bool optimizeConstants) { 241 246 SymbolicExpressionTree tree = ParseSymbolicExpressionTree(s); 247 242 248 return RSquaredEvaluator.Evaluate(problemData, tree, optimizeConstants); 243 249 } -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
r15974 r15975 52 52 } 53 53 54 p rotecteddouble VariableImportanceWeight {54 public double VariableImportanceWeight { 55 55 get { return VariableImportanceWeightParameter.Value.Value; } 56 set { VariableImportanceWeightParameter.Value.Value = value; } 56 57 } 57 58 … … 133 134 } 134 135 136 [Storable] 135 137 public SymbolString BestTrainingSentence { get; set; } // Currently set in RSquaredEvaluator: quite hacky, but makes testing much easier for now... 136 138 #endregion … … 144 146 [Storable] 145 147 internal SearchDataStore OpenPhrases { get; private set; } // Stack/Queue/etc. for fetching the next node in the search tree. 146 147 [StorableHook(HookType.AfterDeserialization)]148 private void AfterDeserialization() {149 variableImportance = CalculateVariableImportances();150 }151 148 152 149 #region execution stats … … 162 159 #endregion 163 160 161 [Storable] 164 162 public Grammar Grammar { get; private set; } 165 163 … … 168 166 return new GrammarEnumerationAlgorithm(this, cloner); 169 167 } 168 169 [StorableConstructor] 170 protected GrammarEnumerationAlgorithm(bool deserializing) : base(deserializing) { } 170 171 171 172 public GrammarEnumerationAlgorithm() { … … 237 238 #endregion 238 239 240 [Storable] 239 241 private Dictionary<VariableTerminalSymbol, double> variableImportance; 240 242 … … 250 252 OpenPhrases = new SearchDataStore(SearchDataStructure, SearchDataStructureSize, SearchCacheSize); // Select search strategy 251 253 254 CalculateVariableImportances(); 255 252 256 base.Prepare(); // this actually clears the results which will get reinitialized on Run() 253 257 } 254 258 255 private Dictionary<VariableTerminalSymbol, double>CalculateVariableImportances() {259 private void CalculateVariableImportances() { 256 260 variableImportance = new Dictionary<VariableTerminalSymbol, double>(); 257 261 … … 271 275 variableImportance[varSym] = rfImpact.Item2 / sum; 272 276 } 273 return variableImportance;274 277 } 275 278 … … 277 280 // do not reinitialize the algorithm if we're resuming from pause 278 281 if (previousExecutionState != ExecutionState.Paused) { 279 CalculateVariableImportances();280 282 InitResults(); 281 283 var phrase0 = new SymbolString(new[] { Grammar.StartSymbol }); -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Symbol.cs
r15974 r15975 1 1 using System; 2 using System.Collections; 2 3 using System.Collections.Generic; 4 using System.Linq; 3 5 using HeuristicLab.Common; 4 6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 101 103 102 104 [StorableClass] 103 public class Production : List<Symbol>, IDeepCloneable { 105 public class Production : DeepCloneable, IList<Symbol> { 106 [Storable] 107 private List<Symbol> symbols; 104 108 105 public Production(params Symbol[] symbols) : base(symbols) {}109 public int Count { get { return symbols.Count; } } 106 110 107 public Production(IEnumerable<Symbol> symbols) : base(symbols) { } 111 public bool IsReadOnly => throw new NotImplementedException(); 112 113 public Symbol this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } 114 115 public Production(params Symbol[] symbols) { 116 this.symbols = symbols.ToList(); 117 } 118 119 public Production(IEnumerable<Symbol> symbols) { 120 this.symbols = symbols.ToList(); 121 } 108 122 109 123 [StorableConstructor] 110 124 protected Production(bool deserializing) { } 111 125 112 protected Production(Production original, Cloner cloner) : this(original){113 cloner.RegisterClonedObject(original, this);126 protected Production(Production original, Cloner cloner) { 127 symbols = original.symbols.Select(cloner.Clone).ToList(); 114 128 } 115 129 116 public IDeepCloneable Clone(Cloner cloner) {130 public override IDeepCloneable Clone(Cloner cloner) { 117 131 return new Production(this, cloner); 118 }119 120 public object Clone() {121 return Clone(new Cloner());122 132 } 123 133 … … 125 135 return string.Join(" ", this); 126 136 } 137 138 #region IList<Symbol> methods 139 public IEnumerator<Symbol> GetEnumerator() { 140 return symbols.GetEnumerator(); 141 } 142 143 IEnumerator IEnumerable.GetEnumerator() { 144 return GetEnumerator(); 145 } 146 147 public int IndexOf(Symbol item) { 148 return symbols.IndexOf(item); 149 } 150 151 public void Insert(int index, Symbol item) { 152 symbols.Insert(index, item); 153 } 154 155 public void RemoveAt(int index) { 156 symbols.RemoveAt(index); 157 } 158 159 public void Add(Symbol item) { 160 symbols.Add(item); 161 } 162 163 public void Clear() { 164 symbols.Clear(); 165 } 166 167 public bool Contains(Symbol item) { 168 return symbols.Contains(item); 169 } 170 171 public void CopyTo(Symbol[] array, int arrayIndex) { 172 symbols.CopyTo(array, arrayIndex); 173 } 174 175 public void CopyTo(int index, Symbol[] array, int arrayIndex, int count) { 176 symbols.CopyTo(index, array, arrayIndex, count); 177 } 178 179 public bool Remove(Symbol item) { 180 return symbols.Remove(item); 181 } 182 #endregion 127 183 } 128 184 } -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Hashing/Hasher.cs
r15965 r15975 17 17 } 18 18 19 protected Grammar Grammar { get; } 19 [Storable] 20 protected Grammar Grammar { get; private set; } 20 21 21 22 protected abstract THashType AggregateHashes(Symbol operatorSym, IList<THashType> hashes);
Note: See TracChangeset
for help on using the changeset viewer.