Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.GradientDescent/3.3/LbfgsState.cs @ 17607

Last change on this file since 17607 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 14.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HEAL.Attic;
28
29namespace HeuristicLab.Algorithms.GradientDescent {
30  [StorableType("2A117076-0311-4F85-A1B9-16F39D5752DE")]
31  [Item("LbfgsState", "Internal state for the limited-memory BFGS optimization algorithm.")]
32  public sealed class LbfgsState : Item {
33    private alglib.minlbfgs.minlbfgsstate state;
34    public alglib.minlbfgs.minlbfgsstate State { get { return state; } }
35
36    [StorableConstructor]
37    private LbfgsState(StorableConstructorFlag _) : base(_) {
38      state = new alglib.minlbfgs.minlbfgsstate();
39    }
40    private LbfgsState(LbfgsState original, Cloner cloner)
41      : base(original, cloner) {
42      this.state = new alglib.minlbfgs.minlbfgsstate();
43      this.state.autobuf = CopyArray(original.state.autobuf);
44      this.state.d = CopyArray(original.state.d);
45      this.state.denseh = CopyArray(original.state.denseh);
46      this.state.diagh = CopyArray(original.state.diagh);
47      this.state.diffstep = original.state.diffstep;
48      this.state.epsf = original.state.epsf;
49      this.state.epsg = original.state.epsg;
50      this.state.epsx = original.state.epsx;
51      this.state.f = original.state.f;
52      this.state.fbase = original.state.fbase;
53      this.state.fm1 = original.state.fm1;
54      this.state.fm2 = original.state.fm2;
55      this.state.fold = original.state.fold;
56      this.state.fp1 = original.state.fp1;
57      this.state.fp2 = original.state.fp1;
58      this.state.g = CopyArray(original.state.g);
59      this.state.gammak = original.state.gammak;
60      this.state.k = original.state.k;
61
62      this.state.lstate.brackt = original.state.lstate.brackt;
63      this.state.lstate.dg = original.state.lstate.dg;
64      this.state.lstate.dginit = original.state.lstate.dginit;
65      this.state.lstate.dgm = original.state.lstate.dgm;
66      this.state.lstate.dgtest = original.state.lstate.dgtest;
67      this.state.lstate.dgx = original.state.lstate.dgx;
68      this.state.lstate.dgxm = original.state.lstate.dgxm;
69      this.state.lstate.dgy = original.state.lstate.dgy;
70      this.state.lstate.dgym = original.state.lstate.dgym;
71      this.state.lstate.finit = original.state.lstate.finit;
72      this.state.lstate.fm = original.state.lstate.fm;
73      this.state.lstate.ftest1 = original.state.lstate.ftest1;
74      this.state.lstate.fx = original.state.lstate.fx;
75      this.state.lstate.fxm = original.state.lstate.fxm;
76      this.state.lstate.fy = original.state.lstate.fy;
77      this.state.lstate.fym = original.state.lstate.fym;
78      this.state.lstate.infoc = original.state.lstate.infoc;
79      this.state.lstate.stage1 = original.state.lstate.stage1;
80      this.state.lstate.stmax = original.state.lstate.stmax;
81      this.state.lstate.stmin = original.state.lstate.stmin;
82      this.state.lstate.stx = original.state.lstate.stx;
83      this.state.lstate.sty = original.state.lstate.sty;
84      this.state.lstate.width = original.state.lstate.width;
85      this.state.lstate.width1 = original.state.lstate.width1;
86      this.state.lstate.xtrapf = original.state.lstate.xtrapf;
87
88      this.state.m = original.state.m;
89      this.state.maxits = original.state.maxits;
90      this.state.mcstage = original.state.mcstage;
91      this.state.n = original.state.n;
92      this.state.needf = original.state.needf;
93      this.state.needfg = original.state.needfg;
94      this.state.nfev = original.state.nfev;
95      this.state.p = original.state.p;
96      this.state.prectype = original.state.prectype;
97      this.state.q = original.state.q;
98      this.state.repiterationscount = original.state.repiterationscount;
99      this.state.repnfev = original.state.repnfev;
100      this.state.repterminationtype = original.state.repterminationtype;
101      this.state.rho = CopyArray(original.state.rho);
102      this.state.rstate.ba = CopyArray(original.state.rstate.ba);
103      this.state.rstate.ca = CopyArray(original.state.rstate.ca);
104      this.state.rstate.ia = CopyArray(original.state.rstate.ia);
105      this.state.rstate.ra = CopyArray(original.state.rstate.ra);
106      this.state.rstate.stage = original.state.rstate.stage;
107
108      this.state.s = CopyArray(original.state.s);
109      this.state.sk = CopyArray(original.state.sk);
110      this.state.stp = original.state.stp;
111      this.state.stpmax = original.state.stpmax;
112      this.state.theta = CopyArray(original.state.theta);
113      this.state.trimthreshold = original.state.trimthreshold;
114      this.state.work = CopyArray(original.state.work);
115      this.state.x = CopyArray(original.state.x);
116      this.state.xrep = original.state.xrep;
117      this.state.xupdated = original.state.xupdated;
118      this.state.yk = CopyArray(original.state.yk);
119    }
120
121    public LbfgsState(alglib.minlbfgs.minlbfgsstate state)
122      : base() {
123      this.state = state;
124    }
125
126    public override IDeepCloneable Clone(Cloner cloner) {
127      return new LbfgsState(this, cloner);
128    }
129
130
131    private T[] CopyArray<T>(T[] a) {
132      var c = new T[a.Length];
133      Array.Copy(a, c, c.Length);
134      return c;
135    }
136    private T[,] CopyArray<T>(T[,] a) {
137      var c = new T[a.GetLength(0), a.GetLength(1)];
138      Array.Copy(a, c, c.Length);
139      return c;
140    }
141
142    #region persistence
143    [Storable]
144    private double[] Autobuf { get { return state.autobuf; } set { state.autobuf = value; } }
145    [Storable]
146    private double[] D { get { return state.d; } set { state.d = value; } }
147    [Storable]
148    private double[,] Denseh { get { return state.denseh; } set { state.denseh = value; } }
149    [Storable]
150    private double[] Diagh { get { return state.diagh; } set { state.diagh = value; } }
151    [Storable]
152    private double Diffstep { get { return state.diffstep; } set { state.diffstep = value; } }
153    [Storable]
154    private double Epsf { get { return state.epsf; } set { state.epsf = value; } }
155    [Storable]
156    private double Epsg { get { return state.epsg; } set { state.epsg = value; } }
157    [Storable]
158    private double Epsx { get { return state.epsx; } set { state.epsx = value; } }
159    [Storable]
160    private double F { get { return state.f; } set { state.f = value; } }
161    [Storable]
162    private double Fbase { get { return state.fbase; } set { state.fbase = value; } }
163    [Storable]
164    private double Fm1 { get { return state.fm1; } set { state.fm1 = value; } }
165    [Storable]
166    private double Fm2 { get { return state.fm2; } set { state.fm2 = value; } }
167    [Storable]
168    private double Fold { get { return state.fold; } set { state.fold = value; } }
169    [Storable]
170    private double Fp1 { get { return state.fp1; } set { state.fp1 = value; } }
171    [Storable]
172    private double Fp2 { get { return state.fp2; } set { state.fp2 = value; } }
173    [Storable]
174    private double[] G { get { return state.g; } set { state.g = value; } }
175    [Storable]
176    private double Gammak { get { return state.gammak; } set { state.gammak = value; } }
177    [Storable]
178    private int K { get { return state.k; } set { state.k = value; } }
179    [Storable]
180    private bool LstateBrackt { get { return state.lstate.brackt; } set { state.lstate.brackt = value; } }
181    [Storable]
182    private double LstateDg { get { return state.lstate.dg; } set { state.lstate.dg = value; } }
183    [Storable]
184    private double LstateDginit { get { return state.lstate.dginit; } set { state.lstate.dginit = value; } }
185    [Storable]
186    private double LstateDgm { get { return state.lstate.dgm; } set { state.lstate.dgm = value; } }
187    [Storable]
188    private double LstateDgtest { get { return state.lstate.dgtest; } set { state.lstate.dgtest = value; } }
189    [Storable]
190    private double LstateDgx { get { return state.lstate.dgx; } set { state.lstate.dgx = value; } }
191    [Storable]
192    private double LstateDgxm { get { return state.lstate.dgxm; } set { state.lstate.dgxm = value; } }
193    [Storable]
194    private double LstateDgy { get { return state.lstate.dgy; } set { state.lstate.dgy = value; } }
195    [Storable]
196    private double LstateDgym { get { return state.lstate.dgym; } set { state.lstate.dgym = value; } }
197    [Storable]
198    private double LstateFinit { get { return state.lstate.finit; } set { state.lstate.finit = value; } }
199    [Storable]
200    private double LstateFm { get { return state.lstate.fm; } set { state.lstate.fm = value; } }
201    [Storable]
202    private double LstateFtest1 { get { return state.lstate.ftest1; } set { state.lstate.ftest1 = value; } }
203    [Storable]
204    private double LstateFx { get { return state.lstate.fx; } set { state.lstate.fx = value; } }
205    [Storable]
206    private double LstateFxm { get { return state.lstate.fxm; } set { state.lstate.fxm = value; } }
207    [Storable]
208    private double LstateFy { get { return state.lstate.fy; } set { state.lstate.fy = value; } }
209    [Storable]
210    private double LstateFym { get { return state.lstate.fym; } set { state.lstate.fym = value; } }
211    [Storable]
212    private int LstateInfoc { get { return state.lstate.infoc; } set { state.lstate.infoc = value; } }
213    [Storable]
214    private bool LstateStage1 { get { return state.lstate.stage1; } set { state.lstate.stage1 = value; } }
215    [Storable]
216    private double LstateStmax { get { return state.lstate.stmax; } set { state.lstate.stmax = value; } }
217    [Storable]
218    private double LstateStmin { get { return state.lstate.stmin; } set { state.lstate.stmin = value; } }
219    [Storable]
220    private double LstateStx { get { return state.lstate.stx; } set { state.lstate.stx = value; } }
221    [Storable]
222    private double LstateSty { get { return state.lstate.sty; } set { state.lstate.sty = value; } }
223    [Storable]
224    private double LstateWidth { get { return state.lstate.width; } set { state.lstate.width = value; } }
225    [Storable]
226    private double LstateWidth1 { get { return state.lstate.width1; } set { state.lstate.width1 = value; } }
227    [Storable]
228    private double LstateXtrapf { get { return state.lstate.xtrapf; } set { state.lstate.xtrapf = value; } }
229
230    [Storable]
231    private int M { get { return state.m; } set { state.m = value; } }
232    [Storable]
233    private int MaxIts { get { return state.maxits; } set { state.maxits = value; } }
234    [Storable]
235    private int Mcstage { get { return state.mcstage; } set { state.mcstage = value; } }
236    [Storable]
237    private int N { get { return state.n; } set { state.n = value; } }
238    [Storable]
239    private bool Needf { get { return state.needf; } set { state.needf = value; } }
240    [Storable]
241    private bool Needfg { get { return state.needfg; } set { state.needfg = value; } }
242    [Storable]
243    private int Nfev { get { return state.nfev; } set { state.nfev = value; } }
244    [Storable]
245    private int P { get { return state.p; } set { state.p = value; } }
246    [Storable]
247    private int Prectype { get { return state.prectype; } set { state.prectype = value; } }
248    [Storable]
249    private int Q { get { return state.q; } set { state.q = value; } }
250    [Storable]
251    private int Repiterationscount { get { return state.repiterationscount; } set { state.repiterationscount = value; } }
252    [Storable]
253    private int Repnfev { get { return state.repnfev; } set { state.repnfev = value; } }
254    [Storable]
255    private int Repterminationtype { get { return state.repterminationtype; } set { state.repterminationtype = value; } }
256    [Storable]
257    private double[] Rho { get { return state.rho; } set { state.rho = value; } }
258    [Storable]
259    private bool[] RstateBa { get { return state.rstate.ba; } set { state.rstate.ba = value; } }
260    [Storable]
261    private IList<Tuple<double, double>> RStateCa {
262      get { return state.rstate.ca.Select(c => Tuple.Create(c.x, c.y)).ToList(); }
263      set { state.rstate.ca = value.Select(t => new alglib.complex(t.Item1, t.Item2)).ToArray(); }
264    }
265    [Storable]
266    private int[] RstateIa { get { return state.rstate.ia; } set { state.rstate.ia = value; } }
267    [Storable]
268    private double[] RstateRa { get { return state.rstate.ra; } set { state.rstate.ra = value; } }
269    [Storable]
270    private int RstateStage { get { return state.rstate.stage; } set { state.rstate.stage = value; } }
271    [Storable]
272    private double[] S { get { return state.s; } set { state.s = value; } }
273    [Storable]
274    private double[,] Sk { get { return state.sk; } set { state.sk = value; } }
275    [Storable]
276    private double Stp { get { return state.stp; } set { state.stp = value; } }
277    [Storable]
278    private double Stpmax { get { return state.stpmax; } set { state.stpmax = value; } }
279    [Storable]
280    private double[] Theta { get { return state.theta; } set { state.theta = value; } }
281    [Storable]
282    private double Trimthreshold { get { return state.trimthreshold; } set { state.trimthreshold = value; } }
283    [Storable]
284    private double[] Work { get { return state.work; } set { state.work = value; } }
285    [Storable]
286    private double[] X { get { return state.x; } set { state.x = value; } }
287    [Storable]
288    private bool Xrep { get { return state.xrep; } set { state.xrep = value; } }
289    [Storable]
290    private bool Xupdated { get { return state.xupdated; } set { state.xupdated = value; } }
291    [Storable]
292    private double[,] Yk { get { return state.yk; } set { state.yk = value; } }
293    #endregion
294  }
295}
Note: See TracBrowser for help on using the repository browser.