Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/09 13:26:48 (15 years ago)
Author:
cbahner
Message:

#519 implemented performance improvements for avg aggregators

Location:
trunk/sources/HeuristicLab.Visualization/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/3.2/AvgAggregator.cs

    r1530 r1605  
    2626
    2727    private void dataRow_ValueChanged(IDataRow row, double value, int index, Action action) {
    28       refreshValue(value);
     28      switch (action) {
     29        case Action.Added:
     30          refreshValue(value, action);
     31          break;
     32        case Action.Modified:
     33          refreshValue();
     34          break;
     35        case Action.Deleted:
     36          refreshValue(value, action);
     37          break;
     38        default:
     39          throw new ArgumentOutOfRangeException("action");
     40      }
     41
     42
    2943    }
    3044
    3145    private void dataRow_ValuesChanged(IDataRow row, double[] values, int index, Action action) {
    3246      for (int i = 0; i < values.Length; i++) {
    33         refreshValue(values[i]);
     47        refreshValue();
    3448      }
    3549    }
    3650
    3751    private void dataRow_DataRowChanged(IDataRow row) {
    38       refreshValue(double.MinValue);
     52      refreshValue();
    3953    }
    4054
    41     private void refreshValue(double newVal) {
    42       //alle durchlaufen und neues min berechnen; verbesserung: merken in welcher row lowest wert steckt
     55    private int count;
     56   
     57    public AvgAggregator() {
     58      curAvgValue = 0;
     59      count = 0;
     60    }
    4361
     62    private void refreshValue() {
    4463      curAvgValue = double.MinValue;
    4564      double tmpSum = 0;
    46       int count = 0;
     65      count = 0;
    4766      foreach (IDataRow rows in dataRowWatches) {
    4867        for (int i = 0; i < rows.Count; i++) {
     
    5170        }
    5271      }
    53       curAvgValue = tmpSum/count;
    54       // evtl nur feuern wenn sich geändert hat (jedes mal?)
     72      if (count == 0) curAvgValue = 0;
     73      else curAvgValue = tmpSum / count;
     74      OnValueChanged(curAvgValue, 0, Action.Modified);
     75    }
     76    private void refreshValue(double newVal, Action action) {
     77      double temp = curAvgValue * count;
     78
     79      switch (action) {
     80        case Action.Added:
     81          temp += newVal;
     82          count++;
     83          break;
     84        case Action.Modified:
     85          throw new InvalidOperationException();
     86        case Action.Deleted:
     87          temp -= newVal;
     88          count--;
     89          break;
     90        default:
     91          throw new ArgumentOutOfRangeException("action");
     92      }
     93
     94      curAvgValue = temp / count;
    5595      OnValueChanged(curAvgValue, 0, Action.Modified);
    5696    }
  • trunk/sources/HeuristicLab.Visualization/3.2/AvgLineAggregator.cs

    r1530 r1605  
    2828
    2929    List<IDataRow> dataRowWatches = new List<IDataRow>();
    30    
     30
    3131    void dataRow_ValueChanged(IDataRow row, double value, int index, Action action) {
    32       refreshValue(value);
     32      switch (action) {
     33        case Action.Added:
     34          refreshValue(row, value, Action.Added);
     35          break;
     36        case Action.Modified:
     37          refreshValue();
     38          break;
     39        case Action.Deleted:
     40          refreshValue(row, value, Action.Deleted);
     41          break;
     42        default:
     43          throw new ArgumentOutOfRangeException("action");
     44      }
     45
    3346    }
    3447
    3548    void dataRow_ValuesChanged(IDataRow row, double[] values, int index, Action action) {
    3649      for (int i = 0; i < values.Length; i++) {
    37         refreshValue(values[i]);
     50        refreshValue();
    3851      }
    3952    }
    4053
    4154    void dataRow_DataRowChanged(IDataRow row) {
    42       refreshValue(double.MinValue);
    43     }
    44 
    45     private void refreshValue(double newVal) {
    46       //alle durchlaufen und neues min berechnen; verbesserung: merken in welcher row lowest wert steckt
    47 
    48       //curAvgValue = double.MinValue;
     55      refreshValue();
     56    }
     57
     58    private void refreshValue() {
    4959      double tmpSum = 0;
    5060      int count = dataRowWatches.Count;
     
    6575          }
    6676
    67           this.dataRow.Add(tmpSum/count);
     77          this.dataRow.Add(tmpSum / count);
    6878          OnValueChanged(tmpSum / count, dataRow.Count - 1, Action.Added);
    6979        }
    7080      }
     81    }
     82
     83    private void refreshValue(IDataRow row, double newVal, Action action) {
     84
     85      int index = row.Count - 1;
     86
     87
     88     
     89     
     90      double curAvg = 0;
     91//      if (dataRow.Count > 0) {
     92//        curAvg = dataRow[0];   //?
     93//      } else {
     94//        curAvg = 0;
     95//      }
     96
     97
     98      foreach (IDataRow watch in dataRowWatches) {
     99        if (watch.Count >= index +1) {
     100          curAvg += watch[index];
     101         
     102        }
     103        //curAvg += watch[watch.Count - 1];
     104      }
     105
     106      if (dataRowWatches.Count > 0)
     107        curAvg /= dataRowWatches.Count;
     108
     109
     110      if (dataRow.Count <= index) {
     111        dataRow.Add(curAvg);
     112        OnValueChanged(curAvg, dataRow.Count - 1, Action.Added);     
     113      }
     114      else {
     115        dataRow[index] = curAvg;
     116        OnValueChanged(curAvg, dataRow.Count - 1, Action.Modified); 
     117      }
     118
     119
     120
     121//      curAvg *= dataRow.Count * dataRowWatches.Count;
     122//      switch (action) {
     123//        case Action.Added:
     124//          curAvg += newVal;
     125//          break;
     126//        case Action.Modified:
     127//          throw new InvalidOperationException();
     128//        case Action.Deleted:
     129//          curAvg -= newVal;
     130//          break;
     131//        default:
     132//          throw new ArgumentOutOfRangeException("action");
     133//      }
     134//
     135//      dataRow.Add((curAvg / (dataRow.Count + 1)) / dataRowWatches.Count);
     136//      OnValueChanged((curAvg / (dataRow.Count + 1)) / dataRowWatches.Count, dataRow.Count - 1, Action.Added); // nicht immer adden!
     137
     138      //      double tmpSum = 0;
     139      //      int count = dataRowWatches.Count;
     140      //
     141      //      IDataRow firstRow = dataRowWatches[0];
     142      //      int count1 = firstRow.Count;
     143      //      System.Console.WriteLine("count: " + count1);
     144      //
     145      //      dataRow.Clear();
     146      //
     147      //      if (dataRowWatches.Count >= 2) {
     148      //        for (int i = 0; i < count1; i++) {
     149      //          tmpSum = 0;
     150      //          for (int j = 0; j < count; j++) {
     151      //            if (dataRowWatches[j].Count > i) {
     152      //              tmpSum += dataRowWatches[j][i];
     153      //            }
     154      //          }
     155      //
     156      //          this.dataRow.Add(tmpSum/count);
     157      //          OnValueChanged(tmpSum / count, dataRow.Count - 1, Action.Added);
     158      //        }
     159      //      }
    71160
    72161      // evtl nur feuern wenn sich geändert hat (jedes mal?)
Note: See TracChangeset for help on using the changeset viewer.