Changeset 2043


Ignore:
Timestamp:
06/15/09 16:46:25 (12 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
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VariableEvaluationImpactCalculator.cs

    r2041 r2043  
    4141
    4242
    43     protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
     43    protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
    4444      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    4545      IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VariableQualityImpactCalculator.cs

    r2041 r2043  
    4040    }
    4141
    42     protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
     42    protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
    4343      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    4444      IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
  • 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}
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLab.SupportVectorMachines-3.2.csproj

    r1906 r2043  
    8888    <Compile Include="SupportVectorEvaluator.cs" />
    8989    <Compile Include="SVMHelper.cs" />
     90    <Compile Include="VariableEvaluationImpactCalculator.cs" />
     91    <Compile Include="VariableQualityImpactCalculator.cs" />
    9092  </ItemGroup>
    9193  <ItemGroup>
     
    126128      <Name>HeuristicLab.PluginInfrastructure</Name>
    127129    </ProjectReference>
     130    <ProjectReference Include="..\..\HeuristicLab.Random\3.2\HeuristicLab.Random-3.2.csproj">
     131      <Project>{47019A74-F7F7-482E-83AA-D3F4F777E879}</Project>
     132      <Name>HeuristicLab.Random-3.2</Name>
     133    </ProjectReference>
     134    <ProjectReference Include="..\..\HeuristicLab.Selection\3.2\HeuristicLab.Selection-3.2.csproj">
     135      <Project>{F7CF0571-25CB-43D5-8443-0843A1E2861A}</Project>
     136      <Name>HeuristicLab.Selection-3.2</Name>
     137    </ProjectReference>
    128138    <ProjectReference Include="..\..\HeuristicLab.SequentialEngine\3.2\HeuristicLab.SequentialEngine-3.2.csproj">
    129139      <Project>{B4BE8E53-BA06-4237-9A01-24255F880201}</Project>
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLabSupportVectorMachinesPlugin.cs

    r1857 r2043  
    3737  [Dependency(Dependency = "HeuristicLab.Logging-3.2")]
    3838  [Dependency(Dependency = "HeuristicLab.Operators.Programmable-3.2")]
     39  [Dependency(Dependency = "HeuristicLab.Random-3.2")]
     40  [Dependency(Dependency = "HeuristicLab.Selection-3.2")]
    3941  public class HeuristicLabSupportVectorMachinesPlugin : PluginBase {
    4042  }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs

    r2036 r2043  
    5959      for (int i = 0; i < end - start; i++) {
    6060        values[i,0] = SVM.Prediction.Predict(modelData.Model, scaledProblem.X[i]);
    61         values[i,1] = dataset.Samples[(start + i) * dataset.Columns + targetVariable];
     61        values[i,1] = dataset.GetValue(start + i,targetVariable);
    6262      }
    6363
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs

    r1922 r2043  
    3434using HeuristicLab.Operators.Programmable;
    3535using HeuristicLab.Modeling;
     36using HeuristicLab.Random;
     37using HeuristicLab.Selection;
    3638
    3739namespace HeuristicLab.SupportVectorMachines {
     
    118120      main.AddSubOperator(CreateGlobalInjector());
    119121      main.AddSubOperator(new ProblemInjector());
    120 
    121       SequentialProcessor nuLoop = new SequentialProcessor();
    122       nuLoop.Name = "NuLoop";
    123       SequentialProcessor costLoop = new SequentialProcessor();
    124       costLoop.Name = "CostLoop";
    125       main.AddSubOperator(nuLoop);
    126       nuLoop.AddSubOperator(CreateResetOperator("CostIndex"));
    127       nuLoop.AddSubOperator(costLoop);
     122      main.AddSubOperator(new RandomInjector());
     123
    128124      SubScopesCreater modelScopeCreator = new SubScopesCreater();
    129125      modelScopeCreator.GetVariableInfo("SubScopes").Local = true;
    130126      modelScopeCreator.AddVariable(new HeuristicLab.Core.Variable("SubScopes", new IntData(1)));
     127      main.AddSubOperator(modelScopeCreator);
     128
     129      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
     130      IOperator modelProcessor = CreateModelProcessor();
     131      seqSubScopesProc.AddSubOperator(modelProcessor);
     132      main.AddSubOperator(seqSubScopesProc);
     133
     134      SequentialProcessor nuLoop = new SequentialProcessor();
     135      nuLoop.Name = "NuLoop";
     136
     137      IOperator costCounter = CreateCounter("Cost");
     138      IOperator costComparator = CreateComparator("Cost");
     139      nuLoop.AddSubOperator(costCounter);
     140      nuLoop.AddSubOperator(costComparator);
     141      ConditionalBranch costBranch = new ConditionalBranch();
     142      costBranch.Name = "IfValidCostIndex";
     143      costBranch.GetVariableInfo("Condition").ActualName = "RepeatCostLoop";
     144
     145      // build cost loop
     146      SequentialProcessor costLoop = new SequentialProcessor();
     147      costLoop.Name = "CostLoop";
    131148      costLoop.AddSubOperator(modelScopeCreator);
    132149      SequentialSubScopesProcessor subScopesProcessor = new SequentialSubScopesProcessor();
    133150      costLoop.AddSubOperator(subScopesProcessor);
     151      subScopesProcessor.AddSubOperator(new EmptyOperator());
     152      subScopesProcessor.AddSubOperator(modelProcessor);
     153
     154      Sorter sorter = new Sorter();
     155      sorter.GetVariableInfo("Value").ActualName = "ValidationQuality";
     156      sorter.GetVariableInfo("Descending").Local = true;
     157      sorter.AddVariable(new Variable("Descending", new BoolData(false)));
     158      costLoop.AddSubOperator(sorter);
     159
     160      LeftSelector selector = new LeftSelector();
     161      selector.GetVariableInfo("Selected").Local = true;
     162      selector.AddVariable(new Variable("Selected", new IntData(1)));
     163      costLoop.AddSubOperator(selector);
     164
     165      RightReducer reducer = new RightReducer();
     166      costLoop.AddSubOperator(reducer);
     167
     168      costLoop.AddSubOperator(costCounter);
     169      costLoop.AddSubOperator(costComparator);
     170
     171      costBranch.AddSubOperator(costLoop);
     172      costLoop.AddSubOperator(costBranch);
     173
     174      nuLoop.AddSubOperator(costBranch);
     175      nuLoop.AddSubOperator(CreateResetOperator("CostIndex"));
     176
     177      nuLoop.AddSubOperator(CreateCounter("Nu"));
     178      nuLoop.AddSubOperator(CreateComparator("Nu"));
     179
     180      ConditionalBranch nuBranch = new ConditionalBranch();
     181      nuBranch.Name = "NuLoop";
     182      nuBranch.GetVariableInfo("Condition").ActualName = "RepeatNuLoop";
     183      nuBranch.AddSubOperator(nuLoop);
     184      nuLoop.AddSubOperator(nuBranch);
     185
     186      main.AddSubOperator(nuLoop);
     187      main.AddSubOperator(CreateModelAnalyser());
     188      return main;
     189    }
     190
     191    private IOperator CreateModelProcessor() {
    134192      SequentialProcessor modelProcessor = new SequentialProcessor();
    135       subScopesProcessor.AddSubOperator(modelProcessor);
    136193      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Nu"));
    137194      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Cost"));
     
    160217      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("ValidationQuality"));
    161218      modelProcessor.AddSubOperator(collector);
    162 
    163       BestSolutionStorer solStorer = new BestSolutionStorer();
    164       solStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    165       solStorer.GetVariableInfo("Maximization").Local = true;
    166       solStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution";
    167       solStorer.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false)));
    168 
    169       costLoop.AddSubOperator(solStorer);
    170       SubScopesRemover remover = new SubScopesRemover();
    171       costLoop.AddSubOperator(remover);
    172       costLoop.AddSubOperator(CreateCounter("Cost"));
    173       costLoop.AddSubOperator(CreateComparator("Cost"));
    174       ConditionalBranch costBranch = new ConditionalBranch();
    175       costBranch.Name = "CostLoop";
    176       costBranch.GetVariableInfo("Condition").ActualName = "RepeatCostLoop";
    177       costBranch.AddSubOperator(costLoop);
    178       costLoop.AddSubOperator(costBranch);
    179 
    180       nuLoop.AddSubOperator(CreateCounter("Nu"));
    181       nuLoop.AddSubOperator(CreateComparator("Nu"));
    182       ConditionalBranch nuBranch = new ConditionalBranch();
    183       nuBranch.Name = "NuLoop";
    184       nuBranch.GetVariableInfo("Condition").ActualName = "RepeatNuLoop";
    185       nuBranch.AddSubOperator(nuLoop);
    186       nuLoop.AddSubOperator(nuBranch);
    187       return main;
     219      return modelProcessor;
    188220    }
    189221
     
    271303      progOp.RemoveVariableInfo("Result");
    272304      progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(IntData), VariableKind.In | VariableKind.Out));
    273       progOp.Code = "Value.Data = 0;";
     305      progOp.Code = "Value.Data = -1;";
    274306      progOp.GetVariableInfo("Value").ActualName = paramName;
    275307      return progOp;
     
    279311      VariableInjector injector = new VariableInjector();
    280312      injector.AddVariable(new HeuristicLab.Core.Variable("CostIndex", new IntData(0)));
    281       injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] { 0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0 })));
     313      injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] { 0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0 })));
    282314      injector.AddVariable(new HeuristicLab.Core.Variable("MaxCostIndex", new IntData()));
    283315      injector.AddVariable(new HeuristicLab.Core.Variable("NuIndex", new IntData(0)));
    284       injector.AddVariable(new HeuristicLab.Core.Variable("NuList", new DoubleArrayData(new double[] { 0.01, 0.05, 0.1, 0.5, 0.9 })));
     316      injector.AddVariable(new HeuristicLab.Core.Variable("NuList", new DoubleArrayData(new double[] { 0.01, 0.05, 0.1, 0.5 })));
    285317      injector.AddVariable(new HeuristicLab.Core.Variable("MaxNuIndex", new IntData()));
    286318      injector.AddVariable(new HeuristicLab.Core.Variable("Log", new ItemList()));
     
    291323      return injector;
    292324    }
     325
     326    private IOperator CreateModelAnalyser() {
     327      CombinedOperator modelAnalyser = new CombinedOperator();
     328      modelAnalyser.Name = "Model Analyzer";
     329      SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
     330      SequentialProcessor seqProc = new SequentialProcessor();
     331      VariableEvaluationImpactCalculator evalImpactCalc = new VariableEvaluationImpactCalculator();
     332      evalImpactCalc.GetVariableInfo("SVMModel").ActualName = "Model";
     333      VariableQualityImpactCalculator qualImpactCalc = new VariableQualityImpactCalculator();
     334      qualImpactCalc.GetVariableInfo("SVMModel").ActualName = "Model";
     335
     336      seqProc.AddSubOperator(evalImpactCalc);
     337      seqProc.AddSubOperator(qualImpactCalc);
     338      seqSubScopeProc.AddSubOperator(seqProc);
     339      modelAnalyser.OperatorGraph.InitialOperator = seqSubScopeProc;
     340      modelAnalyser.OperatorGraph.AddOperator(seqSubScopeProc);
     341      return modelAnalyser;
     342    }
     343
    293344
    294345    protected internal virtual Model CreateSVMModel(IScope bestModelScope) {
     
    309360      model.ValidationVarianceAccountedFor = bestModelScope.GetVariableValue<DoubleData>("ValidationVAF", false).Data;
    310361      model.TestVarianceAccountedFor = bestModelScope.GetVariableValue<DoubleData>("TestVAF", false).Data;
    311      
     362
    312363      model.Data = bestModelScope.GetVariableValue<SVMModel>("BestValidationModel", false);
    313364      HeuristicLab.DataAnalysis.Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
    314365      model.Dataset = ds;
    315366      model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
     367
     368      ItemList evaluationImpacts = bestModelScope.GetVariableValue<ItemList>("VariableEvaluationImpacts", false);
     369      ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>("VariableQualityImpacts", false);
     370      foreach (ItemList row in evaluationImpacts) {
     371        string variableName = ((StringData)row[0]).Data;
     372        double impact = ((DoubleData)row[0]).Data;
     373        model.SetVariableEvaluationImpact(variableName, impact);
     374      }
     375      foreach (ItemList row in qualityImpacts) {
     376        string variableName = ((StringData)row[0]).Data;
     377        double impact = ((DoubleData)row[0]).Data;
     378        model.SetVariableQualityImpact(variableName, impact);
     379      }
     380
    316381      return model;
    317382    }
     
    337402
    338403    #endregion
    339 
    340404  }
    341405}
  • 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  }
  • 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.