Last change
on this file since 2115 was
1808,
checked in by mkommend, 15 years ago
|
SupportVectorEvaluator and SVMHelper added (ticket #619)
|
File size:
1.3 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.DataAnalysis;
|
---|
8 |
|
---|
9 | namespace 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.