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

File:
1 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  }
Note: See TracChangeset for help on using the changeset viewer.