Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2038 for trunk/sources


Ignore:
Timestamp:
06/10/09 10:46:56 (15 years ago)
Author:
gkronber
Message:
  • Renamed VariableImpactCalculator to VariableQualityImpactCalculator and calculate the ratio of new quality value to old quality value to get an idea how the quality value is influenced by each variable.
  • Changes in Dataset to improve the speed of SetValue (only set a dirty flag instead of reallocating the caches)

#644 (Variable impact of CEDMA models should be calculated and stored in the result DB)

Location:
trunk/sources
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAnalysis/3.2/Dataset.cs

    r2012 r2038  
    3939    private double[] scalingFactor;
    4040    private double[] scalingOffset;
     41    private bool cachedValuesInvalidated = true;
     42
     43    private bool fireChangeEvents = true;
     44    public bool FireChangeEvents {
     45      get { return fireChangeEvents; }
     46      set { fireChangeEvents = value; }
     47    }
    4148
    4249    public string Name {
     
    7481      if (v != samples[columns * i + j]) {
    7582        samples[columns * i + j] = v;
    76         CreateDictionaries();
    77         FireChanged();
     83        cachedValuesInvalidated = true;
     84        if (fireChangeEvents) FireChanged();
    7885      }
    7986    }
     
    8996        }
    9097        samples = value;
    91         CreateDictionaries();
    92         FireChanged();
     98        cachedValuesInvalidated = true;
     99        if (fireChangeEvents) FireChanged();
    93100      }
    94101    }
     
    104111      scalingOffset = new double[] { 0.0 };
    105112      scalingFactor = new double[] { 1.0 };
    106     }
    107 
    108     private void CreateDictionaries() {
    109       // keep a means and ranges dictionary for each column (possible target variable) of the dataset.
    110       cachedMeans = new Dictionary<int, Dictionary<int, double>>[columns];
    111       cachedRanges = new Dictionary<int, Dictionary<int, double>>[columns];
    112       for (int i = 0; i < columns; i++) {
    113         cachedMeans[i] = new Dictionary<int, Dictionary<int, double>>();
    114         cachedRanges[i] = new Dictionary<int, Dictionary<int, double>>();
    115       }
     113      cachedValuesInvalidated = true;
     114      fireChangeEvents = true;
    116115    }
    117116
     
    206205        }
    207206      }
    208       CreateDictionaries();
    209207    }
    210208
     
    270268
    271269    public double GetMean(int column, int from, int to) {
     270      if (cachedValuesInvalidated) CreateDictionaries();
    272271      if (!cachedMeans[column].ContainsKey(from) || !cachedMeans[column][from].ContainsKey(to)) {
    273272        double[] values = new double[to - from];
     
    289288
    290289    public double GetRange(int column, int from, int to) {
     290      if (cachedValuesInvalidated) CreateDictionaries();
    291291      if (!cachedRanges[column].ContainsKey(from) || !cachedRanges[column][from].ContainsKey(to)) {
    292292        double[] values = new double[to - from];
     
    329329        else ScaleVariable(column, 1.0 / range, -min);
    330330      }
    331       CreateDictionaries();
    332       FireChanged();
     331      cachedValuesInvalidated = true;
     332      if (fireChangeEvents) FireChanged();
    333333    }
    334334
     
    340340        samples[i * columns + column] = (origValue + offset) * factor;
    341341      }
    342       CreateDictionaries();
    343       FireChanged();
     342      cachedValuesInvalidated = true;
     343      if (fireChangeEvents) FireChanged();
    344344    }
    345345
     
    353353        scalingOffset[column] = 0.0;
    354354      }
     355      cachedValuesInvalidated = true;
     356      if (fireChangeEvents) FireChanged();
     357    }
     358
     359    private void CreateDictionaries() {
     360      // keep a means and ranges dictionary for each column (possible target variable) of the dataset.
     361      cachedMeans = new Dictionary<int, Dictionary<int, double>>[columns];
     362      cachedRanges = new Dictionary<int, Dictionary<int, double>>[columns];
     363      for (int i = 0; i < columns; i++) {
     364        cachedMeans[i] = new Dictionary<int, Dictionary<int, double>>();
     365        cachedRanges[i] = new Dictionary<int, Dictionary<int, double>>();
     366      }
    355367    }
    356368  }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs

    r2034 r2038  
    7272        }
    7373      }
     74      dataset.FireChangeEvents = false;
    7475
    7576      Evaluate(scope, evaluator, dataset, targetVariable, start, end, useEstimatedValues);
     
    8182        }
    8283      }
     84      dataset.FireChangeEvents = true;
     85      dataset.FireChanged();
    8386
    8487      // update the value of total evaluated nodes
  • trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj

    r2034 r2038  
    8383  <ItemGroup>
    8484    <Compile Include="ClassificationProblemInjector.cs" />
    85     <Compile Include="VariableImpactCalculator.cs" />
    8685    <Compile Include="Model.cs" />
    8786    <Compile Include="IModel.cs" />
     
    106105    <Compile Include="TimeSeriesProblemInjector.cs" />
    107106    <Compile Include="SimpleVarianceAccountedForEvaluator.cs" />
     107    <Compile Include="VariableQualityImpactCalculator.cs" />
    108108  </ItemGroup>
    109109  <ItemGroup>
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs

    r2037 r2038  
    3030
    3131namespace HeuristicLab.Modeling {
    32   public class VariableImpactCalculator : OperatorBase {
     32  public class VariableQualityImpactCalculator : OperatorBase {
    3333    public override string Description {
    3434      get { return @"Calculates the impact of all allowed input variables on the quality of the model using evaluator supplied as suboperator."; }
    3535    }
    3636
    37     public VariableImpactCalculator()
     37    public VariableQualityImpactCalculator()
    3838      : base() {
    3939      AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.In));
     
    4242      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.In));
    4343      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "TrainingSamplesEnd", typeof(IntData), VariableKind.In));
    44       AddVariableInfo(new VariableInfo("VariableImpacts", "Variable impacts", typeof(ItemList), VariableKind.New));
     44      AddVariableInfo(new VariableInfo("VariableQualityImpacts", "Effect on quality of model (percentage of original quality) if variable is replaced by its mean.", typeof(ItemList), VariableKind.New));
    4545    }
    4646
     
    5353      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    5454
    55       if (SubOperators.Count < 1) throw new InvalidOperationException("VariableImpactCalculator needs a suboperator to evaluate the model");
     55      if (SubOperators.Count < 1) throw new InvalidOperationException("VariableQualityImpactCalculator needs a suboperator to evaluate the model");
    5656      IOperator evaluationOperator = this.SubOperators[0];
    57 
    58       ItemList variableImpacts = new ItemList();
     57      ItemList variableQualityImpacts = new ItemList();
    5958
    6059      // calculateReferenceQuality
     
    6564        var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable , CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end);
    6665        double newQuality = CalculateQuality(scope, dirtyDataset, evaluationOperator);
    67         double ratio = referenceQuality / newQuality;
    68         double impact = ratio < 1.0 ? 1.0 - ratio : 1.0 - 1.0 / ratio;
     66        double ratio = newQuality / referenceQuality;
    6967        ItemList row = new ItemList();
    7068        row.Add(new StringData(dataset.GetVariableName(currentVariable)));
    71         row.Add(new DoubleData(impact));
    72         variableImpacts.Add(row);
     69        row.Add(new DoubleData(ratio));
     70        variableQualityImpacts.Add(row);
    7371        ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end);
    7472      }
    75       scope.AddVariable(new Variable(scope.TranslateName("VariableImpacts"), variableImpacts));
     73      scope.AddVariable(new Variable(scope.TranslateName("VariableQualityImpacts"), variableQualityImpacts));
    7674      return null;
    7775    }
     
    9391
    9492      int index = start;
     93      ds.FireChangeEvents = false;
    9594      foreach(double v in newValues) {
    9695        ds.SetValue(index++, variableIndex, v);
    9796      }
     97      ds.FireChangeEvents = true;
     98      ds.FireChanged();
    9899      return oldValues;
    99100    }
Note: See TracChangeset for help on using the changeset viewer.