Changeset 5275 for branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineUtil.cs
- Timestamp:
- 01/11/11 15:03:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineUtil.cs
r4068 r5275 29 29 /// </summary> 30 30 /// <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> 33 32 /// <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(); 37 37 38 38 SVM.Node[][] nodes = new SVM.Node[targetVector.Length][]; 39 39 List<SVM.Node> tempRow; 40 40 int maxNodeIndex = 0; 41 for (int row = 0; row < rowCount; row++) { 41 int svmProblemRowIndex = 0; 42 foreach (int row in rowIndices) { 42 43 tempRow = new List<SVM.Node>(); 43 44 foreach (var inputVariable in problemData.InputVariables.CheckedItems) { 44 45 int col = problemData.Dataset.GetVariableIndex(inputVariable.Value.Value); 45 double value = problemData.Dataset[ start +row, col];46 double value = problemData.Dataset[row, col]; 46 47 if (!double.IsNaN(value)) { 47 int nodeIndex = col + 1; // make sure the smallest nodeIndex = 148 int nodeIndex = col + 1; // make sure the smallest nodeIndex is 1 (libSVM convention) 48 49 tempRow.Add(new SVM.Node(nodeIndex, value)); 49 50 if (nodeIndex > maxNodeIndex) maxNodeIndex = nodeIndex; 50 51 } 51 52 } 52 nodes[ row] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index53 nodes[svmProblemRowIndex++] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index 53 54 } 54 55
Note: See TracChangeset
for help on using the changeset viewer.