Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17947 for branches


Ignore:
Timestamp:
04/16/21 19:02:43 (4 years ago)
Author:
pfleck
Message:

#3107 Added MinimumFrequency and LearningRate parameters to symbol frequency and node impact strategy controllers.

Location:
branches/3107_LearningALPS
Files:
2 edited

Legend:

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

    r17917 r17947  
    66using HeuristicLab.Common;
    77using HeuristicLab.Core;
     8using HeuristicLab.Data;
    89using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    910using HeuristicLab.Operators;
     
    2021    private const string ProblemDataParameterName = "ProblemData";
    2122    private const string EstimationLimitsParameterName = "EstimationLimits";
     23    private const string MinimumFrequencyParameterName = "MinimumFrequency";
     24    private const string LearningRateParameterName = "LearningRate";
    2225
    2326    #region Parameter Properties
     
    4144      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    4245    }
     46
     47    public IFixedValueParameter<DoubleValue> MinimumFrequencyParameter {
     48      get { return (IFixedValueParameter<DoubleValue>)Parameters[MinimumFrequencyParameterName]; }
     49    }
     50
     51    public IFixedValueParameter<DoubleValue> LearningRateParameter {
     52      get { return (IFixedValueParameter<DoubleValue>)Parameters[LearningRateParameterName]; }
     53    }
     54    #endregion
     55
     56    #region Properties
     57    public double MinimumFrequency {
     58      get { return MinimumFrequencyParameter.Value.Value; }
     59      set { MinimumFrequencyParameter.Value.Value = value; }
     60    }
     61
     62    public double LearningRate {
     63      get { return LearningRateParameter.Value.Value; }
     64      set { LearningRateParameter.Value.Value = value; }
     65    }
    4366    #endregion
    4467
     
    5073      Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution."));
    5174      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
     75      Parameters.Add(new FixedValueParameter<DoubleValue>(MinimumFrequencyParameterName, "Minimum Frequency for the controller to set to symbols.", new DoubleValue(0)));
     76      Parameters.Add(new FixedValueParameter<DoubleValue>(LearningRateParameterName, "Learning Rate for how fast the frequency is adapted. Zero learning rate means no adaption, one means new frequency = symbol frequency.", new DoubleValue(0.1)));
    5277    }
    5378
     
    6287    [StorableHook(HookType.AfterDeserialization)]
    6388    private void AfterDeserialization() {
     89      if (!Parameters.ContainsKey(MinimumFrequencyParameterName))
     90        Parameters.Add(new FixedValueParameter<DoubleValue>(MinimumFrequencyParameterName, "Minimum Frequency for the controller to set to symbols.", new DoubleValue(0)));
     91      if (!Parameters.ContainsKey(LearningRateParameterName))
     92        Parameters.Add(new FixedValueParameter<DoubleValue>(LearningRateParameterName, "Learning Rate for how fast the frequency is adapted. Zero learning rate means no adaption, one means new frequency = symbol frequency.", new DoubleValue(0.1)));
    6493    }
    6594    #endregion
     
    71100      var pd = ProblemDataParameter.ActualValue;
    72101      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     102      double minimumFrequency = MinimumFrequency;
     103      double learningRate = LearningRate;
    73104
    74105      if (interpreter == null) {
     
    108139        if (symbolImpacts.TryGetValue(symbol.Name, out double impact)) {
    109140          var f = Math.Max(0, impact / symbolCounts[symbol.Name]); // do something clever here
    110           symbol.InitialFrequency = f;
     141          double oldFrequency = symbol.InitialFrequency;
     142          double impactFrequency = f;
     143          double newFrequency = oldFrequency + (impactFrequency - oldFrequency) * learningRate;
     144          symbol.InitialFrequency = Math.Max(minimumFrequency, newFrequency);
    111145        }
    112146      }
  • branches/3107_LearningALPS/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Creators/SymbolFrequencyReinitializationStrategyController.cs

    r17925 r17947  
    1 using System.Linq;
    2 
     1using System;
     2using System.Linq;
    33using HEAL.Attic;
    44using HeuristicLab.Common;
    55using HeuristicLab.Core;
     6using HeuristicLab.Data;
    67using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    78using HeuristicLab.Operators;
     
    1617    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    1718    private const string SymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
     19    private const string MinimumFrequencyParameterName = "MinimumFrequency";
     20    private const string LearningRateParameterName = "LearningRate";
    1821
    1922    #region Parameter Properties
     
    2528      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
    2629    }
     30
     31    public IFixedValueParameter<DoubleValue> MinimumFrequencyParameter {
     32      get { return (IFixedValueParameter<DoubleValue>)Parameters[MinimumFrequencyParameterName]; }
     33    }
     34
     35    public IFixedValueParameter<DoubleValue> LearningRateParameter {
     36      get { return (IFixedValueParameter<DoubleValue>)Parameters[LearningRateParameterName]; }
     37    }
    2738    #endregion
     39
     40    #region Properties
     41    public double MinimumFrequency {
     42      get { return MinimumFrequencyParameter.Value.Value; }
     43      set { MinimumFrequencyParameter.Value.Value = value; }
     44    }
     45
     46    public double LearningRate {
     47      get { return LearningRateParameter.Value.Value; }
     48      set { LearningRateParameter.Value.Value = value; }
     49    }
     50    #endregion
     51
    2852
    2953    #region Constructors
     
    3155      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated."));
    3256      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
     57      Parameters.Add(new FixedValueParameter<DoubleValue>(MinimumFrequencyParameterName, "Minimum Frequency for the controller to set to symbols.", new DoubleValue(0)));
     58      Parameters.Add(new FixedValueParameter<DoubleValue>(LearningRateParameterName, "Learning Rate for how fast the frequency is adapted. Zero learning rate means no adaption, one means new frequency = symbol frequency.", new DoubleValue(0.1)));
    3359    }
    3460
     
    4369    [StorableHook(HookType.AfterDeserialization)]
    4470    private void AfterDeserialization() {
     71      if (!Parameters.ContainsKey(MinimumFrequencyParameterName))
     72        Parameters.Add(new FixedValueParameter<DoubleValue>(MinimumFrequencyParameterName, "Minimum Frequency for the controller to set to symbols.", new DoubleValue(0)));
     73      if (!Parameters.ContainsKey(LearningRateParameterName))
     74        Parameters.Add(new FixedValueParameter<DoubleValue>(LearningRateParameterName, "Learning Rate for how fast the frequency is adapted. Zero learning rate means no adaption, one means new frequency = symbol frequency.", new DoubleValue(0.1)));
    4575    }
    4676    #endregion
     
    5080      var trees = SymbolicExpressionTreeParameter.ActualValue;
    5181      var grammar = SymbolicExpressionTreeGrammarParameter.ActualValue;
     82      double minimumFrequency = MinimumFrequency;
     83      double learningRate = LearningRate;
    5284
    5385      var symbolFrequencies = SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(trees).ToDictionary(x => x.Key, x => x.Value);
     
    5991
    6092        if (symbolFrequencies.TryGetValue(s.Name, out double f)) {
    61           s.InitialFrequency = f;
     93          double oldFrequency = s.InitialFrequency;
     94          double symbolFrequency = f;
     95          double newFrequency = oldFrequency + (symbolFrequency - oldFrequency) * learningRate;
     96          s.InitialFrequency = Math.Max(minimumFrequency, newFrequency);
    6297        }
    6398      }
Note: See TracChangeset for help on using the changeset viewer.