1
#region License Information
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 * This file is part of HeuristicLab.
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.
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.
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/>.
24 using HeuristicLab
.Analysis
;
25 using HeuristicLab
.Common
;
26 using HeuristicLab
.Core
;
27 using HeuristicLab
.Data
;
28 using HeuristicLab
.Encodings
.RealVectorEncoding
;
29 using HeuristicLab
.Operators
;
30 using HeuristicLab
.Optimization
;
31 using HeuristicLab
.Parameters
;
34 namespace HeuristicLab
.Algorithms
.CMAEvolutionStrategy
{
35 [Item("CMAAnalyzer", "Analyzes the development of strategy parameters and visualizes the performance of CMA-ES.")]
36 [StorableType("7E36BAC4-D2A5-405D-B46F-FF91BC592D43")]
37 public sealed class CMAAnalyzer
: SingleSuccessorOperator
, IAnalyzer
, ISingleObjectiveOperator
{
39 public bool EnabledByDefault
{
43 #region Parameter Properties
44 public ILookupParameter
<CMAParameters
> StrategyParametersParameter
{
45 get { return (ILookupParameter<CMAParameters>)Parameters["StrategyParameters"]; }
48 public ILookupParameter
<RealVector
> MeanParameter
{
49 get { return (ILookupParameter<RealVector>)Parameters["Mean"]; }
52 public IScopeTreeLookupParameter
<DoubleValue
> QualityParameter
{
53 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
56 public ILookupParameter
<ResultCollection
> ResultsParameter
{
57 get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
62 private CMAAnalyzer(StorableConstructorFlag _
) : base(_
) { }
63 private CMAAnalyzer(CMAAnalyzer original
, Cloner cloner
) : base(original
, cloner
) { }
66 Parameters
.Add(new LookupParameter
<CMAParameters
>("StrategyParameters", "The CMA strategy parameters to be analyzed."));
67 Parameters
.Add(new LookupParameter
<RealVector
>("Mean", "The mean real vector that is being optimized."));
68 Parameters
.Add(new ScopeTreeLookupParameter
<DoubleValue
>("Quality", "The qualities of the solutions."));
69 Parameters
.Add(new LookupParameter
<ResultCollection
>("Results", "The collection to store the results in."));
72 public override IDeepCloneable
Clone(Cloner cloner
) {
73 return new CMAAnalyzer(this, cloner
);
76 public override IOperation
Apply() {
77 var sp
= StrategyParametersParameter
.ActualValue
;
78 var vector
= MeanParameter
.ActualValue
;
79 var results
= ResultsParameter
.ActualValue
;
80 var qualities
= QualityParameter
.ActualValue
;
81 double min
= qualities
[0].Value
, max
= qualities
[0].Value
, avg
= qualities
[0].Value
;
82 for (int i
= 1; i
< qualities
.Length
; i
++) {
83 if (qualities
[i
].Value
< min
) min
= qualities
[i
].Value
;
84 if (qualities
[i
].Value
> max
) max
= qualities
[i
].Value
;
85 avg
+= qualities
[i
].Value
;
87 avg
/= qualities
.Length
;
90 if (results
.ContainsKey("Progress")) {
91 progress
= (DataTable
)results
["Progress"].Value
;
93 progress
= new DataTable("Progress");
94 progress
.Rows
.Add(new DataRow("AxisRatio"));
95 progress
.Rows
.Add(new DataRow("Sigma"));
96 progress
.Rows
.Add(new DataRow("Min Quality"));
97 progress
.Rows
.Add(new DataRow("Max Quality"));
98 progress
.Rows
.Add(new DataRow("Avg Quality"));
99 progress
.VisualProperties
.YAxisLogScale
= true;
100 results
.Add(new Result("Progress", progress
));
102 progress
.Rows
["AxisRatio"].Values
.Add(sp
.AxisRatio
);
103 progress
.Rows
["Sigma"].Values
.Add(sp
.Sigma
);
104 progress
.Rows
["Min Quality"].Values
.Add(min
);
105 progress
.Rows
["Max Quality"].Values
.Add(max
);
106 progress
.Rows
["Avg Quality"].Values
.Add(avg
);
109 if (results
.ContainsKey("Scaling")) {
110 scaling
= (DataTable
)results
["Scaling"].Value
;
112 scaling
= new DataTable("Scaling");
113 scaling
.VisualProperties
.YAxisLogScale
= true;
114 for (int i
= 0; i
< sp
.C
.GetLength(0); i
++)
115 scaling
.Rows
.Add(new DataRow("Axis" + i
.ToString()));
116 results
.Add(new Result("Scaling", scaling
));
118 for (int i
= 0; i
< sp
.C
.GetLength(0); i
++)
119 scaling
.Rows
["Axis" + i
.ToString()].Values
.Add(sp
.D
[i
]);
121 DataTable realVector
;
122 if (results
.ContainsKey("Object Variables")) {
123 realVector
= (DataTable
)results
["Object Variables"].Value
;
125 realVector
= new DataTable("Object Variables");
126 for (int i
= 0; i
< vector
.Length
; i
++)
127 realVector
.Rows
.Add(new DataRow("Axis" + i
.ToString()));
128 results
.Add(new Result("Object Variables", realVector
));
130 for (int i
= 0; i
< vector
.Length
; i
++)
131 realVector
.Rows
["Axis" + i
.ToString()].Values
.Add(vector
[i
]);
134 if (results
.ContainsKey("Standard Deviations")) {
135 stdDevs
= (DataTable
)results
["Standard Deviations"].Value
;
137 stdDevs
= new DataTable("Standard Deviations");
138 stdDevs
.VisualProperties
.YAxisLogScale
= true;
139 stdDevs
.Rows
.Add(new DataRow("MinStdDev"));
140 stdDevs
.Rows
.Add(new DataRow("MaxStdDev"));
141 for (int i
= 0; i
< vector
.Length
; i
++)
142 stdDevs
.Rows
.Add(new DataRow("Axis" + i
.ToString()));
143 results
.Add(new Result("Standard Deviations", stdDevs
));
145 for (int i
= 0; i
< vector
.Length
; i
++)
146 stdDevs
.Rows
["Axis" + i
.ToString()].Values
.Add(Math
.Sqrt(sp
.C
[i
, i
]));
147 stdDevs
.Rows
["MinStdDev"].Values
.Add(sp
.D
.Min() * sp
.Sigma
);
148 stdDevs
.Rows
["MaxStdDev"].Values
.Add(sp
.D
.Max() * sp
.Sigma
);