[7128] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Optimization;
|
---|
| 7 | using HeuristicLab.Data;
|
---|
| 8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 9 | using HeuristicLab.Common;
|
---|
| 10 | using HeuristicLab.Common.Resources;
|
---|
| 11 | using HeuristicLab.Analysis.FitnessLandscape.DataTables;
|
---|
| 12 | using System.Drawing;
|
---|
| 13 | using HeuristicLab.Analysis.FitnessLandscape.Analysis;
|
---|
| 14 |
|
---|
| 15 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
| 16 |
|
---|
| 17 | [Item("Ruggedness Aggregator", "Aggregates scalar ruggedness analyses.")]
|
---|
| 18 | [StorableClass]
|
---|
| 19 | public class RuggednessAggregator : NamedItem, IAggregator {
|
---|
| 20 |
|
---|
[7202] | 21 | public static new Image StaticItemImage { get { return VSImageLibrary.Database; } }
|
---|
[7128] | 22 | public override bool CanChangeName { get { return false; } }
|
---|
| 23 |
|
---|
| 24 | private List<double> correlationLengthValues = new List<double>();
|
---|
| 25 | private List<double> autocorrelations = new List<double>();
|
---|
| 26 |
|
---|
| 27 | #region Construction & Cloning
|
---|
| 28 | [StorableConstructor]
|
---|
| 29 | protected RuggednessAggregator(bool deserializing) : base(deserializing) { }
|
---|
| 30 | protected RuggednessAggregator(RuggednessAggregator original, Cloner cloner) : base(original, cloner) {
|
---|
| 31 | autocorrelations = original.autocorrelations.ToList();
|
---|
| 32 | correlationLengthValues = original.correlationLengthValues.ToList();
|
---|
| 33 | }
|
---|
| 34 | public RuggednessAggregator() {
|
---|
| 35 | name = ItemName;
|
---|
| 36 | description = ItemDescription;
|
---|
| 37 | }
|
---|
| 38 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 39 | return new RuggednessAggregator(this, cloner);
|
---|
| 40 | }
|
---|
| 41 | #endregion
|
---|
| 42 |
|
---|
| 43 | #region IAggregator interface
|
---|
| 44 | public virtual void MaybeAddResult(IResult result) {
|
---|
| 45 | MaybeAddAutoCorrelation1(result);
|
---|
| 46 | MaybeAddCorrelationLength(result);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public virtual IResult CreateResult() {
|
---|
| 50 | var results = new ResultCollection();
|
---|
| 51 | results.AddRange(CreateSummary("AutoCorrelation1", autocorrelations));
|
---|
| 52 | results.AddRange(CreateSummary("CorrelationLength", correlationLengthValues.Select(l => (double)l)));
|
---|
| 53 | return new Result("Ruggedness", results);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public virtual void Reset() {
|
---|
| 57 | autocorrelations.Clear();
|
---|
| 58 | correlationLengthValues.Clear();
|
---|
| 59 | }
|
---|
| 60 | #endregion
|
---|
| 61 |
|
---|
| 62 | private void MaybeAddAutoCorrelation1(IResult result) {
|
---|
| 63 | if (result.Name != "AutoCorrelation1")
|
---|
| 64 | return;
|
---|
| 65 | DoubleValue autocorrelation1 = result.Value as DoubleValue;
|
---|
| 66 | if (autocorrelation1 != null)
|
---|
| 67 | autocorrelations.Add(autocorrelation1.Value);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private void MaybeAddCorrelationLength(IResult result) {
|
---|
| 71 | if (result.Name != "CorrelationLength")
|
---|
| 72 | return;
|
---|
| 73 | IntValue correlationLength = result.Value as IntValue;
|
---|
| 74 | if (correlationLength != null)
|
---|
| 75 | correlationLengthValues.Add(correlationLength.Value);
|
---|
| 76 | else {
|
---|
| 77 | DoubleValue correlationLength2 = result.Value as DoubleValue;
|
---|
| 78 | if (correlationLength2 != null)
|
---|
| 79 | correlationLengthValues.Add(correlationLength2.Value);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | private IEnumerable<IResult> CreateSummary(string name, IEnumerable<double> values) {
|
---|
| 84 | DistributionAnalyzer analyzer = new DistributionAnalyzer(values);
|
---|
| 85 | return new[] {
|
---|
| 86 | new Result(name + " Avg", new DoubleValue(analyzer.Mean)),
|
---|
| 87 | new Result(name + " Quartile-Spread", new DoubleValue(analyzer[0.75]-analyzer[0.25])),
|
---|
| 88 | new Result(name + " 90%-Spread", new DoubleValue(analyzer[0.95]-analyzer[0.05])),
|
---|
| 89 | new Result(name + " Range", new DoubleValue(analyzer[1]-analyzer[0])),
|
---|
| 90 | };
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | }
|
---|
| 96 | }
|
---|