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

Location:
trunk/sources/HeuristicLab.SupportVectorMachines/3.2
Files:
5 edited

Legend:

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

    r2148 r2165  
    99namespace HeuristicLab.SupportVectorMachines {
    1010  public class SVMHelper {
    11     public static SVM.Problem CreateSVMProblem(Dataset dataset, ItemList<IntData> allowedFeatures, int targetVariable, int start, int end) {
     11    public static SVM.Problem CreateSVMProblem(Dataset dataset, int targetVariable, int start, int end) {
    1212      int rowCount = end - start;
    13       double[] samples = dataset.Samples;
     13      List<int> skippedFeatures = new List<int>();
     14      for (int i = 0; i < dataset.Columns; i++) {
     15        if (i != targetVariable) {
     16          if (dataset.GetRange(i, start, end) == 0)
     17            skippedFeatures.Add(i);
     18        }
     19      }
    1420
    15       List<int> skippedFeatures = new List<int>();
    16       for (int i = 0; i < allowedFeatures.Count; i++) {
    17         if (dataset.GetRange(allowedFeatures[i].Data, start, end) == 0)
    18           skippedFeatures.Add(i);
    19       }
     21      int maxColumns = dataset.Columns - skippedFeatures.Count();
    2022
    2123      double[] targetVector = new double[rowCount];
    2224      for (int i = 0; i < rowCount; i++) {
    23         double value = samples[(start + i) * dataset.Columns + targetVariable];
     25        double value = dataset.GetValue(start + i, targetVariable);
    2426          targetVector[i] = value;
    2527      }
     
    3133      for (int row = 0; row < rowCount; row++) {
    3234        tempRow = new List<SVM.Node>();
    33         for (int col = 0; col < allowedFeatures.Count; col++) {
    34           if (!skippedFeatures.Contains(col)) {
    35             double value = samples[(start + row) * dataset.Columns + allowedFeatures[col].Data];
     35        for (int col = 0; col < dataset.Columns; col++) {
     36          if (!skippedFeatures.Contains(col) && col!=targetVariable) {
     37            double value = dataset.GetValue(start + row, col);
    3638            if (!double.IsNaN(value))
    37               tempRow.Add(new SVM.Node(allowedFeatures[col].Data, value));
     39              tempRow.Add(new SVM.Node(col, value));
    3840          }
    3941        }
    40         if (!double.IsNaN(samples[(start + row) * dataset.Columns + targetVariable])) {
     42        if (!double.IsNaN(dataset.GetValue(start + row, targetVariable))) {
    4143          nodes[addedRows] = tempRow.ToArray();
    4244          addedRows++;
     
    4446      }
    4547
    46       return new SVM.Problem(targetVector.Length, targetVector, nodes, allowedFeatures.Max(x => x.Data));
     48      return new SVM.Problem(targetVector.Length, targetVector, nodes, maxColumns);
    4749    }
    4850  }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorCreator.cs

    r2163 r2165  
    3939      //Dataset infos
    4040      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    41       AddVariableInfo(new VariableInfo("AllowedFeatures", "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    4241      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
    4342      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    6766      abortRequested = false;
    6867      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    69       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);
    7068      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    7169      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
     
    8381      parameter.Gamma = GetVariableValue<DoubleData>("SVMGamma", scope, true).Data;
    8482
    85       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     83      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    8684      SVM.RangeTransform rangeTransform = SVM.Scaling.DetermineRange(problem);
    8785      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, rangeTransform);
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs

    r2148 r2165  
    3535      //Dataset infos
    3636      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    37       AddVariableInfo(new VariableInfo("AllowedFeatures", "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    3837      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
    3938      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    4746    public override IOperation Apply(IScope scope) {
    4847      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    49       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);
    5048      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    5149      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
     
    5351
    5452      SVMModel modelData = GetVariableValue<SVMModel>("SVMModel", scope, true);
    55       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     53      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    5654      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, modelData.RangeTransform);
    5755
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableEvaluationImpactCalculator.cs

    r2043 r2165  
    3838
    3939
    40     protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     40    protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4141      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
    42       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     42      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    4343      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform);
    4444
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableQualityImpactCalculator.cs

    r2136 r2165  
    3737    }
    3838
    39     protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     39    protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4040      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
    41       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     41      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    4242      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform);
    4343
Note: See TracChangeset for help on using the changeset viewer.