Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/02/16 14:10:53 (9 years ago)
Author:
abeham
Message:

#2457:

  • Added stripped-down version of FLA branch
  • Added appropriate calculators
  • Fixed detecting maximization in RLD view
Location:
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape
Files:
1 added
6 deleted
9 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/EnumerableExtensions.cs

    r7128 r13583  
    1919 */
    2020#endregion
     21
    2122using System;
    2223using System.Collections.Generic;
     24
    2325namespace HeuristicLab.Analysis.FitnessLandscape {
    2426
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/FitnessCloudAnalyzer.cs

    r7176 r13583  
    1919 */
    2020#endregion
     21
    2122using System.Drawing;
    2223using System.Linq;
     
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930
    30 namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
     31namespace HeuristicLab.Analysis.FitnessLandscape {
    3132
    3233  [StorableClass]
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/IQualityTrailAnalyzer.cs

    r7128 r13583  
    1919 */
    2020#endregion
     21
    2122using HeuristicLab.Optimization;
     23
    2224namespace HeuristicLab.Analysis.FitnessLandscape {
    2325  public interface IQualityTrailAnalyzer : IAnalyzer { }
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalysis.cs

    r9142 r13583  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 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;
    223using System.Collections.Generic;
    324using System.Linq;
    425
    5 namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
     26namespace HeuristicLab.Analysis.FitnessLandscape {
    627
    728  public class InformationAnalysis {
     
    1940    public List<double> PartialInformationContent { get; private set; }
    2041    public List<double> DensityBasinInformation { get; private set; }
    21     public List<double> TotalEntropy { get; private set; } 
     42    public List<double> TotalEntropy { get; private set; }
    2243    public List<double> QualityDelta { get; private set; }
    2344    public double InformationStability { get; private set; }
     
    89110
    90111      #region types, fields and properties
    91       public enum Form {Uni, NonUni, Any}
     112      public enum Form { Uni, NonUni, Any }
    92113
    93114      private readonly Slope[] slopes;
    94115
    95116      private static readonly Dictionary<Tuple<Form, int>, IList<Shape>> SHAPES =
    96         new Dictionary<Tuple<Form,int>,IList<Shape>>();
     117        new Dictionary<Tuple<Form, int>, IList<Shape>>();
    97118      #endregion
    98119
     
    130151
    131152      private Shape Extend(Slope s) {
    132         return new Shape(slopes.Concat(new[] {s}));
     153        return new Shape(slopes.Concat(new[] { s }));
    133154      }
    134155
     
    157178      #region IEnumerable Members
    158179      public IEnumerator<Slope> GetEnumerator() {
    159         return (IEnumerator<Slope>) slopes.GetEnumerator();
     180        return (IEnumerator<Slope>)slopes.GetEnumerator();
    160181      }
    161182      System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
     
    171192        if (other.Length > Length)
    172193          return 1;
    173         for (var i = 0; i<Length; i++) {
     194        for (var i = 0; i < Length; i++) {
    174195          var d = slopes[i].CompareTo(other.slopes[i]);
    175196          if (d != 0)
     
    184205      }
    185206      public override int GetHashCode() {
    186         return slopes.Aggregate(0, (a, s) => a*3 + ((int) s + 1)).GetHashCode();
     207        return slopes.Aggregate(0, (a, s) => a * 3 + ((int)s + 1)).GetHashCode();
    187208      }
    188209
     
    197218    private static IEnumerable<Slope> Slopes(double eps, IEnumerable<double> differences) {
    198219      return differences.Select(d => (d > eps ? Slope.Up : (d < -eps ? Slope.Down : 0)));
    199     } 
     220    }
    200221
    201222    private static IEnumerable<Shape> Shapes(int size, IEnumerable<Slope> slopes) {
     
    243264
    244265    private static IEnumerable<double> Differences(IEnumerable<double> values) {
    245       return Utils.Delta(values, (x, y) => y - x);
     266      return values.Delta((x, y) => y - x);
    246267    }
    247268
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalyzer.cs

    r9142 r13583  
    2020#endregion
    2121
    22 using System;
    23 using System.Linq;
    24 using HeuristicLab.Analysis.FitnessLandscape.DataTables;
    2522using HeuristicLab.Common;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Data;
    2825using HeuristicLab.Operators;
    29 using HeuristicLab.Optimization.Operators;
     26using HeuristicLab.Optimization;
    3027using HeuristicLab.Parameters;
    3128using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using System.Linq;
    3230
    33 namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
     31namespace HeuristicLab.Analysis.FitnessLandscape {
    3432
    3533  [StorableClass]
    36   public class InformationAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {
     34  public class InformationAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer {
    3735    public bool EnabledByDefault {
    3836      get { return false; }
     
    4341      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
    4442    }
    45     public LookupParameter<InformationStabilityTable> InformationStabilityParameter {
    46       get { return (LookupParameter<InformationStabilityTable>)Parameters["Information Stability"]; }
    47     }
    48     public LookupParameter<InformationAnalysisTable> InformationParameter {
    49       get { return (LookupParameter<InformationAnalysisTable>)Parameters["Information"]; }
    50     }
    51     public LookupParameter<VariableCollection> ResultsParameter {
    52       get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
     43    public LookupParameter<ResultCollection> ResultsParameter {
     44      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
    5345    }
    5446    public ValueLookupParameter<IntValue> NQuantilesParameter {
     
    5850      get { return (ValueLookupParameter<IntValue>)Parameters["ShapeSize"]; }
    5951    }
    60     public LookupParameter<DoubleValue> InformationContentValueParameter {
    61       get { return (LookupParameter<DoubleValue>)Parameters["InformationContentValue"]; }
     52    public LookupParameter<DoubleValue> InformationContentParameter {
     53      get { return (LookupParameter<DoubleValue>)Parameters["InformationContent"]; }
    6254    }
    63     public LookupParameter<DoubleValue> PartialInformationContentValueParameter {
    64       get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContentValue"]; }
     55    public LookupParameter<DoubleValue> PartialInformationContentParameter {
     56      get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContent"]; }
    6557    }
    66     public LookupParameter<DoubleValue> DensityBasinInformationValueParameter {
    67       get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformationValue"]; }
     58    public LookupParameter<DoubleValue> DensityBasinInformationParameter {
     59      get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformation"]; }
    6860    }
    69     public LookupParameter<DoubleValue> TotalEntropyValueParameter {
    70       get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropyValue"]; }
     61    public LookupParameter<DoubleValue> TotalEntropyParameter {
     62      get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropy"]; }
    7163    }
    72     public LookupParameter<DoubleValue> InformationStabilityValueParameter {
    73       get { return (LookupParameter<DoubleValue>)Parameters["InformationStabilityValue"]; }
     64    public LookupParameter<DoubleValue> InformationStabilityParameter {
     65      get { return (LookupParameter<DoubleValue>)Parameters["InformationStability"]; }
    7466    }
    75     public LookupParameter<IntValue> RegularityValueParameter {
    76       get { return (LookupParameter<IntValue>)Parameters["RegularityValue"]; }
     67    public LookupParameter<DoubleValue> RegularityParameter {
     68      get { return (LookupParameter<DoubleValue>)Parameters["Regularity"]; }
    7769    }
    78     public LookupParameter<IntValue> DiversityValueParameter {
    79       get { return (LookupParameter<IntValue>)Parameters["DiversityValue"]; }
     70    public LookupParameter<DoubleValue> DiversityParameter {
     71      get { return (LookupParameter<DoubleValue>)Parameters["Diversity"]; }
    8072    }
    81 
    82     #region Peaks
    8373    public LookupParameter<DoubleValue> PeakInformationContentParameter {
    84       get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContent"]; }
    85     }
    86     public LookupParameter<DoubleValue> PeakInformationContentQualityDeltaParameter {
    87       get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContentQualityDelta"]; }
     74      get { return (LookupParameter<DoubleValue>)Parameters["PeakInformationContent"]; }
    8875    }
    8976    public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter {
    90       get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformation"]; }
     77      get { return (LookupParameter<DoubleValue>)Parameters["PeakDensityBasinInformation"]; }
    9178    }
    92     public LookupParameter<DoubleValue> PeakDensityBasinInformationQualityDeltaParameter {
    93       get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformationQualityDelta"]; }
    94     }
    95 
    96 
    9779    #endregion
    98 
    99     #endregion
    100 
    101     private InformationStabilityTable InformationStability {
    102       get { return InformationStabilityParameter.ActualValue; }
    103     }
    104     private double InformationContentValue {
    105       set { InformationContentValueParameter.ActualValue = new DoubleValue(value); }
    106     }
    107     private double PartialInformationContentValue {
    108       set { PartialInformationContentValueParameter.ActualValue = new DoubleValue(value); }
    109     }
    110     private double DensityBasinInformationValue {
    111       set { DensityBasinInformationValueParameter.ActualValue = new DoubleValue(value); }
    112     }
    113     private double TotalEntropyValue {
    114       set { TotalEntropyValueParameter.ActualValue = new DoubleValue(value); }
    115     }
    116     private double InformationStabilityValue {
    117       set { InformationStabilityValueParameter.ActualValue = new DoubleValue(value); }
    118     }
    11980
    12081    [StorableConstructor]
     
    12485    public InformationAnalyzer() {
    12586      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
    126       Parameters.Add(new LookupParameter<InformationStabilityTable>("Information Stability", "Information stability development over time"));
    127       Parameters.Add(new LookupParameter<InformationAnalysisTable>("Information", "A data table that information theoretic fitness landscape characteristics"));
    128       Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
     87      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
    12988
    13089      Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20)));
    13190      Parameters.Add(new ValueLookupParameter<IntValue>("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2)));
    13291
    133       Parameters.Add(new LookupParameter<DoubleValue>("InformationContentValue", "The information content H(0) at eps = 0"));
    134       Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContentValue", "Partial information content M(0) at eps = 0"));
    135       Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0"));
    136       Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropyValue", "The overall disorder in the trajectory"));
    137       Parameters.Add(new LookupParameter<DoubleValue>("InformationStabilityValue", "Information Stability Value"));
    138       Parameters.Add(new LookupParameter<IntValue>("RegularityValue", "The number of different quality differences"));
    139       Parameters.Add(new LookupParameter<IntValue>("DiversityValue", "The number of different quality values"));
     92      Parameters.Add(new LookupParameter<DoubleValue>("InformationContent", "The information content H(0) at eps = 0"));
     93      Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContent", "Partial information content M(0) at eps = 0"));
     94      Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformation", "Density Basin Information h(0) at eps = 0"));
     95      Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropy", "The overall disorder in the trajectory"));
     96      Parameters.Add(new LookupParameter<DoubleValue>("InformationStability", "Information Stability Value"));
     97      Parameters.Add(new LookupParameter<DoubleValue>("Regularity", "The number of different quality differences"));
     98      Parameters.Add(new LookupParameter<DoubleValue>("Diversity", "The number of different quality values"));
    14099      Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta."));
    141       Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContentQualityDelta", "Quality delta with maximum information content."));
    142100      Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta."));
    143       Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformationQualityDelta", "Quality delta with maximum density basin information."));
    144 
    145       var resultsCollector = new ResultsCollector();
    146       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationParameter.Name));
    147       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationStabilityParameter.Name));
    148       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationContentValueParameter.Name));
    149       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PartialInformationContentValueParameter.Name));
    150       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DensityBasinInformationValueParameter.Name));
    151       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(TotalEntropyValueParameter.Name));
    152       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationStabilityValueParameter.Name));
    153       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(RegularityValueParameter.Name));
    154       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(DiversityValueParameter.Name));
    155       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentParameter.Name));
    156       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentQualityDeltaParameter.Name));
    157       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationParameter.Name));
    158       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationQualityDeltaParameter.Name));
    159 
    160       OperatorGraph.InitialOperator = resultsCollector;
    161       resultsCollector.Successor = null;
    162101    }
    163102
     
    167106
    168107    public override IOperation Apply() {
    169       DataTable qualityTrail = QualityTrailParameter.ActualValue;
    170       if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
    171         EnsureExistsInformationStabilityTable();
    172         EnsureExistsInformationTable();
    173         AnalyseInformation();
    174       }
     108      var qualityTrail = QualityTrailParameter.ActualValue;
     109      if (qualityTrail == null || qualityTrail.Rows.Count == 0) return base.Apply();
     110
     111      var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
     112      if (qualities.Count <= 2) return base.Apply();
     113
     114      var nQuantiles = NQuantilesParameter.ActualValue.Value;
     115      var shapeSize = ShapeSizeParameter.ActualValue.Value;
     116      var results = ResultsParameter.ActualValue;
     117
     118      var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize);
     119      var ic = new DoubleValue(analysis.InformationContent.FirstOrDefault());
     120      InformationContentParameter.ActualValue = ic;
     121      AddOrUpdateResult(results, InformationContentParameter.Name, ic);
     122      var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault());
     123      PartialInformationContentParameter.ActualValue = pic;
     124      AddOrUpdateResult(results, PartialInformationContentParameter.Name, pic);
     125      var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault());
     126      DensityBasinInformationParameter.ActualValue = dbi;
     127      AddOrUpdateResult(results, DensityBasinInformationParameter.Name, dbi);
     128      var @is = new DoubleValue(analysis.InformationStability);
     129      InformationStabilityParameter.ActualValue = @is;
     130      AddOrUpdateResult(results, InformationStabilityParameter.Name, @is);
     131      var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count);
     132      RegularityParameter.ActualValue = regularity;
     133      AddOrUpdateResult(results, RegularityParameter.Name, regularity);
     134      var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count);
     135      DiversityParameter.ActualValue = diversity;
     136      AddOrUpdateResult(results, DiversityParameter.Name, diversity);
     137      var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault());
     138      TotalEntropyParameter.ActualValue = totalEntropy;
     139      AddOrUpdateResult(results, TotalEntropyParameter.Name, totalEntropy);
     140      var peakIc = new DoubleValue(analysis.PeakInformationContent.Value);
     141      PeakInformationContentParameter.ActualValue = peakIc;
     142      AddOrUpdateResult(results, PeakInformationContentParameter.Name, peakIc);
     143      var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
     144      PeakDensityBasinInformationParameter.ActualValue = peakDbi;
     145      AddOrUpdateResult(results, PeakDensityBasinInformationParameter.Name, peakDbi);
     146
    175147      return base.Apply();
    176148    }
    177149
    178     private void AnalyseInformation() {
    179       int nQuantiles = NQuantilesParameter.ActualValue.Value;
    180       int shapeSize = ShapeSizeParameter.ActualValue.Value;
    181       var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
    182       if (qualities.Count > 2) {
    183         InformationAnalysisTable informationTable = InformationParameter.ActualValue;
    184         var informationContent = informationTable.Rows["Information Content"].Values;
    185         var partialInformationContent = informationTable.Rows["Partial Information Content"].Values;
    186         var densityBasinInformation = informationTable.Rows["Density Basin Information"].Values;
    187         var totalEntropy = informationTable.Rows["Total Entropy"].Values;
    188         var qualityDelta = informationTable.Rows["Quality Delta"].Values;
    189         var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize);
    190         InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity);
    191         InformationStability.Rows["Diversity"].Values.Add(analysis.Diversity);
    192         InformationStability.Rows["Relative Regularity"].Values.Add(1.0*analysis.Regularity/qualities.Count);
    193         InformationStability.Rows["Relative Diversity"].Values.Add(1.0*analysis.Diversity/qualities.Count);
    194         InformationStability.Rows["Information Stability"].Values.Add(analysis.InformationStability);
    195         informationContent.Clear();
    196         informationContent.AddRange(analysis.InformationContent);
    197         partialInformationContent.Clear();
    198         partialInformationContent.AddRange(analysis.PartialInformationContent);
    199         densityBasinInformation.Clear();
    200         densityBasinInformation.AddRange(analysis.DensityBasinInformation);
    201         totalEntropy.Clear();
    202         totalEntropy.AddRange(analysis.TotalEntropy);
    203         qualityDelta.Clear();
    204         qualityDelta.AddRange(analysis.QualityDelta);
    205         InformationContentValue = analysis.InformationContent.FirstOrDefault();
    206         PartialInformationContentValue = analysis.PartialInformationContent.FirstOrDefault();
    207         DensityBasinInformationValue = analysis.DensityBasinInformation.FirstOrDefault();
    208         InformationStabilityValue = analysis.InformationStability;
    209         RegularityValueParameter.ActualValue = new IntValue(analysis.Regularity);
    210         DiversityValueParameter.ActualValue = new IntValue(analysis.Diversity);
    211         if (analysis.PeakInformationContent != null) {
    212           PeakInformationContentParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.Value);
    213           PeakInformationContentQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.QualityDelta);
    214         }
    215         if (analysis.PeakDensityBasinInformation != null) {
    216           PeakDensityBasinInformationParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
    217           PeakDensityBasinInformationQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.QualityDelta);
    218         }
    219       }
    220     }
    221 
    222     private void EnsureExistsInformationTable() {
    223       InformationAnalysisTable information = InformationParameter.ActualValue;
    224       if (information == null) {
    225         information = new InformationAnalysisTable("Information");
    226         information.Rows.Add(new DataRow("Information Content"));
    227         information.Rows.Add(new DataRow("Partial Information Content"));
    228         information.Rows.Add(new DataRow("Density Basin Information"));
    229         information.Rows.Add(new DataRow("Total Entropy"));
    230         information.Rows.Add(new DataRow("Quality Delta") {VisualProperties = {SecondYAxis = true}});
    231         InformationParameter.ActualValue = information;
    232       }
    233     }
    234 
    235     private void EnsureExistsInformationStabilityTable() {
    236       InformationStabilityTable informationStability = InformationStabilityParameter.ActualValue;
    237       if (informationStability == null) {
    238         informationStability = new InformationStabilityTable("Information Stability");
    239         informationStability.Rows.Add(new DataRow("Information Stability"));
    240         informationStability.Rows.Add(new DataRow("Relative Regularity"));
    241         informationStability.Rows.Add(new DataRow("Relative Diversity"));
    242         informationStability.Rows.Add(new DataRow("Regularity") {VisualProperties = {SecondYAxis = true}});
    243         informationStability.Rows.Add(new DataRow("Diversity") {VisualProperties = {SecondYAxis = true}});
    244         InformationStabilityParameter.ActualValue = informationStability;
    245       }
     150    private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) {
     151      IResult r;
     152      if (!results.TryGetValue(name, out r)) {
     153        results.Add(new Result(name, clone ? (IItem)item.Clone() : item));
     154      } else r.Value = clone ? (IItem)item.Clone() : item;
    246155    }
    247156  }
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/QualityTrailMultiAnalyzer.cs

    r10299 r13583  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using System.Linq;
    23 using HeuristicLab.Collections;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
     
    2725using HeuristicLab.Operators;
    2826using HeuristicLab.Optimization;
    29 using HeuristicLab.Optimization.Operators;
    3027using HeuristicLab.Parameters;
    3128using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3229using HeuristicLab.PluginInfrastructure;
     30using System.Linq;
     31
    3332namespace HeuristicLab.Analysis.FitnessLandscape {
    34 
    3533  [Item("QualityTrailAnalyzer", "An analyzer that creates a quality trail which can be further analyzed by several analyzers.")]
    3634  [StorableClass]
     
    4442    }
    4543
    46     public ValueLookupParameter<IntValue> UpdateIntervalParameter {
    47       get { return (ValueLookupParameter<IntValue>)Parameters["QualityTrailUpdateInterval"]; }
     44    public IValueLookupParameter<IntValue> UpdateIntervalParameter {
     45      get { return (IValueLookupParameter<IntValue>)Parameters["QualityTrailUpdateInterval"]; }
    4846    }
    49     public LookupParameter<IntValue> UpdateCounterParameter {
    50       get { return (LookupParameter<IntValue>)Parameters["QualityTrailUpdateCounter"]; }
     47    public ILookupParameter<IntValue> UpdateCounterParameter {
     48      get { return (ILookupParameter<IntValue>)Parameters["QualityTrailUpdateCounter"]; }
    5149    }
    52     public ValueLookupParameter<DataTable> QualityTrailParameter {
    53       get { return (ValueLookupParameter<DataTable>)Parameters["Quality Trail"]; }
     50    public ILookupParameter<DataTable> QualityTrailParameter {
     51      get { return (ILookupParameter<DataTable>)Parameters["Quality Trail"]; }
    5452    }
    55     public LookupParameter<VariableCollection> ResultsParameter {
    56       get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
     53    public ILookupParameter<ResultCollection> ResultsParameter {
     54      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
    5755    }
    58     public LookupParameter<DoubleValue> QualityParameter {
    59       get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
     56    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     57      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    6058    }
    61     public ScopeTreeLookupParameter<DoubleValue> QualitiesParameter {
    62       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Qualities"]; }
    63     }
    64     public OperatorParameter ResultsCollector {
    65       get { return (OperatorParameter)Parameters["ResultsCollector"]; }
    66     }
    67     public LookupParameter<BoolValue> MaximizationParameter {
    68       get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     59    public ILookupParameter<BoolValue> MaximizationParameter {
     60      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    6961    }
    7062
     
    7769    protected QualityTrailMultiAnalyzer(bool deserializing) : base(deserializing) { }
    7870    protected QualityTrailMultiAnalyzer(QualityTrailMultiAnalyzer original, Cloner cloner) : base(original, cloner) { }
    79 
    8071    public QualityTrailMultiAnalyzer()
    8172      : base() {
    8273      Parameters.Add(new ValueLookupParameter<IntValue>("QualityTrailUpdateInterval", "The interval at which the contained analyzers should be applied.", new IntValue(1)));
    8374      Parameters.Add(new LookupParameter<IntValue>("QualityTrailUpdateCounter", "The number of times the Analyzer was called since the last update."));
    84       Parameters.Add(new ValueLookupParameter<DataTable>("Quality Trail", "All historical quality values throughout the algorithm run"));
    85       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Single quality value from the current iteration/generation"));
    86       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Qualities", "Quality values of the whole population", "Quality", 1));
    87       Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collected results"));
    88       Parameters.Add(new OperatorParameter("ResultsCollector"));
     75      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "All historical quality values throughout the algorithm run"));
     76      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "Quality values of the whole population", 1));
     77      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collected results"));
    8978      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem"));
    9079
    91       foreach (var analyzer in ApplicationManager.Manager.GetInstances<IQualityTrailAnalyzer>())
    92         Operators.Add(analyzer);
    93 
    94       var resultsCollector = new ResultsCollector();
    95       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(QualityTrailParameter.Name));
    96       ResultsCollector.Value = resultsCollector;
     80      foreach (var analyzer in ApplicationManager.Manager.GetInstances<IQualityTrailAnalyzer>()) {
     81        Operators.Add(analyzer, !(analyzer is FitnessCloudAnalyzer));
     82      }
    9783    }
    9884
     
    10288
    10389    public override IOperation InstrumentedApply() {
    104       UpdateQualityTrail();
    105 
    106       IntValue interval = UpdateIntervalParameter.ActualValue;
    107       if (interval == null) interval = new IntValue(1);
    108 
    109       IntValue counter = UpdateCounterParameter.ActualValue;
    110       if (counter == null) {
    111         counter = new IntValue(interval.Value);
    112         UpdateCounterParameter.ActualValue = counter;
    113       } else counter.Value++;
    114 
    115       OperationCollection next = new OperationCollection();
    116       next.Add(ExecutionContext.CreateOperation(ResultsCollector.Value));
    117       if (counter.Value == interval.Value) {
    118         counter.Value = 0;
    119         foreach (IndexedItem<IQualityTrailAnalyzer> item in Operators.CheckedItems)
    120           next.Add(ExecutionContext.CreateOperation(item.Value));
    121 
    122       }
    123       next.Add(base.InstrumentedApply());
    124       return next;
    125     }
    126 
    127     private void UpdateQualityTrail() {
    128       DataTable qualityTrail = QualityTrailParameter.ActualValue;
     90      var maximization = MaximizationParameter.ActualValue.Value;
     91      var qualityTrail = QualityTrailParameter.ActualValue;
    12992      if (qualityTrail == null) {
    13093        qualityTrail = new DataTable("Quality Trail");
     
    13295        QualityTrailParameter.ActualValue = qualityTrail;
    13396      }
    134       if (QualityParameter.ActualValue != null)
    135         qualityTrail.Rows["Qualities"].Values.Add(QualityParameter.ActualValue.Value);
    136       if (QualitiesParameter.ActualName != null &&
    137         QualitiesParameter.ActualValue.Count() > 0 &&
    138         MaximizationParameter != null)
    139         if (MaximizationParameter.ActualValue.Value)
    140           qualityTrail.Rows["Qualities"].Values.Add(QualitiesParameter.ActualValue.Select(dv => dv.Value).Max());
    141         else
    142           qualityTrail.Rows["Qualities"].Values.Add(QualitiesParameter.ActualValue.Select(dv => dv.Value).Min());
     97      var qualities = QualityParameter.ActualValue.Select(x => x.Value);
     98      qualityTrail.Rows["Qualities"].Values.Add(maximization ? qualities.Max() : qualities.Min());
    14399
     100      var interval = UpdateIntervalParameter.ActualValue.Value;
     101      var counter = UpdateCounterParameter.ActualValue;
     102      if (counter == null) {
     103        counter = new IntValue(0);
     104        UpdateCounterParameter.ActualValue = counter;
     105      }
     106      counter.Value++;
     107
     108      var next = new OperationCollection();
     109      if (counter.Value % interval == 0) {
     110        counter.Value = 0;
     111        foreach (var item in Operators.CheckedItems) next.Add(ExecutionContext.CreateOperation(item.Value));
     112      }
     113      next.Add(base.InstrumentedApply());
     114      return next;
    144115    }
    145116  }
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessAnalyzer.cs

    r7176 r13583  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using System.Linq;
    23 using HeuristicLab.Analysis.FitnessLandscape.DataTables;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
    2725using HeuristicLab.Operators;
    28 using HeuristicLab.Optimization.Operators;
     26using HeuristicLab.Optimization;
    2927using HeuristicLab.Parameters;
    3028using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using System.Linq;
    3130
    32 namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
    33 
     31namespace HeuristicLab.Analysis.FitnessLandscape {
     32  [Item("Ruggedness Analyzer", "Analyzes autocorrelation for one mutation step and correlation length.")]
    3433  [StorableClass]
    35   public class RuggednessAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {
     34  public class RuggednessAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer {
    3635    public bool EnabledByDefault {
    3736      get { return false; }
     
    4241      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
    4342    }
    44     public LookupParameter<DataTable> CorrelationLengthTableParameter {
    45       get { return (LookupParameter<DataTable>)Parameters["CorrelationLengthTable"]; }
    46     }
    47     public LookupParameter<AutoCorrelationTable> AutocorrelationParameter {
    48       get { return (LookupParameter<AutoCorrelationTable>)Parameters["Autocorrelation"]; }
    49     }
    50     public LookupParameter<VariableCollection> ResultsParameter {
    51       get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
     43    public LookupParameter<ResultCollection> ResultsParameter {
     44      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
    5245    }
    5346    public LookupParameter<DoubleValue> AutoCorrelation1Parameter {
     
    6255    protected RuggednessAnalyzer(bool deserializing) : base(deserializing) { }
    6356    protected RuggednessAnalyzer(RuggednessAnalyzer original, Cloner cloner) : base(original, cloner) { }
    64 
    6557    public RuggednessAnalyzer() {
    6658      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The quality of the solution"));
    67       Parameters.Add(new LookupParameter<DataTable>("CorrelationLengthTable", "Maximum nr of steps between statistically significantly correlated quality values"));
    68       Parameters.Add(new LookupParameter<AutoCorrelationTable>("Autocorrelation", "Autocorrelation function of successive quality values"));
    69       Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
     59      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
    7060      Parameters.Add(new LookupParameter<DoubleValue>("AutoCorrelation1", "Autocorrelation for one mutation step."));
    7161      Parameters.Add(new LookupParameter<IntValue>("CorrelationLength", "The correlation length."));
    72 
    73       var resultsCollector = new ResultsCollector();
    74       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(CorrelationLengthTableParameter.Name));
    75       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(AutocorrelationParameter.Name));
    76       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(AutoCorrelation1Parameter.Name));
    77       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(CorrelationLengthParameter.Name));
    78 
    79       OperatorGraph.InitialOperator = resultsCollector;
    80       resultsCollector.Successor = null;
    8162    }
    8263
     
    8667
    8768    public override IOperation Apply() {
    88       DataTable correlationLengthTable = GetOrCreateCorrelationLengthTable();
    89       AutoCorrelationTable autocorrelationTable = GetOrCreateAutoCorrelationTable();
    90       DataTable qualityTrail = QualityTrailParameter.ActualValue;
    91       if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
    92         double[] autocorrelationValues;
    93         int correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues);
    94         correlationLengthTable.Rows["Correlation Length"].Values.Add(correlationLength);
    95         autocorrelationTable.Rows["Auto Correlation"].Values.Clear();
    96         autocorrelationTable.Rows["Auto Correlation"].Values.AddRange(autocorrelationValues);
    97         CorrelationLengthParameter.ActualValue = new IntValue(correlationLength);
    98         AutoCorrelation1Parameter.ActualValue = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0);
    99       }
     69      var qualityTrail = QualityTrailParameter.ActualValue;
     70      if (qualityTrail == null || qualityTrail.Rows.Count <= 0) return base.Apply();
     71      var results = ResultsParameter.ActualValue;
     72      double[] autocorrelationValues;
     73      var correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues);
     74      var cl = new IntValue(correlationLength);
     75      CorrelationLengthParameter.ActualValue = cl;
     76      AddOrUpdateResult(results, CorrelationLengthParameter.Name, cl);
     77      var ac1 = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0);
     78      AutoCorrelation1Parameter.ActualValue = ac1;
     79      AddOrUpdateResult(results, AutoCorrelation1Parameter.Name, ac1);
    10080      return base.Apply();
    10181    }
    10282
    103     private AutoCorrelationTable GetOrCreateAutoCorrelationTable() {
    104       AutoCorrelationTable autocorrelationTable = AutocorrelationParameter.ActualValue;
    105       if (autocorrelationTable == null) {
    106         autocorrelationTable = new AutoCorrelationTable("Auto Correlation");
    107         AutocorrelationParameter.ActualValue = autocorrelationTable;
    108         var row = new DataRow("Auto Correlation");
    109         row.VisualProperties.StartIndexZero = true;
    110         autocorrelationTable.Rows.Add(row);
    111       }
    112       return autocorrelationTable;
    113     }
    114 
    115     private DataTable GetOrCreateCorrelationLengthTable() {
    116       DataTable correlationLengthTable = CorrelationLengthTableParameter.ActualValue;
    117       if (correlationLengthTable == null) {
    118         correlationLengthTable = new DataTable("Correlation Length");
    119         CorrelationLengthTableParameter.ActualValue = correlationLengthTable;
    120         correlationLengthTable.Rows.Add(new DataRow("Correlation Length"));
    121       }
    122       return correlationLengthTable;
     83    private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) {
     84      IResult r;
     85      if (!results.TryGetValue(name, out r)) {
     86        results.Add(new Result(name, clone ? (IItem)item.Clone() : item));
     87      } else r.Value = clone ? (IItem)item.Clone() : item;
    12388    }
    12489  }
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessCalculator.cs

    r13484 r13583  
    1 using System;
    2 using System.Linq;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 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
    322using HeuristicLab.Common;
    423using HeuristicLab.Core;
     
    726using HeuristicLab.Parameters;
    827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using System;
    929using System.Collections.Generic;
     30using System.Linq;
    1031
    11 namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
     32namespace HeuristicLab.Analysis.FitnessLandscape {
    1233  [Item("Ruggedness Calculator", "Calculates ruggedness descriptors froma given quality trail.")]
    1334  [StorableClass]
     
    2546    }
    2647    #endregion
    27 
    2848
    2949    #region Constructors & Cloning
     
    5878      alglib.basestat.samplemoments(qualities, qualities.Length, ref mean, ref variance, ref skewness, ref kurtosis);
    5979      List<double> autocorrelation = new List<double>() { 1.0 };
    60       double bound = Math.Min(2 / Math.Sqrt(qualities.Length), 1.0);
    61       int correlationLength = 1;
    62       for (; correlationLength < qualities.Length; correlationLength++) {
    63         double value = correlations[correlationLength]/qualities.Length - mean * mean;
     80      int correlationLength = -1, counter = 1;
     81      for (; counter < qualities.Length / 2; counter++) {
     82        double value = correlations[counter] / qualities.Length - mean * mean;
    6483        if (variance > 0)
    65           value = Math.Max(Math.Min(value/variance, 1.0), -1.0);
     84          value = Math.Max(Math.Min(value / variance, 1.0), -1.0);
    6685        else
    6786          value = 1;
    6887        autocorrelation.Add(value);
    69         if (Math.Abs(value) < bound) break;
     88        if (value < 0 && correlationLength < 0) correlationLength = counter;
    7089      }
    7190      acf = autocorrelation.ToArray();
    72       return correlationLength-1;
     91      return correlationLength - 1;
    7392    }
    7493
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/UniqueThresholdCalculator.cs

    r7128 r13583  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 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.Diagnostics;
    225using System.Linq;
    3 using System.Collections.Generic;
    4 using System.Text;
    5 using System.Diagnostics;
    626
    7 namespace HeuristicLab.Analysis {
     27namespace HeuristicLab.Analysis.FitnessLandscape {
    828
    929  public static class UniqueThresholdCalculator {
     
    6181      } else {
    6282        double min = thresholds[0];
    63         double max = thresholds[thresholds.Count-1];
     83        double max = thresholds[thresholds.Count - 1];
    6484        if (min == max) {
    6585          yield return min;
    6686        } else {
    6787          yield return min;
    68           foreach (var t in DetermineInnerThresholds(thresholds, n-2))
     88          foreach (var t in DetermineInnerThresholds(thresholds, n - 2))
    6989            yield return t;
    7090          yield return max;
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/UpDownWalkAnalyzer.cs

    r7176 r13583  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Drawing;
    24 using System.Linq;
    25 using HeuristicLab.Collections;
    2622using HeuristicLab.Common;
    2723using HeuristicLab.Core;
    2824using HeuristicLab.Data;
    2925using HeuristicLab.Operators;
    30 using HeuristicLab.Optimization.Operators;
     26using HeuristicLab.Optimization;
    3127using HeuristicLab.Parameters;
    3228using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using System.Linq;
    3330
    34 namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
    35 
     31namespace HeuristicLab.Analysis.FitnessLandscape {
     32  [Item("Up/Down Walk Analyzer", "Analyzes the quality trail produced from an up/down walk.")]
    3633  [StorableClass]
    37   public class UpDownWalkAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {
     34  public class UpDownWalkAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer {
    3835    public bool EnabledByDefault {
    3936      get { return false; }
     
    4441      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
    4542    }
    46     public LookupParameter<VariableCollection> ResultsParameter {
    47       get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
    48     }
    49     public LookupParameter<DataTable> UpDownStepsParameter {
    50       get { return (LookupParameter<DataTable>)Parameters["UpDownSteps"]; }
    51     }
    52     public LookupParameter<DataTable> UpDownLevelsParameter {
    53       get { return (LookupParameter<DataTable>)Parameters["UpDownLevels"]; }
     43    public LookupParameter<ResultCollection> ResultsParameter {
     44      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
    5445    }
    5546    public LookupParameter<DoubleValue> UpWalkLengthParameter {
     
    6556      get { return (LookupParameter<DoubleValue>)Parameters["DownWalkLenVar"]; }
    6657    }
    67     public LookupParameter<DoubleValue> UpperLevelParameter {
    68       get { return (LookupParameter<DoubleValue>)Parameters["UpperLevel"]; }
    69     }
    70     public LookupParameter<DoubleValue> LowerLevelParameter {
    71       get { return (LookupParameter<DoubleValue>)Parameters["LowerLevel"]; }
    72     }
    7358    public LookupParameter<DoubleValue> UpperVarianceParameter {
    7459      get { return (LookupParameter<DoubleValue>)Parameters["UpperVariance"]; }
     
    8267    protected UpDownWalkAnalyzer(bool deserializing) : base(deserializing) { }
    8368    protected UpDownWalkAnalyzer(UpDownWalkAnalyzer original, Cloner cloner) : base(original, cloner) { }
    84 
    8569    public UpDownWalkAnalyzer() {
    8670      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
    87       Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
    88       Parameters.Add(new LookupParameter<DataTable>("UpDownSteps", "Distribution of upward and downward steps between extremes."));
    89       Parameters.Add(new LookupParameter<DataTable>("UpDownLevels", "Distribution of upper and lower levels in up-down walks."));
     71      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
    9072      Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLength", "Average downward walk length."));
    9173      Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLength", "Average updward walk length."));
    9274      Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLenVar", "Upward walk length variance."));
    9375      Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLenVar", "Downward walk length variance."));
    94       Parameters.Add(new LookupParameter<DoubleValue>("UpperLevel", "Average maximum fitness value."));
    95       Parameters.Add(new LookupParameter<DoubleValue>("LowerLevel", "Average minimum fitness value."));
    9676      Parameters.Add(new LookupParameter<DoubleValue>("LowerVariance", "Lower level variance."));
    9777      Parameters.Add(new LookupParameter<DoubleValue>("UpperVariance", "Upper level variance."));
    98    
    99 
    100       var resultsCollector = new ResultsCollector();
    101       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(UpDownStepsParameter.Name));
    102       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(UpDownLevelsParameter.Name));
    103       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DownWalkLengthParameter.Name));
    104       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpWalkLengthParameter.Name));
    105       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpWalkLenVarParameter.Name));
    106       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DownWalkLenVarParameter.Name));
    107       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpperLevelParameter.Name));
    108       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(LowerLevelParameter.Name));
    109       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpperVarianceParameter.Name));
    110       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(LowerVarianceParameter.Name));
    111 
    112       OperatorGraph.InitialOperator = resultsCollector;
    113       resultsCollector.Successor = null;
    11478    }
    11579
     
    11983
    12084    public override IOperation Apply() {
    121       var stepsTable = GetOrCreateTable(UpDownStepsParameter, "Up", "Down");
    122       var levelsTable = GetOrCreateTable(UpDownLevelsParameter, "Top", "Bottom");
    123       DataTable qualityTrail = QualityTrailParameter.ActualValue;
     85      var qualityTrail = QualityTrailParameter.ActualValue;
    12486      if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
    12587        var qualities = qualityTrail.Rows.First().Values.ToList();
    12688        if (qualities.Count > 2) {
     89          var results = ResultsParameter.ActualValue;
    12790          var extremes = qualities
    128             .Delta((a, b) => new {a, b, diff = b - a})
    129             .Select((p, i) => new {p.a, p.b, p.diff, i = i+1})
     91            .Delta((a, b) => new { a, b, diff = b - a })
     92            .Select((p, i) => new { p.a, p.b, p.diff, i = i + 1 })
    13093            .Delta((s1, s2) => new {
    13194              s1.i,
     
    143106          var maxima = extremes.Where(x => x.top).ToList();
    144107          var minima = extremes.Where(x => x.bottom).ToList();
    145           var tops = Enumerable.Repeat(new {length = 0, value = 0.0}, 0).ToList();
     108          var tops = Enumerable.Repeat(new { length = 0, value = 0.0 }, 0).ToList();
    146109          var bottoms = tops;
    147110          if (maxima.Count > 0 && minima.Count > 0) {
    148111            if (maxima.First().i < minima.First().i) {
    149               bottoms = maxima.Zip(minima, (t, b) => new {length = b.i - t.i, b.value}).ToList();
    150               minima.Insert(0, new {i = -1, value = 0.0, top = false, bottom = false});
    151               tops = maxima.Zip(minima, (t, b) => new {length = t.i - b.i, t.value}).ToList();
     112              bottoms = maxima.Zip(minima, (t, b) => new { length = b.i - t.i, b.value }).ToList();
     113              minima.Insert(0, new { i = -1, value = 0.0, top = false, bottom = false });
     114              tops = maxima.Zip(minima, (t, b) => new { length = t.i - b.i, t.value }).ToList();
    152115            } else {
    153               tops = maxima.Zip(minima, (t, b) => new {length = t.i - b.i, t.value}).ToList();
    154               maxima.Insert(0, new {i = -1, value = 0.0, top = false, bottom = false});
    155               bottoms = maxima.Zip(minima, (t, b) => new {length = b.i - t.i, b.value}).ToList();
     116              tops = maxima.Zip(minima, (t, b) => new { length = t.i - b.i, t.value }).ToList();
     117              maxima.Insert(0, new { i = -1, value = 0.0, top = false, bottom = false });
     118              bottoms = maxima.Zip(minima, (t, b) => new { length = b.i - t.i, b.value }).ToList();
    156119            }
    157120            if (tops.Count > 0) {
    158               var topLengths = tops.Select(t => (double) t.length).ToList();
     121              var topLengths = tops.Select(t => (double)t.length).ToList();
    159122              var topVals = tops.Select(t => t.value).ToList();
    160               ReplaceHistogram(stepsTable.Rows["Up"], topLengths);
    161               ReplaceHistogram(levelsTable.Rows["Top"], topVals);
    162               UpperLevelParameter.ActualValue = new DoubleValue(topVals.Average());
    163               UpperVarianceParameter.ActualValue = new DoubleValue(topVals.Variance());
    164               UpWalkLengthParameter.ActualValue = new DoubleValue(topLengths.Average());
    165               UpWalkLenVarParameter.ActualValue = new DoubleValue(topLengths.Variance());
     123              var uv = new DoubleValue(topVals.Variance());
     124              UpperVarianceParameter.ActualValue = uv;
     125              AddOrUpdateResult(results, UpperVarianceParameter.Name, uv);
     126              var ul = new DoubleValue(topLengths.Average());
     127              UpWalkLengthParameter.ActualValue = ul;
     128              AddOrUpdateResult(results, UpWalkLengthParameter.Name, ul);
     129              var ulv = new DoubleValue(topLengths.Variance());
     130              UpWalkLenVarParameter.ActualValue = ulv;
     131              AddOrUpdateResult(results, UpWalkLenVarParameter.Name, ulv);
    166132            }
    167133            if (bottoms.Count > 0) {
    168               var bottomLengths = bottoms.Select(b => (double) b.length).ToList();
     134              var bottomLengths = bottoms.Select(b => (double)b.length).ToList();
    169135              var bottomVals = bottoms.Select(b => b.value).ToList();
    170               ReplaceHistogram(stepsTable.Rows["Down"], bottomLengths);
    171               ReplaceHistogram(levelsTable.Rows["Bottom"], bottomVals);
    172               LowerLevelParameter.ActualValue = new DoubleValue(bottomVals.Average());
    173               LowerVarianceParameter.ActualValue = new DoubleValue(bottomVals.Variance());
    174               DownWalkLengthParameter.ActualValue = new DoubleValue(bottomLengths.Average());
    175               DownWalkLenVarParameter.ActualValue = new DoubleValue(bottomLengths.Variance());
     136              var lv = new DoubleValue(bottomVals.Variance());
     137              LowerVarianceParameter.ActualValue = lv;
     138              AddOrUpdateResult(results, LowerVarianceParameter.Name, lv);
     139              var dl = new DoubleValue(bottomLengths.Average());
     140              DownWalkLengthParameter.ActualValue = dl;
     141              AddOrUpdateResult(results, DownWalkLengthParameter.Name, dl);
     142              var dlv = new DoubleValue(bottomLengths.Variance());
     143              DownWalkLenVarParameter.ActualValue = dlv;
     144              AddOrUpdateResult(results, DownWalkLenVarParameter.Name, dlv);
    176145            }
    177146          }
     
    181150    }
    182151
    183     private void ReplaceHistogram(DataRow row, IEnumerable<double> values) {
    184       row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    185       row.VisualProperties.Bins = 25;
    186       row.Values.Clear();
    187       row.Values.AddRange(values);
    188     }
    189 
    190     private DataTable GetOrCreateTable(LookupParameter<DataTable> tableParameter, params string[] rowNames) {
    191       DataTable table = tableParameter.ActualValue;
    192       if (table == null) {
    193         table = new DataTable(tableParameter.Name, tableParameter.Description);
    194         tableParameter.ActualValue = table;
    195         foreach (var name in rowNames) {
    196           table.Rows.Add(new DataRow(name));
    197         }
    198       }
    199       return table;
     152    private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) {
     153      IResult r;
     154      if (!results.TryGetValue(name, out r)) {
     155        results.Add(new Result(name, clone ? (IItem)item.Clone() : item));
     156      } else r.Value = clone ? (IItem)item.Clone() : item;
    200157    }
    201158  }
Note: See TracChangeset for help on using the changeset viewer.