Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Analysis/3.3/QualityAnalysis/ScaledQualityDifferenceAnalyzer.cs @ 10189

Last change on this file since 10189 was 6760, checked in by epitzer, 13 years ago

#1530 integrate changes from trunk

File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Analysis.QualityAnalysis {
31  [Item("ScaledQualityDifferenceAnalyzer", @"Calculates the quality value relative to a certain range given with a minimum and a maximum value.
32The difference lies in the interval [0;1] if the range [min;max] is as large as the observed quality values, otherwise the difference will become < 0 or > 1.
33A value towards 0 always means that it's closer to the better fitness value, while a value towards 1 means that it's closer to the worse fitness value.")]
34  [StorableClass]
35  public class ScaledQualityDifferenceAnalyzer : SingleSuccessorOperator, IAnalyzer {
36    public ILookupParameter<DoubleValue> QualityParameter {
37      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
38    }
39    public ILookupParameter<BoolValue> MaximizationParameter {
40      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
41    }
42    public ILookupParameter<DoubleValue> ScaledDifferenceParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["ScaledDifference"]; }
44    }
45    public ILookupParameter<ResultCollection> ResultsParameter {
46      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
47    }
48    public IValueLookupParameter<DoubleValue> MinimumQualityParameter {
49      get { return (IValueLookupParameter<DoubleValue>)Parameters["MinimumQuality"]; }
50    }
51    public IValueLookupParameter<DoubleValue> MaximumQualityParameter {
52      get { return (IValueLookupParameter<DoubleValue>)Parameters["MaximumQuality"]; }
53    }
54
55    [StorableConstructor]
56    protected ScaledQualityDifferenceAnalyzer(bool deserializing) : base(deserializing) { }
57    protected ScaledQualityDifferenceAnalyzer(ScaledQualityDifferenceAnalyzer original, Cloner cloner) : base(original, cloner) { }
58    public ScaledQualityDifferenceAnalyzer()
59      : base() {
60      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value that should be compared."));
61      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, false otherwise."));
62      Parameters.Add(new LookupParameter<DoubleValue>("ScaledDifference", "The value that describes whether the quality value lies towards the better quality in the range (<=0.5) or more towards the worse quality (> 0.5)."));
63      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection where the difference will be stored (in addition to the scope)."));
64      Parameters.Add(new ValueLookupParameter<DoubleValue>("MinimumQuality", "The lower bound of the quality range to which the quality is compared."));
65      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumQuality", "The upper bound of the quality range to which the quality is compared."));
66    }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new ScaledQualityDifferenceAnalyzer(this, cloner);
70    }
71
72    public override IOperation Apply() {
73      bool maximization = MaximizationParameter.ActualValue.Value;
74      double quality = QualityParameter.ActualValue.Value, max = MaximumQualityParameter.ActualValue.Value, min = MinimumQualityParameter.ActualValue.Value;
75      double difference;
76
77      difference = ((quality - min) / (max - min));
78      if (maximization) difference = 1.0 - difference;
79
80      DoubleValue differenceValue = ScaledDifferenceParameter.ActualValue;
81      if (differenceValue == null) {
82        differenceValue = new DoubleValue(difference);
83        ScaledDifferenceParameter.ActualValue = differenceValue;
84      } else differenceValue.Value = difference;
85
86      ResultCollection results = ResultsParameter.ActualValue;
87      if (results != null) {
88        IResult r;
89        if (!results.TryGetValue(ScaledDifferenceParameter.ActualName, out r)) {
90          r = new Result(ScaledDifferenceParameter.ActualName, differenceValue);
91          results.Add(r);
92        }
93      }
94
95      return base.Apply();
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.