[2645] | 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 |
|
---|
[4068] | 21 | namespace SVM {
|
---|
| 22 | /// <summary>
|
---|
| 23 | /// Deals with the scaling of Problems so they have uniform ranges across all dimensions in order to
|
---|
| 24 | /// result in better SVM performance.
|
---|
| 25 | /// </summary>
|
---|
| 26 | public static class Scaling {
|
---|
[2645] | 27 | /// <summary>
|
---|
[4068] | 28 | /// Scales a problem using the provided range. This will not affect the parameter.
|
---|
[2645] | 29 | /// </summary>
|
---|
[4068] | 30 | /// <param name="prob">The problem to scale</param>
|
---|
| 31 | /// <param name="range">The Range transform to use in scaling</param>
|
---|
| 32 | /// <returns>The Scaled problem</returns>
|
---|
| 33 | public static Problem Scale(this IRangeTransform range, Problem prob) {
|
---|
| 34 | Problem scaledProblem = new Problem(prob.Count, new double[prob.Count], new Node[prob.Count][], prob.MaxIndex);
|
---|
| 35 | for (int i = 0; i < scaledProblem.Count; i++) {
|
---|
| 36 | scaledProblem.X[i] = new Node[prob.X[i].Length];
|
---|
| 37 | for (int j = 0; j < scaledProblem.X[i].Length; j++)
|
---|
| 38 | scaledProblem.X[i][j] = new Node(prob.X[i][j].Index, range.Transform(prob.X[i][j].Value, prob.X[i][j].Index));
|
---|
| 39 | scaledProblem.Y[i] = prob.Y[i];
|
---|
| 40 | }
|
---|
| 41 | return scaledProblem;
|
---|
[2645] | 42 | }
|
---|
[4068] | 43 | }
|
---|
[2645] | 44 | }
|
---|