Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.ExtLibs/HeuristicLab.LibSVM/1.6.3/LibSVM-1.6.3/Scaling.cs @ 9760

Last change on this file since 9760 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 1.8 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
19
20
21namespace 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 {
27    /// <summary>
28    /// Scales a problem using the provided range.  This will not affect the parameter.
29    /// </summary>
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;
42    }
43  }
44}
Note: See TracBrowser for help on using the repository browser.