Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6903 for trunk/sources


Ignore:
Timestamp:
10/12/11 11:27:53 (13 years ago)
Author:
epitzer
Message:

#1622 Enable discretization by empirical distribution's quantiles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionDiscretizer.cs

    r6690 r6903  
    5050    public RunCollectionDiscretizer() {
    5151      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)));
    5454      Parameters.Add(new ValueParameter<StringValue>("GroupBy", "Create separate analyzes for different values of this variable.", new StringValue("")));
    5555      Parameters.Add(new ValueParameter<ItemList<StringValue>>("Levels", "The list of levels to be assigned.",
     
    101101        var values = group.Select(r => r.Value).ToList();
    102102        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            }
    107115          }
    108116        }
     
    141149    }
    142150
    143     private string Fuzzify(double value, double avg, double stdDev) {
     151    private string Discretize(double value, double avg, double stdDev) {
    144152      double dev = (value - avg)/(stdDev*Spread);
    145153      int index;
     
    157165    }
    158166
     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
    159173    #endregion
    160174  }
Note: See TracChangeset for help on using the changeset viewer.