-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathParameter.cs
More file actions
221 lines (198 loc) · 6.41 KB
/
Copy pathParameter.cs
File metadata and controls
221 lines (198 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* SVM.NET Library
* Copyright (C) 2008 Matthew Johnson
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Linq;
using System.Collections.Generic;
namespace Bigtree.Algorithm.SVM
{
/// <summary>
/// Contains all of the types of SVM this library can model.
/// </summary>
public enum SvmType {
/// <summary>
/// C-SVC.
/// </summary>
C_SVC,
/// <summary>
/// nu-SVC.
/// </summary>
NU_SVC,
/// <summary>
/// one-class SVM
/// </summary>
ONE_CLASS,
/// <summary>
/// epsilon-SVR
/// </summary>
EPSILON_SVR,
/// <summary>
/// nu-SVR
/// </summary>
NU_SVR
};
/// <summary>
/// Contains the various kernel types this library can use.
/// </summary>
public enum KernelType {
/// <summary>
/// Linear: u'*v
/// </summary>
LINEAR,
/// <summary>
/// Polynomial: (gamma*u'*v + coef0)^degree
/// </summary>
POLY,
/// <summary>
/// Radial basis function: exp(-gamma*|u-v|^2)
/// </summary>
RBF,
/// <summary>
/// Sigmoid: tanh(gamma*u'*v + coef0)
/// </summary>
SIGMOID,
/// <summary>
/// Precomputed kernel
/// </summary>
PRECOMPUTED,
};
/// <summary>
/// This class contains the various parameters which can affect the way in which an SVM
/// is learned. Unless you know what you are doing, chances are you are best off using
/// the default values.
/// </summary>
[Serializable]
public class Parameter : ICloneable
{
/// <summary>
/// Default Constructor. Gives good default values to all parameters.
/// </summary>
public Parameter()
{
SvmType = SvmType.C_SVC;
KernelType = KernelType.RBF;
Degree = 3;
Gamma = 0; // 1/k
Coefficient0 = 0;
Nu = 0.5;
CacheSize = 40;
C = 1;
EPS = 1e-3;
P = 0.1;
Shrinking = true;
Probability = false;
Weights = new Dictionary<int, double>();
}
/// <summary>
/// Type of SVM (default C-SVC)
/// </summary>
public SvmType SvmType{get;set;}
/// <summary>
/// Type of kernel function (default Polynomial)
/// </summary>
public KernelType KernelType{get;set;}
/// <summary>
/// Degree in kernel function (default 3).
/// </summary>
public int Degree{get;set;}
/// <summary>
/// Gamma in kernel function (default 1/k)
/// </summary>
public double Gamma{get;set;}
/// <summary>
/// Zeroeth coefficient in kernel function (default 0)
/// </summary>
public double Coefficient0{get;set;}
/// <summary>
/// Cache memory size in MB (default 100)
/// </summary>
public double CacheSize{get;set;}
/// <summary>
/// Tolerance of termination criterion (default 0.001)
/// </summary>
public double EPS{get;set;}
/// <summary>
/// The parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
/// </summary>
public double C{get;set;}
/// <summary>
/// Contains custom weights for class labels. Default weight value is 1.
/// </summary>
public Dictionary<int,double> Weights{get; private set;}
/// <summary>
/// The parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
/// </summary>
public double Nu{get;set;}
/// <summary>
/// The epsilon in loss function of epsilon-SVR (default 0.1)
/// </summary>
public double P{get;set;}
/// <summary>
/// Whether to use the shrinking heuristics, (default True)
/// </summary>
public bool Shrinking{get;set;}
/// <summary>
/// Whether to train an SVC or SVR model for probability estimates, (default False)
/// </summary>
public bool Probability{get;set;}
public override bool Equals(object obj)
{
Parameter other = obj as Parameter;
if (other == null)
return false;
return other.C == C &&
other.CacheSize == CacheSize &&
other.Coefficient0 == Coefficient0 &&
other.Degree == Degree &&
other.EPS == EPS &&
other.Gamma == Gamma &&
other.KernelType == KernelType &&
other.Nu == Nu &&
other.P == P &&
other.Probability == Probability &&
other.Shrinking == Shrinking &&
other.SvmType == SvmType &&
other.Weights.ToArray().IsEqual(Weights.ToArray());
}
public override int GetHashCode()
{
return C.GetHashCode() +
CacheSize.GetHashCode() +
Coefficient0.GetHashCode() +
Degree.GetHashCode() +
EPS.GetHashCode() +
Gamma.GetHashCode() +
KernelType.GetHashCode() +
Nu.GetHashCode() +
P.GetHashCode() +
Probability.GetHashCode() +
Shrinking.GetHashCode() +
SvmType.GetHashCode() +
Weights.ToArray().ComputeHashcode();
}
#region ICloneable Members
/// <summary>
/// Creates a memberwise clone of this parameters object.
/// </summary>
/// <returns>The clone (as type Parameter)</returns>
public object Clone()
{
return base.MemberwiseClone();
}
#endregion
}
}