Changeset 6668
- Timestamp:
- 08/17/11 17:52:09 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionFuzzifier.cs
r6665 r6668 30 30 get { return (ValueParameter<DoubleValue>)Parameters["Spread"]; } 31 31 } 32 public ValueParameter<StringValue> GroupByParameter { 33 get { return (ValueParameter<StringValue>)Parameters["GroupBy"]; } 34 } 32 35 public ValueParameter<ItemList<StringValue>> LevelsParameter { 33 36 get { return (ValueParameter<ItemList<StringValue>>)Parameters["Levels"]; } 34 } 37 } 35 38 #endregion 36 39 … … 39 42 private string Suffix { get { return SuffixParameter.Value.Value; } } 40 43 private double Spread { get { return SpreadParameter.Value.Value; } } 44 private string GroupBy { get { return GroupByParameter.Value.Value; } } 41 45 private List<string> Levels { get { return LevelsParameter.Value.Select(v => v.Value).ToList(); } } 42 46 … … 52 56 Parameters.Add(new ValueParameter<StringValue>("Suffix", "The suffix of all fuzzified values.", new StringValue())); 53 57 Parameters.Add(new ValueParameter<DoubleValue>("Spread", "The number of standard deviations considered one additional level.", new DoubleValue(1))); 58 Parameters.Add(new ValueParameter<StringValue>("GroupBy", "Create separate analyzes for different values of this variable.", new StringValue(""))); 54 59 Parameters.Add(new ValueParameter<ItemList<StringValue>>("Levels", "The list of levels to be assigned.", 55 60 new ItemList<StringValue> { … … 59 64 new StringValue("High"), 60 65 new StringValue("Very High"), 61 })); 66 })); 62 67 RegisterEvents(); 63 68 UpdateName(); … … 76 81 TargetParameter.ToStringChanged += Parameter_NameChanged; 77 82 SuffixParameter.ToStringChanged += Parameter_NameChanged; 83 GroupByParameter.ToStringChanged += Parameter_NameChanged; 78 84 } 79 85 … … 83 89 84 90 private void UpdateName() { 85 name = string.Format("{0} := Fuzzy({1}) {2}", Target,Source, Suffix); 91 name = string.Format("{0} := Fuzzy({1}) {3}", 92 Target, 93 Source, 94 string.IsNullOrWhiteSpace(GroupBy) ? "" : string.Format("/{0}", GroupBy), 95 Suffix); 86 96 OnNameChanged(); 87 97 } … … 90 100 91 101 public void Modify(List<IRun> runs) { 92 var values = 93 (from run in runs 94 select GetSourceValue(run) into value 95 where value.HasValue 96 select value.Value).ToList(); 97 if (values.Count == 0) 98 return; 99 var avg = values.Average(); 100 var stdDev = values.StandardDeviation(); 101 foreach (var run in runs) { 102 double? value = GetSourceValue(run); 103 if (value.HasValue) { 104 run.Results[Target] = new StringValue(Fuzzify(value.Value, avg, stdDev)); 102 foreach (var group in runs 103 .Select(r => new {Run=r, Value=GetSourceValue(r)}) 104 .Where(r => r.Value.HasValue && !double.IsNaN(r.Value.Value) && !double.IsInfinity(r.Value.Value)) 105 .Select(r => new {r.Run, r.Value.Value, Bin=GetGroupByValue(r.Run)}) 106 .GroupBy(r => r.Bin).ToList()) { 107 var values = group.Select(r => r.Value).ToList(); 108 if (values.Count > 0) { 109 var avg = values.Average(); 110 var stdDev = values.StandardDeviation(); 111 foreach (var r in group) { 112 r.Run.Results[Target] = new StringValue(Fuzzify(r.Value, avg, stdDev)); 113 } 105 114 } 106 115 } … … 109 118 private double? GetSourceValue(IRun run) { 110 119 return CastSourceValue(run.Results) ?? CastSourceValue(run.Parameters); 120 } 121 122 private string GetGroupByValue(IRun run) { 123 if (string.IsNullOrWhiteSpace(GroupBy)) 124 return String.Empty; 125 IItem value; 126 run.Results.TryGetValue(GroupBy, out value); 127 if (value == null) 128 run.Parameters.TryGetValue(GroupBy, out value); 129 if (value != null) 130 return value.ToString(); 131 else 132 return String.Empty; 111 133 } 112 134 … … 129 151 int index; 130 152 if (Levels.Count % 2 == 1) { 131 index = (int) Math.Floor(Math.Abs(dev)); 132 index = (Levels.Count - 1)/2 + Math.Sign(dev) * index; 153 index = (int) Math.Floor(Math.Abs(dev)); 154 index = (Levels.Count - 1)/2 + Math.Sign(dev) * index; 133 155 } else { 134 156 index = (int) Math.Ceiling(Math.Abs(dev)); … … 136 158 index = Levels.Count/2 + index; 137 159 else 138 index = Levels.Count/2 + 1 - index; 139 } 160 index = Levels.Count/2 + 1 - index; 161 } 140 162 return Levels[Math.Min(Levels.Count - 1, Math.Max(0, index))]; 141 163 }
Note: See TracChangeset
for help on using the changeset viewer.