Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/LibSVM/Parameter.cs @ 1886

Last change on this file since 1886 was 1819, checked in by mkommend, 15 years ago

created new project for LibSVM source files (ticket #619)

File size: 8.5 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
20using System;
21
22namespace SVM
23{
24    /// <remarks>
25    /// Contains all of the types of SVM this library can model.
26    /// </remarks>
27    public enum SvmType {
28        /// <summary>
29        /// C-SVC.
30        /// </summary>
31        C_SVC,
32        /// <summary>
33        /// nu-SVC.
34        /// </summary>
35        NU_SVC,
36        /// <summary>
37        /// one-class SVM
38        /// </summary>
39        ONE_CLASS,
40        /// <summary>
41        /// epsilon-SVR
42        /// </summary>
43        EPSILON_SVR,
44        /// <summary>
45        /// nu-SVR
46        /// </summary>
47        NU_SVR
48    };
49    /// <remarks>
50    /// Contains the various kernel types this library can use.
51    /// </remarks>
52    public enum KernelType {
53        /// <summary>
54        /// Linear: u'*v
55        /// </summary>
56        LINEAR,
57        /// <summary>
58        /// Polynomial: (gamma*u'*v + coef0)^degree
59        /// </summary>
60        POLY,
61        /// <summary>
62        /// Radial basis function: exp(-gamma*|u-v|^2)
63        /// </summary>
64        RBF,
65        /// <summary>
66        /// Sigmoid: tanh(gamma*u'*v + coef0)
67        /// </summary>
68        SIGMOID,
69        /// <summary>
70        /// Precomputed kernel
71        /// </summary>
72        PRECOMPUTED,
73    };
74
75    /// <remarks>
76    /// This class contains the various parameters which can affect the way in which an SVM
77    /// is learned.  Unless you know what you are doing, chances are you are best off using
78    /// the default values.
79    /// </remarks>
80  [Serializable]
81  public class Parameter : ICloneable
82  {
83        private SvmType _svmType;
84        private KernelType _kernelType;
85        private int _degree;
86        private double _gamma;
87        private double _coef0;
88
89        private double _cacheSize;
90        private double _C;
91        private double _eps;
92
93        private int _weightCount;
94        private int[] _weightLabels;
95        private double[] _weights;
96        private double _nu;
97        private double _p;
98        private bool _shrinking;
99        private bool _probability;
100
101        /// <summary>
102        /// Default Constructor.  Gives good default values to all parameters.
103        /// </summary>
104        public Parameter()
105        {
106            _svmType = SvmType.C_SVC;
107            _kernelType = KernelType.RBF;
108            _degree = 3;
109            _gamma = 0; // 1/k
110            _coef0 = 0;
111            _nu = 0.5;
112            _cacheSize = 40;
113            _C = 1;
114            _eps = 1e-3;
115            _p = 0.1;
116            _shrinking = true;
117            _probability = false;
118            _weightCount = 0;
119            _weightLabels = new int[0];
120            _weights = new double[0];
121        }
122
123        /// <summary>
124        /// Type of SVM (default C-SVC)
125        /// </summary>
126        public SvmType SvmType
127        {
128            get
129            {
130                return _svmType;
131            }
132            set
133            {
134                _svmType = value;
135            }
136        }
137        /// <summary>
138        /// Type of kernel function (default Polynomial)
139        /// </summary>
140        public KernelType KernelType
141        {
142            get
143            {
144                return _kernelType;
145            }
146            set
147            {
148                _kernelType = value;
149            }
150        }
151        /// <summary>
152        /// Degree in kernel function (default 3).
153        /// </summary>
154        public int Degree
155        {
156            get
157            {
158                return _degree;
159            }
160            set
161            {
162                _degree = value;
163            }
164        }
165        /// <summary>
166        /// Gamma in kernel function (default 1/k)
167        /// </summary>
168        public double Gamma
169        {
170            get
171            {
172                return _gamma;
173            }
174            set
175            {
176                _gamma = value;
177            }
178        }
179        /// <summary>
180        /// Zeroeth coefficient in kernel function (default 0)
181        /// </summary>
182        public double Coefficient0
183        {
184            get
185            {
186                return _coef0;
187            }
188            set
189            {
190                _coef0 = value;
191            }
192        }
193   
194        /// <summary>
195        /// Cache memory size in MB (default 100)
196        /// </summary>
197        public double CacheSize
198        {
199            get
200            {
201                return _cacheSize;
202            }
203            set
204            {
205                _cacheSize = value;
206            }
207        }
208        /// <summary>
209        /// Tolerance of termination criterion (default 0.001)
210        /// </summary>
211        public double EPS
212        {
213            get
214            {
215                return _eps;
216            }
217            set
218            {
219                _eps = value;
220            }
221        }
222        /// <summary>
223        /// The parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
224        /// </summary>
225        public double C
226        {
227            get
228            {
229                return _C;
230            }
231            set
232            {
233                _C = value;
234            }
235        }
236        /// <summary>
237        /// Number of weights.
238        /// </summary>
239        public int WeightCount
240        {
241            get
242            {
243                return _weightCount;
244            }
245            set
246            {
247                _weightCount = value;
248            }
249        }
250        /// <summary>
251        /// Array of indicies corresponding to the Weights array (for C-SVC)
252        /// </summary>
253        public int[] WeightLabels
254        {
255            get
256            {
257                return _weightLabels;
258            }
259            set
260            {
261                _weightLabels = value;
262            }
263        }
264        /// <summary>
265        /// The parameter C of class i to weight*C in C-SVC (default 1)
266        /// </summary>
267        public double[] Weights
268        {
269            get
270            {
271                return _weights;
272            }
273            set
274            {
275                _weights = value;
276            }
277        }
278        /// <summary>
279        /// The parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
280        /// </summary>
281        public double Nu
282        {
283            get
284            {
285                return _nu;
286            }
287            set
288            {
289                _nu = value;
290            }
291        }
292        /// <summary>
293        /// The epsilon in loss function of epsilon-SVR (default 0.1)
294        /// </summary>
295        public double P
296        {
297            get
298            {
299                return _p;
300            }
301            set
302            {
303                _p = value;
304            }
305        }
306        /// <summary>
307        /// Whether to use the shrinking heuristics, (default True)
308        /// </summary>
309        public bool Shrinking
310        {
311            get
312            {
313                return _shrinking;
314            }
315            set
316            {
317                _shrinking = value;
318            }
319        }
320        /// <summary>
321        /// Whether to train an SVC or SVR model for probability estimates, (default False)
322        /// </summary>
323        public bool Probability
324        {
325            get
326            {
327                return _probability;
328            }
329            set
330            {
331                _probability = value;
332            }
333        }
334
335
336        #region ICloneable Members
337        /// <summary>
338        /// Creates a memberwise clone of this parameters object.
339        /// </summary>
340        /// <returns>The clone (as type Parameter)</returns>
341        public object Clone()
342        {
343            return base.MemberwiseClone();
344        }
345
346        #endregion
347    }
348}
Note: See TracBrowser for help on using the repository browser.