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