1 | /*
|
---|
2 | * SVM.NET Library
|
---|
3 | * Copyright (C) 2008 Matthew Johnson
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | using System;
|
---|
21 |
|
---|
22 | namespace SVM
|
---|
23 | {
|
---|
24 | /// <summary>
|
---|
25 | /// Deals with the scaling of Problems so they have uniform ranges across all dimensions in order to
|
---|
26 | /// result in better SVM performance.
|
---|
27 | /// </summary>
|
---|
28 | public static class Scaling
|
---|
29 | {
|
---|
30 | /// <summary>
|
---|
31 | /// Scales a problem using the provided range. This will not affect the parameter.
|
---|
32 | /// </summary>
|
---|
33 | /// <param name="prob">The problem to scale</param>
|
---|
34 | /// <param name="range">The Range transform to use in scaling</param>
|
---|
35 | /// <returns>The Scaled problem</returns>
|
---|
36 | public static Problem Scale(this IRangeTransform range, Problem prob)
|
---|
37 | {
|
---|
38 | Problem scaledProblem = new Problem(prob.Count, new double[prob.Count], new Node[prob.Count][], prob.MaxIndex);
|
---|
39 | for (int i = 0; i < scaledProblem.Count; i++)
|
---|
40 | {
|
---|
41 | scaledProblem.X[i] = new Node[prob.X[i].Length];
|
---|
42 | for (int j = 0; j < scaledProblem.X[i].Length; j++)
|
---|
43 | scaledProblem.X[i][j] = new Node(prob.X[i][j].Index, range.Transform(prob.X[i][j].Value, prob.X[i][j].Index));
|
---|
44 | scaledProblem.Y[i] = prob.Y[i];
|
---|
45 | }
|
---|
46 | return scaledProblem;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|