Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/15/09 16:46:25 (15 years ago)
Author:
gkronber
Message:

Added variable impact calculation operators for support vector machines. #644 (Variable impact of CEDMA models should be calculated and stored in the result DB)

Location:
trunk/sources/HeuristicLab.Modeling/3.2
Files:
3 edited

Legend:

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

    r2041 r2043  
    5353    }
    5454
    55     protected override double[] CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    56       return GetOutputs(scope, dataset, targetVariable, start, end);
     55    protected override double[] CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     56      return GetOutputs(scope, dataset, targetVariable, allowedFeatures, start, end);
    5757    }
    5858
     
    6666    }
    6767
    68     protected abstract double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end);
     68    protected abstract double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end);
    6969  }
    7070}
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableImpactCalculatorBase.cs

    r2041 r2043  
    3131namespace HeuristicLab.Modeling {
    3232  public abstract class VariableImpactCalculatorBase<T> : OperatorBase {
     33    private bool abortRequested = false;
     34
    3335    public override string Description {
    3436      get { return @"Calculates the impact of all allowed input variables on the model."; }
     
    3638
    3739    public abstract string OutputVariableName { get; }
     40
     41    public override void Abort() {
     42      abortRequested = true;
     43    }
    3844
    3945    public VariableImpactCalculatorBase()
     
    5561      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    5662
    57       T referenceValue = CalculateValue(scope, dataset, targetVariable, start, end);
     63      T referenceValue = CalculateValue(scope, dataset, targetVariable, allowedFeatures, start, end);
    5864      double[] impacts = new double[allowedFeatures.Count];
    5965
    60       for (int i = 0; i < allowedFeatures.Count; i++) {
     66      for (int i = 0; i < allowedFeatures.Count && !abortRequested; i++) {
    6167        int currentVariable = allowedFeatures[i].Data;
    62         var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable , CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end);
    63         T newValue = CalculateValue(scope, dirtyDataset, targetVariable, start, end);
     68        var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable, CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end);
     69        T newValue = CalculateValue(scope, dirtyDataset, targetVariable, allowedFeatures, start, end);
    6470        impacts[i] = CalculateImpact(referenceValue, newValue);
    6571        ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end);
    6672      }
    6773
    68       impacts = PostProcessImpacts(impacts);
     74      if (!abortRequested) {
     75        impacts = PostProcessImpacts(impacts);
    6976
    70       ItemList variableImpacts = new ItemList();
    71       for (int i = 0; i < allowedFeatures.Count; i++) {
    72         int currentVariable = allowedFeatures[i].Data;
    73         ItemList row = new ItemList();
    74         row.Add(new StringData(dataset.GetVariableName(currentVariable)));
    75         row.Add(new DoubleData(impacts[i]));
    76         variableImpacts.Add(row);
     77        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);
     84        }
     85
     86        scope.AddVariable(new Variable(scope.TranslateName(OutputVariableName), variableImpacts));
     87        return null;
     88      } else {
     89        return new AtomicOperation(this, scope);
    7790      }
    78 
    79       scope.AddVariable(new Variable(scope.TranslateName(OutputVariableName), variableImpacts));
    80       return null;
    8191    }
    8292
    83     protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end);
     93    protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end);
    8494
    8595    protected abstract double CalculateImpact(T referenceValue, T newValue);
     
    96106      int index = start;
    97107      ds.FireChangeEvents = false;
    98       foreach(double v in newValues) {
     108      foreach (double v in newValues) {
    99109        ds.SetValue(index++, variableIndex, v);
    100110      }
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs

    r2041 r2043  
    4343    }
    4444
    45     protected override double CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    46       return CalculateQuality(scope, dataset, targetVariable, start, end);
     45    protected override double CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     46      return CalculateQuality(scope, dataset, targetVariable, allowedFeatures, start, end);
    4747    }
    4848
    49     protected abstract double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end);
     49    protected abstract double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end);
    5050  }
    5151}
Note: See TracChangeset for help on using the changeset viewer.