/* * 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 . */ using System; using System.Linq; using System.Collections.Generic; namespace SVM.BotSharp.MachineLearning { /// /// Contains all of the types of SVM this library can model. /// public enum SvmType { /// /// C-SVC. /// C_SVC, /// /// nu-SVC. /// NU_SVC, /// /// one-class SVM /// ONE_CLASS, /// /// epsilon-SVR /// EPSILON_SVR, /// /// nu-SVR /// NU_SVR }; /// /// Contains the various kernel types this library can use. /// public enum KernelType { /// /// Linear: u'*v /// LINEAR, /// /// Polynomial: (gamma*u'*v + coef0)^degree /// POLY, /// /// Radial basis function: exp(-gamma*|u-v|^2) /// RBF, /// /// Sigmoid: tanh(gamma*u'*v + coef0) /// SIGMOID, /// /// Precomputed kernel /// PRECOMPUTED, }; /// /// 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. /// [Serializable] public class Parameter : ICloneable { /// /// Default Constructor. Gives good default values to all parameters. /// 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(); } /// /// Type of SVM (default C-SVC) /// public SvmType SvmType{get;set;} /// /// Type of kernel function (default Polynomial) /// public KernelType KernelType{get;set;} /// /// Degree in kernel function (default 3). /// public int Degree{get;set;} /// /// Gamma in kernel function (default 1/k) /// public double Gamma{get;set;} /// /// Zeroeth coefficient in kernel function (default 0) /// public double Coefficient0{get;set;} /// /// Cache memory size in MB (default 100) /// public double CacheSize{get;set;} /// /// Tolerance of termination criterion (default 0.001) /// public double EPS{get;set;} /// /// The parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1) /// public double C{get;set;} /// /// Contains custom weights for class labels. Default weight value is 1. /// public Dictionary Weights{get; private set;} /// /// The parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5) /// public double Nu{get;set;} /// /// The epsilon in loss function of epsilon-SVR (default 0.1) /// public double P{get;set;} /// /// Whether to use the shrinking heuristics, (default True) /// public bool Shrinking{get;set;} /// /// Whether to train an SVC or SVR model for probability estimates, (default False) /// 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 /// /// Creates a memberwise clone of this parameters object. /// /// The clone (as type Parameter) public object Clone() { return base.MemberwiseClone(); } #endregion } }