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/VariableEvaluationImpactCalculator.cs

    r2042 r2043  
    2929using System.Linq;
    3030
    31 namespace HeuristicLab.GP.StructureIdentification {
     31namespace HeuristicLab.SupportVectorMachines {
    3232  public class VariableEvaluationImpactCalculator : HeuristicLab.Modeling.VariableEvaluationImpactCalculator {
    3333
    3434    public VariableEvaluationImpactCalculator()
    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
    4239
    43     protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    44       ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    45       IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
    46       double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
    47       evaluator.PrepareForEvaluation(dataset, targetVariable, start, end, punishmentFactor, tree);
     40    protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     41      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
     42      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     43      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform);
    4844
    49       double[] result = new double[end - start];
    50       for (int i = start; i < end; i++) {
    51         result[i - start] = evaluator.Evaluate(i);
     45      double[] values = new double[end - start];
     46      for (int i = 0; i < end - start; i++) {
     47        values[i] = SVM.Prediction.Predict(model.Model, scaledProblem.X[i]);
    5248      }
    53 
    54       return result;
     49      return values;
    5550    }
    5651  }
Note: See TracChangeset for help on using the changeset viewer.