Changeset 6903 for trunk/sources
- Timestamp:
- 10/12/11 11:27:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionDiscretizer.cs
r6690 r6903 50 50 public RunCollectionDiscretizer() { 51 51 Parameters.Add(new ValueParameter<StringValue>("Source", "Source value name to be fuzzified.", new StringValue("Value"))); 52 Parameters.Add(new ValueParameter<StringValue>("Target", "Target value name. The new, fuzzified variable to be created.", new StringValue("Calc.Value"))); 53 Parameters.Add(new ValueParameter<DoubleValue>("Spread", "The number of standard deviations considered one additional level. ", new DoubleValue(1)));52 Parameters.Add(new ValueParameter<StringValue>("Target", "Target value name. The new, fuzzified variable to be created.", new StringValue("Calc.Value"))); 53 Parameters.Add(new ValueParameter<DoubleValue>("Spread", "The number of standard deviations considered one additional level. Set to zero to use empirical distribution instead.", new DoubleValue(1))); 54 54 Parameters.Add(new ValueParameter<StringValue>("GroupBy", "Create separate analyzes for different values of this variable.", new StringValue(""))); 55 55 Parameters.Add(new ValueParameter<ItemList<StringValue>>("Levels", "The list of levels to be assigned.", … … 101 101 var values = group.Select(r => r.Value).ToList(); 102 102 if (values.Count > 0) { 103 var avg = values.Average(); 104 var stdDev = values.StandardDeviation(); 105 foreach (var r in group) { 106 r.Run.Results[Target] = new StringValue(Fuzzify(r.Value, avg, stdDev)); 103 if (Spread > 0) { 104 var avg = values.Average(); 105 var stdDev = values.StandardDeviation(); 106 foreach (var r in group) { 107 r.Run.Results[Target] = new StringValue(Discretize(r.Value, avg, stdDev)); 108 } 109 } else { 110 values.Sort(); 111 var a = values.ToArray(); 112 foreach (var r in group) { 113 r.Run.Results[Target] = new StringValue(Discretize(r.Value, a)); 114 } 107 115 } 108 116 } … … 141 149 } 142 150 143 private string Fuzzify(double value, double avg, double stdDev) {151 private string Discretize(double value, double avg, double stdDev) { 144 152 double dev = (value - avg)/(stdDev*Spread); 145 153 int index; … … 157 165 } 158 166 167 private string Discretize(double value, double[] values) { 168 var index = Array.BinarySearch(values, value); 169 var pos = 1.0*(index < 0 ? ~index : index)/(values.Length-1); 170 return Levels[Math.Min(Levels.Count - 1, Math.Max(0, (int) Math.Round(pos*(Levels.Count-1))))]; 171 } 172 159 173 #endregion 160 174 }
Note: See TracChangeset
for help on using the changeset viewer.