Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/11/11 15:03:46 (14 years ago)
Author:
gkronber
Message:

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineUtil.cs

    r4068 r5275  
    2929    /// </summary>
    3030    /// <param name="problemData">The problem data to transform</param>
    31     /// <param name="start">The index of the first row of <paramref name="problemData"/> to copy to the output.</param>
    32     /// <param name="end">The last of the first row of <paramref name="problemData"/> to copy to the output.</param>
     31    /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param>
    3332    /// <returns>A problem data type that can be used to train a support vector machine.</returns>
    34     public static SVM.Problem CreateSvmProblem(DataAnalysisProblemData problemData, int start, int end) {
    35       int rowCount = end - start;
    36       var targetVector = problemData.Dataset.GetVariableValues(problemData.TargetVariable.Value, start, end);
     33    public static SVM.Problem CreateSvmProblem(DataAnalysisProblemData problemData, IEnumerable<int> rowIndices) {
     34      double[] targetVector =
     35        problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, rowIndices)
     36        .ToArray();
    3737
    3838      SVM.Node[][] nodes = new SVM.Node[targetVector.Length][];
    3939      List<SVM.Node> tempRow;
    4040      int maxNodeIndex = 0;
    41       for (int row = 0; row < rowCount; row++) {
     41      int svmProblemRowIndex = 0;
     42      foreach (int row in rowIndices) {
    4243        tempRow = new List<SVM.Node>();
    4344        foreach (var inputVariable in problemData.InputVariables.CheckedItems) {
    4445          int col = problemData.Dataset.GetVariableIndex(inputVariable.Value.Value);
    45           double value = problemData.Dataset[start + row, col];
     46          double value = problemData.Dataset[row, col];
    4647          if (!double.IsNaN(value)) {
    47             int nodeIndex = col + 1; // make sure the smallest nodeIndex = 1
     48            int nodeIndex = col + 1; // make sure the smallest nodeIndex is 1 (libSVM convention)
    4849            tempRow.Add(new SVM.Node(nodeIndex, value));
    4950            if (nodeIndex > maxNodeIndex) maxNodeIndex = nodeIndex;
    5051          }
    5152        }
    52         nodes[row] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index
     53        nodes[svmProblemRowIndex++] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index
    5354      }
    5455
Note: See TracChangeset for help on using the changeset viewer.