Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/16/09 11:34:22 (15 years ago)
Author:
gkronber
Message:

Removed variable AllowedFeatures in all modeling algorithms. #709

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableImpactCalculatorBase.cs

    r2043 r2165  
    3434
    3535    public override string Description {
    36       get { return @"Calculates the impact of all allowed input variables on the model."; }
     36      get { return @"Calculates the impact of all input variables on the model."; }
    3737    }
    3838
     
    4747      AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.In));
    4848      AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(IntData), VariableKind.In));
    49       AddVariableInfo(new VariableInfo("AllowedFeatures", "Indexes of allowed input variables", typeof(ItemList<IntData>), VariableKind.In));
    5049      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.In));
    5150      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "TrainingSamplesEnd", typeof(IntData), VariableKind.In));
     
    5453
    5554    public override IOperation Apply(IScope scope) {
    56       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);
    5755      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    5856      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
     
    6159      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    6260
    63       T referenceValue = CalculateValue(scope, dataset, targetVariable, allowedFeatures, start, end);
    64       double[] impacts = new double[allowedFeatures.Count];
     61      T referenceValue = CalculateValue(scope, dataset, targetVariable, start, end);
     62      double[] impacts = new double[dataset.Columns];
    6563
    66       for (int i = 0; i < allowedFeatures.Count && !abortRequested; i++) {
    67         int currentVariable = allowedFeatures[i].Data;
    68         var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable, CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end);
    69         T newValue = CalculateValue(scope, dirtyDataset, targetVariable, allowedFeatures, start, end);
    70         impacts[i] = CalculateImpact(referenceValue, newValue);
    71         ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end);
     64      for (int i = 0; i < impacts.Length && !abortRequested; i++) {
     65        int currentVariable = i;
     66        if (currentVariable != targetVariable) {
     67          var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable, CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end);
     68          T newValue = CalculateValue(scope, dirtyDataset, targetVariable, start, end);
     69          impacts[i] = CalculateImpact(referenceValue, newValue);
     70          ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end);
     71        }
    7272      }
    7373
     
    7676
    7777        ItemList variableImpacts = new ItemList();
    78         for (int i = 0; i < allowedFeatures.Count; i++) {
    79           int currentVariable = allowedFeatures[i].Data;
    80           ItemList row = new ItemList();
    81           row.Add(new StringData(dataset.GetVariableName(currentVariable)));
    82           row.Add(new DoubleData(impacts[i]));
    83           variableImpacts.Add(row);
     78        for (int i = 0; i < impacts.Length; i++) {
     79          int currentVariable = i;
     80          if (currentVariable != targetVariable) {
     81            ItemList row = new ItemList();
     82            row.Add(new StringData(dataset.GetVariableName(currentVariable)));
     83            row.Add(new DoubleData(impacts[i]));
     84            variableImpacts.Add(row);
     85          }
    8486        }
    8587
     
    9193    }
    9294
    93     protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end);
     95    protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end);
    9496
    9597    protected abstract double CalculateImpact(T referenceValue, T newValue);
Note: See TracChangeset for help on using the changeset viewer.