Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CMAES/HeuristicLab.Algorithms.CMAEvolutionStrategy/3.3/CMAAnalyzer.cs @ 9274

Last change on this file since 9274 was 9148, checked in by abeham, 12 years ago

#1961:

  • Added Logarithmic flag also to AxisRatio
  • Fixed some bugs regarding initial iterations
  • Removed the PredefinedRealVectorCreator and instead added a NormalDistributedRealVectorCreator
    • When sigma is 0 this is the same as the PredefinedRealVectorCreator
File size: 5.3 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.Analysis;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using System;
31
32namespace HeuristicLab.Algorithms.CMAEvolutionStrategy {
33  [Item("CMAAnalyzer", "Analyzes the development of strategy parameters and visualizes the performance of CMA-ES.")]
34  [StorableClass]
35  public sealed class CMAAnalyzer : SingleSuccessorOperator, IAnalyzer {
36
37    public bool EnabledByDefault {
38      get { return false; }
39    }
40
41    #region Parameter Properties
42    public ILookupParameter<CMAParameters> StrategyParametersParameter {
43      get { return (ILookupParameter<CMAParameters>)Parameters["StrategyParameters"]; }
44    }
45
46    public ILookupParameter<RealVector> MeanParameter {
47      get { return (ILookupParameter<RealVector>)Parameters["Mean"]; }
48    }
49
50    public ILookupParameter<ResultCollection> ResultsParameter {
51      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
52    }
53    #endregion
54
55    [StorableConstructor]
56    private CMAAnalyzer(bool deserializing) : base(deserializing) { }
57    private CMAAnalyzer(CMAAnalyzer original, Cloner cloner) : base(original, cloner) { }
58    public CMAAnalyzer()
59      : base() {
60      Parameters.Add(new LookupParameter<CMAParameters>("StrategyParameters", "The CMA strategy parameters to be analyzed."));
61      Parameters.Add(new LookupParameter<RealVector>("Mean", "The mean real vector that is being optimized."));
62      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection to store the results in."));
63    }
64
65    public override IDeepCloneable Clone(Cloner cloner) {
66      return new CMAAnalyzer(this, cloner);
67    }
68
69    public override IOperation Apply() {
70      var sp = StrategyParametersParameter.ActualValue;
71      var vector = MeanParameter.ActualValue;
72      var results = ResultsParameter.ActualValue;
73
74      DataTable axisRatio;
75      if (results.ContainsKey("AxisRatio")) {
76        axisRatio = (DataTable)results["AxisRatio"].Value;
77      } else {
78        axisRatio = new DataTable("AxisRatio");
79        axisRatio.Rows.Add(new DataRow("AxisRatio"));
80        axisRatio.VisualProperties.YAxisLogScale = true;
81        results.Add(new Result("AxisRatio", axisRatio));
82      }
83      axisRatio.Rows["AxisRatio"].Values.Add(sp.AxisRatio.Value);
84
85      DataTable sigma;
86      if (results.ContainsKey("Sigma")) {
87        sigma = (DataTable)results["Sigma"].Value;
88      } else {
89        sigma = new DataTable("Sigma");
90        sigma.VisualProperties.YAxisLogScale = true;
91        sigma.Rows.Add(new DataRow("Sigma"));
92        results.Add(new Result("Sigma", sigma));
93      }
94      sigma.Rows["Sigma"].Values.Add(sp.Sigma.Value);
95
96      DataTable scaling;
97      if (results.ContainsKey("Scaling")) {
98        scaling = (DataTable)results["Scaling"].Value;
99      } else {
100        scaling = new DataTable("Scaling");
101        scaling.VisualProperties.YAxisLogScale = true;
102        for (int i = 0; i < sp.C.Rows; i++)
103          scaling.Rows.Add(new DataRow("Axis" + i.ToString()));
104        results.Add(new Result("Scaling", scaling));
105      }
106      for (int i = 0; i < sp.C.Rows; i++)
107        scaling.Rows["Axis" + i.ToString()].Values.Add(sp.D[i]);
108
109      DataTable realVector;
110      if (results.ContainsKey("RealVector")) {
111        realVector = (DataTable)results["RealVector"].Value;
112      } else {
113        realVector = new DataTable("RealVector");
114        for (int i = 0; i < vector.Length; i++)
115          realVector.Rows.Add(new DataRow("Axis" + i.ToString()));
116        results.Add(new Result("RealVector", realVector));
117      }
118      for (int i = 0; i < vector.Length; i++)
119        realVector.Rows["Axis" + i.ToString()].Values.Add(vector[i]);
120
121      DataTable stdDevs;
122      if (results.ContainsKey("StandardDeviations")) {
123        stdDevs = (DataTable)results["StandardDeviations"].Value;
124      } else {
125        stdDevs = new DataTable("StandardDeviations");
126        stdDevs.VisualProperties.YAxisLogScale = true;
127        for (int i = 0; i < vector.Length; i++)
128          stdDevs.Rows.Add(new DataRow("Axis" + i.ToString()));
129        results.Add(new Result("StandardDeviations", stdDevs));
130      }
131      for (int i = 0; i < vector.Length; i++)
132        stdDevs.Rows["Axis" + i.ToString()].Values.Add(Math.Sqrt(sp.C[i, i]));
133
134      return base.Apply();
135    }
136  }
137}
Note: See TracBrowser for help on using the repository browser.