Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17857


Ignore:
Timestamp:
03/03/21 13:33:41 (4 years ago)
Author:
bburlacu
Message:

#3107: Implement crude initial reinitialization concept.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3107_LearningALPS/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Creators/SymbolFrequencyReinitializationStrategyController.cs

    r17854 r17857  
    1 using HEAL.Attic;
     1using System.Linq;
     2
     3using HEAL.Attic;
    24using HeuristicLab.Common;
    35using HeuristicLab.Core;
    46using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    57using HeuristicLab.Operators;
     8using HeuristicLab.Optimization;
    69using HeuristicLab.Parameters;
    710
     
    912  [Item("SymbolFrequencyReinitializationStrategyController", "")]
    1013  [StorableType("8F0B7020-A02F-491D-881A-5CE550426E5B")]
    11   public class SymbolFrequencyReinitializationStrategyController : InstrumentedOperator {
     14  public class SymbolFrequencyReinitializationStrategyController : InstrumentedOperator, IReinitializationStrategyController {
    1215
    1316    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
     
    2427    #endregion
    2528
    26     #region Constructos
     29    #region Constructors
    2730    public SymbolFrequencyReinitializationStrategyController() {
    2831      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated."));
     
    4851      var grammar = SymbolicExpressionTreeGrammarParameter.ActualValue;
    4952
    50       var symbolFrequencies = SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(trees);
    51       // TODO: adapt grammar
     53      var symbolFrequencies = SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(trees).ToDictionary(x => x.Key, x => x.Value);
     54
     55      foreach(var s in grammar.AllowedSymbols) {
     56        if (s is ProgramRootSymbol || s is StartSymbol) {
     57          continue;
     58        }
     59
     60        if (symbolFrequencies.TryGetValue(s.Name, out double f)) {
     61          s.InitialFrequency = f;
     62        }
     63      }
    5264
    5365      return base.InstrumentedApply();
Note: See TracChangeset for help on using the changeset viewer.