Changeset 8742 for branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs
- Timestamp:
- 10/05/12 11:58:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs
r7259 r8742 23 23 using System.Linq; 24 24 using HeuristicLab.Problems.DataAnalysis; 25 using LibSVM; 25 26 26 27 namespace HeuristicLab.Algorithms.DataAnalysis { … … 32 33 /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param> 33 34 /// <returns>A problem data type that can be used to train a support vector machine.</returns> 34 public static SVM.Problem CreateSvmProblem(Dataset dataset, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) {35 public static svm_problem CreateSvmProblem(Dataset dataset, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) { 35 36 double[] targetVector = 36 37 dataset.GetDoubleValues(targetVariable, rowIndices).ToArray(); 37 38 38 SVM.Node[][] nodes = new SVM.Node[targetVector.Length][];39 List< SVM.Node> tempRow;39 svm_node[][] nodes = new svm_node[targetVector.Length][]; 40 List<svm_node> tempRow; 40 41 int maxNodeIndex = 0; 41 42 int svmProblemRowIndex = 0; 42 43 List<string> inputVariablesList = inputVariables.ToList(); 43 44 foreach (int row in rowIndices) { 44 tempRow = new List< SVM.Node>();45 tempRow = new List<svm_node>(); 45 46 int colIndex = 1; // make sure the smallest node index for SVM = 1 46 47 foreach (var inputVariable in inputVariablesList) { … … 49 50 // => don't add NaN values in the dataset to the sparse SVM matrix representation 50 51 if (!double.IsNaN(value)) { 51 tempRow.Add(new SVM.Node(colIndex, value)); // nodes must be sorted in ascending ordered by column index52 tempRow.Add(new svm_node() { index = colIndex, value = value }); // nodes must be sorted in ascending ordered by column index 52 53 if (colIndex > maxNodeIndex) maxNodeIndex = colIndex; 53 54 } … … 57 58 } 58 59 59 return new SVM.Problem(targetVector.Length, targetVector, nodes, maxNodeIndex);60 return new svm_problem() { l = targetVector.Length, y = targetVector, x = nodes }; 60 61 } 61 62 }
Note: See TracChangeset
for help on using the changeset viewer.