/*
* 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;
namespace SVM
{
///
/// 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
{
private SvmType _svmType;
private KernelType _kernelType;
private int _degree;
private double _gamma;
private double _coef0;
private double _cacheSize;
private double _C;
private double _eps;
private int _weightCount;
private int[] _weightLabels;
private double[] _weights;
private double _nu;
private double _p;
private bool _shrinking;
private bool _probability;
///
/// Default Constructor. Gives good default values to all parameters.
///
public Parameter()
{
_svmType = SvmType.C_SVC;
_kernelType = KernelType.RBF;
_degree = 3;
_gamma = 0; // 1/k
_coef0 = 0;
_nu = 0.5;
_cacheSize = 40;
_C = 1;
_eps = 1e-3;
_p = 0.1;
_shrinking = true;
_probability = false;
_weightCount = 0;
_weightLabels = new int[0];
_weights = new double[0];
}
///
/// Type of SVM (default C-SVC)
///
public SvmType SvmType
{
get
{
return _svmType;
}
set
{
_svmType = value;
}
}
///
/// Type of kernel function (default Polynomial)
///
public KernelType KernelType
{
get
{
return _kernelType;
}
set
{
_kernelType = value;
}
}
///
/// Degree in kernel function (default 3).
///
public int Degree
{
get
{
return _degree;
}
set
{
_degree = value;
}
}
///
/// Gamma in kernel function (default 1/k)
///
public double Gamma
{
get
{
return _gamma;
}
set
{
_gamma = value;
}
}
///
/// Zeroeth coefficient in kernel function (default 0)
///
public double Coefficient0
{
get
{
return _coef0;
}
set
{
_coef0 = value;
}
}
///
/// Cache memory size in MB (default 100)
///
public double CacheSize
{
get
{
return _cacheSize;
}
set
{
_cacheSize = value;
}
}
///
/// Tolerance of termination criterion (default 0.001)
///
public double EPS
{
get
{
return _eps;
}
set
{
_eps = value;
}
}
///
/// The parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
///
public double C
{
get
{
return _C;
}
set
{
_C = value;
}
}
///
/// Number of weights.
///
public int WeightCount
{
get
{
return _weightCount;
}
set
{
_weightCount = value;
}
}
///
/// Array of indicies corresponding to the Weights array (for C-SVC)
///
public int[] WeightLabels
{
get
{
return _weightLabels;
}
set
{
_weightLabels = value;
}
}
///
/// The parameter C of class i to weight*C in C-SVC (default 1)
///
public double[] Weights
{
get
{
return _weights;
}
set
{
_weights = value;
}
}
///
/// The parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
///
public double Nu
{
get
{
return _nu;
}
set
{
_nu = value;
}
}
///
/// The epsilon in loss function of epsilon-SVR (default 0.1)
///
public double P
{
get
{
return _p;
}
set
{
_p = value;
}
}
///
/// Whether to use the shrinking heuristics, (default True)
///
public bool Shrinking
{
get
{
return _shrinking;
}
set
{
_shrinking = value;
}
}
///
/// Whether to train an SVC or SVR model for probability estimates, (default False)
///
public bool Probability
{
get
{
return _probability;
}
set
{
_probability = value;
}
}
#region ICloneable Members
///
/// Creates a memberwise clone of this parameters object.
///
/// The clone (as type Parameter)
public object Clone()
{
return base.MemberwiseClone();
}
#endregion
}
}