Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistentDataStructures/HeuristicLab.ExtLibs/HeuristicLab.LibSVM/3.12/LibSVM-3.12/Scaling.cs @ 14710

Last change on this file since 14710 was 8607, checked in by gkronber, 12 years ago

#1944 added new C# port of libSVM 3.12 and the HL wrapper plugin

File size: 2.0 KB
Line 
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 * Adaptions to work with direct C# translation of the java libSVM source code (version 3.1.2) by Gabriel Kronberger
19 *
20 */
21
22
23
24namespace LibSVM {
25  /// <summary>
26  /// Deals with the scaling of Problems so they have uniform ranges across all dimensions in order to
27  /// result in better SVM performance.
28  /// </summary>
29  public static class Scaling {
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 svm_problem Scale(this RangeTransform range, svm_problem prob) {
37      svm_problem scaledProblem = new svm_problem() { l = prob.l, y = new double[prob.l], x = new svm_node[prob.l][] };
38      for (int i = 0; i < scaledProblem.l; i++) {
39        scaledProblem.x[i] = new svm_node[prob.x[i].Length];
40        for (int j = 0; j < scaledProblem.x[i].Length; j++)
41          scaledProblem.x[i][j] = new svm_node() { index = prob.x[i][j].index, value = range.Transform(prob.x[i][j].value, prob.x[i][j].index) };
42        scaledProblem.y[i] = prob.y[i];
43      }
44      return scaledProblem;
45    }
46  }
47}
Note: See TracBrowser for help on using the repository browser.