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)

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableQualityImpactCalculator.cs

    r2042 r2043  
    2929using System.Linq;
    3030
    31 namespace HeuristicLab.GP.StructureIdentification {
     31namespace HeuristicLab.SupportVectorMachines {
    3232  public class VariableQualityImpactCalculator : HeuristicLab.Modeling.VariableQualityImpactCalculator {
    3333
    3434    public VariableQualityImpactCalculator()
    3535      : base() {
    36       AddVariableInfo(new VariableInfo("TreeEvaluator", "The evaluator that should be used to evaluate the expression tree", typeof(ITreeEvaluator), VariableKind.In));
    37       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IFunctionTree), VariableKind.In));
    38       AddVariableInfo(new VariableInfo("TreeSize", "Size (number of nodes) of the tree to evaluate", typeof(IntData), VariableKind.In));
    39       AddVariableInfo(new VariableInfo("PunishmentFactor", "Punishment factor for invalid estimations", typeof(DoubleData), VariableKind.In));
     36      AddVariableInfo(new VariableInfo("SVMModel", "The model that should be evaluated", typeof(SVMModel), VariableKind.In));
    4037    }
    4138
    42     protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    43       ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    44       IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
    45       double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
    46       evaluator.PrepareForEvaluation(dataset, targetVariable, start, end, punishmentFactor, tree);
     39    protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     40      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
     41      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     42      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform);
    4743
    48       double[,] result = new double[end - start,2];
    49       for (int i = start; i < end; i++) {
    50         result[i - start, 0] = dataset.GetValue(i, targetVariable);
    51         result[i - start,1] = evaluator.Evaluate(i);
     44      double[,] values = new double[end - start, 2];
     45      for (int i = 0; i < end - start; i++) {
     46        values[i, 0] = SVM.Prediction.Predict(model.Model, scaledProblem.X[i]);
     47        values[i, 1] = dataset.GetValue(start + i,targetVariable);
    5248      }
    5349
    54       return HeuristicLab.Modeling.SimpleMSEEvaluator.Calculate(result);
     50      return HeuristicLab.Modeling.SimpleMSEEvaluator.Calculate(values);
    5551    }
    5652  }
Note: See TracChangeset for help on using the changeset viewer.