Changeset 17947 for branches/3107_LearningALPS
- Timestamp:
- 04/16/21 19:02:43 (4 years ago)
- 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 6 6 using HeuristicLab.Common; 7 7 using HeuristicLab.Core; 8 using HeuristicLab.Data; 8 9 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 9 10 using HeuristicLab.Operators; … … 20 21 private const string ProblemDataParameterName = "ProblemData"; 21 22 private const string EstimationLimitsParameterName = "EstimationLimits"; 23 private const string MinimumFrequencyParameterName = "MinimumFrequency"; 24 private const string LearningRateParameterName = "LearningRate"; 22 25 23 26 #region Parameter Properties … … 41 44 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 42 45 } 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 } 43 66 #endregion 44 67 … … 50 73 Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution.")); 51 74 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))); 52 77 } 53 78 … … 62 87 [StorableHook(HookType.AfterDeserialization)] 63 88 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))); 64 93 } 65 94 #endregion … … 71 100 var pd = ProblemDataParameter.ActualValue; 72 101 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 102 double minimumFrequency = MinimumFrequency; 103 double learningRate = LearningRate; 73 104 74 105 if (interpreter == null) { … … 108 139 if (symbolImpacts.TryGetValue(symbol.Name, out double impact)) { 109 140 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); 111 145 } 112 146 } -
branches/3107_LearningALPS/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Creators/SymbolFrequencyReinitializationStrategyController.cs
r17925 r17947 1 using System .Linq;2 1 using System; 2 using System.Linq; 3 3 using HEAL.Attic; 4 4 using HeuristicLab.Common; 5 5 using HeuristicLab.Core; 6 using HeuristicLab.Data; 6 7 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 7 8 using HeuristicLab.Operators; … … 16 17 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 17 18 private const string SymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar"; 19 private const string MinimumFrequencyParameterName = "MinimumFrequency"; 20 private const string LearningRateParameterName = "LearningRate"; 18 21 19 22 #region Parameter Properties … … 25 28 get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; } 26 29 } 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 } 27 38 #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 28 52 29 53 #region Constructors … … 31 55 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated.")); 32 56 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))); 33 59 } 34 60 … … 43 69 [StorableHook(HookType.AfterDeserialization)] 44 70 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))); 45 75 } 46 76 #endregion … … 50 80 var trees = SymbolicExpressionTreeParameter.ActualValue; 51 81 var grammar = SymbolicExpressionTreeGrammarParameter.ActualValue; 82 double minimumFrequency = MinimumFrequency; 83 double learningRate = LearningRate; 52 84 53 85 var symbolFrequencies = SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(trees).ToDictionary(x => x.Key, x => x.Value); … … 59 91 60 92 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); 62 97 } 63 98 }
Note: See TracChangeset
for help on using the changeset viewer.