Changeset 12794
- Timestamp:
- 07/21/15 16:46:19 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.GradientDescent/3.3/LbfgsUpdateResults.cs
r12012 r12794 37 37 private const string StateParameterName = "State"; 38 38 private const string ApproximateGradientsParameterName = "ApproximateGradients"; 39 private const string MaximizationParameterName = "Maximization"; 39 40 40 41 #region Parameter Properties … … 51 52 get { return (ILookupParameter<LbfgsState>)Parameters[StateParameterName]; } 52 53 } 54 public ILookupParameter<BoolValue> MaximizationParameter { 55 get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; } 56 } 53 57 #endregion 54 58 … … 58 62 private DoubleValue Quality { get { return QualityParameter.ActualValue; } } 59 63 private LbfgsState State { get { return StateParameter.ActualValue; } } 64 private BoolValue Maximization { get { return MaximizationParameter.ActualValue; } } 60 65 #endregion 61 66 … … 70 75 Parameters.Add(new LookupParameter<BoolValue>(ApproximateGradientsParameterName, 71 76 "Flag that indicates if gradients should be approximated.")); 77 Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "Flag that indicates if we solve a maximization problem.")); 72 78 // in & out 73 79 Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS algorithm.")); 80 } 81 82 [StorableHook(HookType.AfterDeserialization)] 83 private void AfterDeserialization() { 84 // BackwardsCompatibility3.3 85 86 #region Backwards compatible code, remove with 3.4 87 if (!Parameters.ContainsKey(MaximizationParameterName)) { 88 // previous behaviour defaulted to minimization 89 Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "Flag that indicates if we solve a maximization problem.")); 90 } 91 #endregion 74 92 } 75 93 … … 80 98 public override IOperation Apply() { 81 99 var state = State; 82 var f = Quality.Value; 100 var sign = Maximization.Value ? -1.0 : 1.0; 101 var f = sign * Quality.Value; 83 102 state.State.f = f; 84 103 if (!ApproximateGradients.Value) { 85 var g = QualityGradients. ToArray();104 var g = QualityGradients.Select(gi => sign * gi).ToArray(); 86 105 state.State.g = g; 87 106 }
Note: See TracChangeset
for help on using the changeset viewer.