Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CMAES/HeuristicLab.Encodings.RealVectorEncoding/3.3/CMAESOperators/CMAParameters.cs @ 9121

Last change on this file since 9121 was 9121, checked in by abeham, 11 years ago

#1961: Added wiring code, removed obsolete parameters, simplified mainloop slightly, changed sigmabounds to a matrix

File size: 8.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using System;
27using System.ComponentModel;
28using System.Linq;
29
30namespace HeuristicLab.Encodings.RealVectorEncoding {
31  [Item("CMAES Strategy Parameters", "CMA-ES controls many strategy parameters that guide the search and which are combined in this class.")]
32  [StorableClass]
33  public sealed class CMAParameters : Item, INotifyPropertyChanged {
34
35    [Storable]
36    private DoubleValue axisRatio;
37    public DoubleValue AxisRatio {
38      get { return axisRatio; }
39      set {
40        if (axisRatio == value) return;
41        axisRatio = value;
42        OnPropertyChanged("AxisRatio");
43      }
44    }
45
46    [Storable]
47    private DoubleValue sigma;
48    public DoubleValue Sigma {
49      get { return sigma; }
50      set {
51        if (sigma == value) return;
52        sigma = value;
53        OnPropertyChanged("Sigma");
54      }
55    }
56
57    [Storable]
58    private DoubleMatrix sigmaBounds;
59    public DoubleMatrix SigmaBounds {
60      get { return sigmaBounds; }
61      set {
62        if (sigmaBounds == value) return;
63        sigmaBounds = value;
64        OnPropertyChanged("SigmaBounds");
65      }
66    }
67
68    [Storable]
69    private IntValue mu;
70    public IntValue Mu {
71      get { return mu; }
72      set {
73        if (mu == value) return;
74        mu = value;
75        OnPropertyChanged("Mu");
76      }
77    }
78
79    [Storable]
80    private DoubleArray weights;
81    public DoubleArray Weights {
82      get { return weights; }
83      set {
84        if (weights == value) return;
85        weights = value;
86        OnPropertyChanged("Weights");
87      }
88    }
89
90    [Storable]
91    private DoubleValue muEff;
92    public DoubleValue MuEff {
93      get { return muEff; }
94      set {
95        if (muEff == value) return;
96        muEff = value;
97        OnPropertyChanged("MuEff");
98      }
99    }
100
101    [Storable]
102    private DoubleValue cc;
103    public DoubleValue CC {
104      get { return cc; }
105      set {
106        if (cc == value) return;
107        cc = value;
108        OnPropertyChanged("CC");
109      }
110    }
111
112    [Storable]
113    private DoubleValue cs;
114    public DoubleValue CS {
115      get { return cs; }
116      set {
117        if (cs == value) return;
118        cs = value;
119        OnPropertyChanged("CS");
120      }
121    }
122
123    [Storable]
124    private DoubleValue damps;
125    public DoubleValue Damps {
126      get { return damps; }
127      set {
128        if (damps == value) return;
129        damps = value;
130        OnPropertyChanged("Damps");
131      }
132    }
133
134    [Storable]
135    private DoubleValue muCov;
136    public DoubleValue MuCov {
137      get { return muCov; }
138      set {
139        if (muCov == value) return;
140        muCov = value;
141        OnPropertyChanged("MuCov");
142      }
143    }
144
145    [Storable]
146    private DoubleValue cCov;
147    public DoubleValue CCov {
148      get { return cCov; }
149      set {
150        if (cCov == value) return;
151        cCov = value;
152        OnPropertyChanged("CCov");
153      }
154    }
155
156    [Storable]
157    private DoubleValue cCovSep;
158    public DoubleValue CCovSep {
159      get { return cCovSep; }
160      set {
161        if (cCovSep == value) return;
162        cCovSep = value;
163        OnPropertyChanged("CCovSep");
164      }
165    }
166
167    [Storable]
168    private DoubleArray pc;
169    public DoubleArray PC {
170      get { return pc; }
171      set {
172        if (pc == value) return;
173        pc = value;
174        OnPropertyChanged("PC");
175      }
176    }
177
178    [Storable]
179    private DoubleArray ps;
180    public DoubleArray PS {
181      get { return ps; }
182      set {
183        if (ps == value) return;
184        ps = value;
185        OnPropertyChanged("PS");
186      }
187    }
188
189    [Storable]
190    private DoubleMatrix b;
191    public DoubleMatrix B {
192      get { return b; }
193      set {
194        if (b == value) return;
195        b = value;
196        OnPropertyChanged("B");
197      }
198    }
199
200    [Storable]
201    private DoubleArray d;
202    public DoubleArray D {
203      get { return d; }
204      set {
205        if (d == value) return;
206        d = value;
207        OnPropertyChanged("D");
208      }
209    }
210
211    [Storable]
212    private DoubleMatrix c;
213    public DoubleMatrix C {
214      get { return c; }
215      set {
216        if (c == value) return;
217        c = value;
218        OnPropertyChanged("C");
219      }
220    }
221
222    [Storable]
223    private DoubleArray bDz;
224    public DoubleArray BDz {
225      get { return bDz; }
226      set {
227        if (bDz == value) return;
228        bDz = value;
229        OnPropertyChanged("BDz");
230      }
231    }
232
233    [Storable]
234    private DoubleValue chiN;
235    public DoubleValue ChiN {
236      get { return chiN; }
237      set {
238        if (chiN == value) return;
239        chiN = value;
240        OnPropertyChanged("ChiN");
241      }
242    }
243
244    [Storable]
245    private IntValue initialIterations;
246    public IntValue InitialIterations {
247      get { return initialIterations; }
248      set {
249        if (initialIterations == value) return;
250        initialIterations = value;
251        OnPropertyChanged("InitialIterations");
252      }
253    }
254
255    [StorableConstructor]
256    private CMAParameters(bool deserializing) : base(deserializing) { }
257    private CMAParameters(CMAParameters original, Cloner cloner)
258      : base(original, cloner) {
259      this.axisRatio = cloner.Clone(original.axisRatio);
260      this.b = cloner.Clone(original.b);
261      this.bDz = cloner.Clone(original.bDz);
262      this.c = cloner.Clone(original.c);
263      this.cCov = cloner.Clone(original.cCov);
264      this.cCovSep = cloner.Clone(original.cCovSep);
265      this.cc = cloner.Clone(original.cc);
266      this.chiN = cloner.Clone(original.chiN);
267      this.cs = cloner.Clone(original.cs);
268      this.d = cloner.Clone(original.d);
269      this.damps = cloner.Clone(original.damps);
270      this.initialIterations = cloner.Clone(original.initialIterations);
271      this.mu = cloner.Clone(original.mu);
272      this.muCov = cloner.Clone(original.muCov);
273      this.muEff = cloner.Clone(original.muEff);
274      this.pc = cloner.Clone(original.pc);
275      this.ps = cloner.Clone(original.ps);
276      this.sigma = cloner.Clone(original.sigma);
277      this.sigmaBounds = cloner.Clone(original.sigmaBounds);
278      this.weights = cloner.Clone(original.weights);
279    }
280    public CMAParameters() { }
281    public CMAParameters(int dimension, int lambda) {
282      SetDefaults(dimension, lambda);
283    }
284
285    private void SetDefaults(int N, int lambda) {
286      ChiN = new DoubleValue(Math.Sqrt(N) * (1.0 - 1.0 / (4.0 * N) + 1.0 / (21.0 * N * N)));
287      Mu = new IntValue((int)Math.Floor(lambda / 2.0));
288
289      var w = new double[Mu.Value];
290      for (int i = 0; i < Mu.Value; i++)
291        w[i] = (Math.Log(Mu.Value + 1) - Math.Log(i + 1));
292
293      var sum = w.Sum();
294      for (int i = 0; i < w.Length; i++) w[i] /= sum;
295
296      Weights = new DoubleArray(w);
297      MuEff = new DoubleValue(1.0 / Weights.Sum(x => x * x));
298      CS = new DoubleValue((MuEff.Value + 2) / (N + MuEff.Value + 3));
299      Damps = new DoubleValue(2 * Math.Max(0, Math.Sqrt((MuEff.Value - 1) / (N + 1)) - 1)
300                                * Math.Max(0.3, 1 - N / (1e-6 + /*TODO earliest stop (MaxGen)*/ 1000))
301                              + CS.Value + 1);
302      CC = new DoubleValue(4.0 / (N + 4));
303      MuCov = new DoubleValue(MuEff.Value);
304      CCov = new DoubleValue(2.0 / ((N + 1.41) * (N + 1.41) * MuCov.Value)
305                             + (1 - (1.0 / MuCov.Value)) * Math.Min(1, (2 * MuEff.Value - 1) / (MuEff.Value + (N + 2) * (N + 2))));
306      CCovSep = new DoubleValue(Math.Min(1, CCov.Value * (N + 1.5) / 3));
307    }
308
309    public override IDeepCloneable Clone(Cloner cloner) {
310      return new CMAParameters(this, cloner);
311    }
312
313    public event PropertyChangedEventHandler PropertyChanged;
314    private void OnPropertyChanged(string name) {
315      var handler = PropertyChanged;
316      if (handler != null) handler(this, new PropertyChangedEventArgs(name));
317    }
318  }
319}
Note: See TracBrowser for help on using the repository browser.