Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Algorithms/RepeatedUpDownWalkAnalyzer.cs @ 17282

Last change on this file since 17282 was 16995, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

File size: 4.6 KB
Line 
1using System.Linq;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HEAL.Attic;
9
10namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms {
11
12  [Item("RepeatedUpDownWalkAnalyzer", "Analyzes and consolidates repeated up down walk analyses.")]
13  [StorableType("1B832D9F-7D75-41AB-94D1-D638F4067CC0")]
14  public class RepeatedUpDownWalkAnalyzer : SingleSuccessorOperator, IRepeatsAnalyzer {
15
16    #region Parameters
17    public ScopeTreeLookupParameter<DoubleValue> DownWalkLengthValuesParameter {
18      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["DownWalkLengthValues"]; }
19    }
20    public ScopeTreeLookupParameter<DoubleValue> UpWalkLengthValuesParameter {
21      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["UpWalkLengthValues"]; }
22    }
23    public ScopeTreeLookupParameter<DoubleValue> DownWalkLenVarValuesParameter {
24      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["DownWalkLenVarValues"]; }
25    }
26    public ScopeTreeLookupParameter<DoubleValue> UpWalkLenVarValuesParameter {
27      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["UpWalkLenVarValues"]; }
28    }
29    public LookupParameter<DoubleValue> DownWalkLengthParameter {
30      get { return (LookupParameter<DoubleValue>)Parameters["DownWalkLength"]; }
31    }
32    public LookupParameter<DoubleValue> UpWalkLengthParameter {
33      get { return (LookupParameter<DoubleValue>)Parameters["UpWalkLength"]; }
34    }
35    public LookupParameter<DoubleValue> DownWalkLenVarParameter {
36      get { return (LookupParameter<DoubleValue>)Parameters["DownWalkLenVar"]; }
37    }
38    public LookupParameter<DoubleValue> UpWalkLenVarParameter {
39      get { return (LookupParameter<DoubleValue>)Parameters["UpWalkLenVar"]; }
40    }
41    public LookupParameter<ResultCollection> ResultsParameter {
42      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
43    }
44    #endregion
45
46    #region Construction & Cloning
47    [StorableConstructor]
48    protected RepeatedUpDownWalkAnalyzer(StorableConstructorFlag _) : base(_) { }
49    protected RepeatedUpDownWalkAnalyzer(RepeatedUpDownWalkAnalyzer original, Cloner cloner) : base(original, cloner) { }
50    public RepeatedUpDownWalkAnalyzer() {
51      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("DownWalkLengthValues", "average down length values of repeats.", "DownWalkLength", 2));
52      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("UpWalkLengthValues", "average up walk length values of repeats.", "UpWalkLength", 2));
53      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("DownWalkLenVarValues", "down length variance values of repeats.", "DownWalkLenVar", 2));
54      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("UpWalkLenVarValues", "down length variance values of repeats.", "UpWalkLenVar", 2));
55
56      Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLength", "Consolidated average down walk length."));
57      Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLength", "Consolidated average up walk length."));
58      Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLenVar", "Consolidated down walk length variance."));
59      Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLenVar", "Consolidated up walk length variance."));
60
61      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results."));
62    }
63    public override IDeepCloneable Clone(Cloner cloner) {
64      return new RepeatedUpDownWalkAnalyzer(this, cloner);
65    }
66    #endregion
67
68    public override IOperation Apply() {
69      AggregateValues(DownWalkLengthValuesParameter, DownWalkLengthParameter);
70      AggregateValues(UpWalkLengthValuesParameter, UpWalkLengthParameter);
71      AggregateValues(DownWalkLenVarValuesParameter, DownWalkLenVarParameter);
72      AggregateValues(UpWalkLenVarValuesParameter, UpWalkLenVarParameter);
73      return base.Apply();
74    }
75
76    private void AggregateValues(ILookupParameter<ItemArray<DoubleValue>> valuesParameter, ILookupParameter<DoubleValue> averageParameter) {
77      var results = ResultsParameter.ActualValue;
78      var values = valuesParameter.ActualValue.Select(v => v.Value).ToList();
79      if (values.Count > 0) {
80        var avg = new DoubleValue(values.Average());
81        averageParameter.ActualValue = avg;
82        results.Remove(averageParameter.ActualName);
83        results.Add(new Result(averageParameter.ActualName, avg));
84      }
85    }
86
87  }
88}
Note: See TracBrowser for help on using the repository browser.