Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMHelper.cs @ 2055

Last change on this file since 2055 was 1808, checked in by mkommend, 15 years ago

SupportVectorEvaluator and SVMHelper added (ticket #619)

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.DataAnalysis;
8
9namespace HeuristicLab.SupportVectorMachines {
10  public class SVMHelper {
11    public static SVM.Problem CreateSVMProblem(Dataset dataset, ItemList<IntData> allowedFeatures, int targetVariable, int start, int end) {
12      int rowCount = end - start;
13      double[] samples = dataset.Samples;
14     
15      SVM.Node[][] nodes = new SVM.Node[rowCount][];
16      List<SVM.Node> tempRow;
17      double value;
18      for (int row = 0; row < rowCount; row++) {
19        tempRow = new List<SVM.Node>();
20        for (int col = 0; col < allowedFeatures.Count; col++) {
21          value = samples[(start + row) * dataset.Columns + allowedFeatures[col].Data];
22          if(!double.IsNaN(value))
23            tempRow.Add(new SVM.Node(allowedFeatures[col].Data, value));
24        }
25        nodes[row] = tempRow.ToArray();
26      }
27
28      double[] targetVector = new double[rowCount];
29      for (int i = 0; i < rowCount; i++)
30        targetVector[i] = samples[(start + i) * dataset.Columns + targetVariable];
31
32      return new SVM.Problem(rowCount, targetVector, nodes, allowedFeatures.Max(x => x.Data));
33    }
34  }
35}
Note: See TracBrowser for help on using the repository browser.