Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.GradientDescent/3.3/LbfgsUpdateResults.cs @ 9503

Last change on this file since 9503 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 4.1 KB
RevLine 
[8371]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8371]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
[8396]26using HeuristicLab.Encodings.RealVectorEncoding;
[8371]27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
[8401]31namespace HeuristicLab.Algorithms.GradientDescent {
[8371]32  [StorableClass]
[8396]33  [Item(Name = "LBFGS UpdateResults", Description = "Sets the results (function value and gradients) for the next optimization step in the LM-BFGS algorithm.")]
34  public sealed class LbfgsUpdateResults : SingleSuccessorOperator {
[8375]35    private const string QualityGradientsParameterName = "QualityGradients";
36    private const string QualityParameterName = "Quality";
[8396]37    private const string StateParameterName = "State";
38    private const string ApproximateGradientsParameterName = "ApproximateGradients";
[8371]39
40    #region Parameter Properties
[8396]41    public ILookupParameter<BoolValue> ApproximateGradientsParameter {
42      get { return (ILookupParameter<BoolValue>)Parameters[ApproximateGradientsParameterName]; }
[8371]43    }
[8396]44    public ILookupParameter<RealVector> QualityGradientsParameter {
45      get { return (ILookupParameter<RealVector>)Parameters[QualityGradientsParameterName]; }
46    }
[8375]47    public ILookupParameter<DoubleValue> QualityParameter {
48      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
[8371]49    }
[8396]50    public ILookupParameter<LbfgsState> StateParameter {
51      get { return (ILookupParameter<LbfgsState>)Parameters[StateParameterName]; }
[8371]52    }
53    #endregion
54
55    #region Properties
[8396]56    private BoolValue ApproximateGradients { get { return ApproximateGradientsParameter.ActualValue; } }
57    private RealVector QualityGradients { get { return QualityGradientsParameter.ActualValue; } }
[8375]58    private DoubleValue Quality { get { return QualityParameter.ActualValue; } }
[8396]59    private LbfgsState State { get { return StateParameter.ActualValue; } }
[8371]60    #endregion
61
62    [StorableConstructor]
[8396]63    private LbfgsUpdateResults(bool deserializing) : base(deserializing) { }
64    private LbfgsUpdateResults(LbfgsUpdateResults original, Cloner cloner) : base(original, cloner) { }
65    public LbfgsUpdateResults()
[8371]66      : base() {
67      // in
[8396]68      Parameters.Add(new LookupParameter<RealVector>(QualityGradientsParameterName, "The gradients at the evaluated point of the function to optimize."));
[8375]69      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The value at the evaluated point of the function to optimize."));
[8396]70      Parameters.Add(new LookupParameter<BoolValue>(ApproximateGradientsParameterName,
71                                                    "Flag that indicates if gradients should be approximated."));
[8371]72      // in & out
[8396]73      Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS algorithm."));
[8371]74    }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
[8396]77      return new LbfgsUpdateResults(this, cloner);
[8371]78    }
79
80    public override IOperation Apply() {
[8396]81      var state = State;
[8375]82      var f = Quality.Value;
[8371]83      state.State.f = f;
[8396]84      if (!ApproximateGradients.Value) {
85        var g = QualityGradients.ToArray();
86        state.State.g = g;
87      }
[8371]88      return base.Apply();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.