Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/11/11 18:41:03 (14 years ago)
Author:
gkronber
Message:

#790 Fixed minor issues in LDA, LR, SVC and SVR to make sure everything works correctly in presence of NaN and infinity values.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs

    r5809 r6002  
    4141      int maxNodeIndex = 0;
    4242      int svmProblemRowIndex = 0;
     43      List<string> inputVariablesList = inputVariables.ToList();
    4344      foreach (int row in rowIndices) {
    4445        tempRow = new List<SVM.Node>();
    45         foreach (var inputVariable in inputVariables) {
    46           int col = dataset.GetVariableIndex(inputVariable);
    47           double value = dataset[row, col];
     46        int colIndex = 1; // make sure the smallest node index for SVM = 1
     47        foreach (var inputVariable in inputVariablesList) {
     48          double value = dataset[row, dataset.GetVariableIndex(inputVariable)];
     49          // SVM also works with missing values
     50          // => don't add NaN values in the dataset to the sparse SVM matrix representation
    4851          if (!double.IsNaN(value)) {
    49             int nodeIndex = col + 1; // make sure the smallest nodeIndex is 1 (libSVM convention)
    50             tempRow.Add(new SVM.Node(nodeIndex, value));
    51             if (nodeIndex > maxNodeIndex) maxNodeIndex = nodeIndex;
     52            tempRow.Add(new SVM.Node(colIndex, value)); // nodes must be sorted in ascending ordered by column index
     53            if (colIndex > maxNodeIndex) maxNodeIndex = colIndex;
    5254          }
     55          colIndex++;
    5356        }
    54         nodes[svmProblemRowIndex++] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index
     57        nodes[svmProblemRowIndex++] = tempRow.ToArray();
    5558      }
    5659
Note: See TracChangeset for help on using the changeset viewer.