Changeset 8613


Ignore:
Timestamp:
09/10/12 13:31:13 (8 years ago)
Author:
gkronber
Message:

#1947: added degree parameter for the polynomial kernel of the SVM

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassification.cs

    r8609 r8613  
    4545    private const string NuParameterName = "Nu";
    4646    private const string GammaParameterName = "Gamma";
     47    private const string DegreeParameterName = "Degree";
    4748
    4849    #region parameter properties
     
    6162    public IValueParameter<DoubleValue> GammaParameter {
    6263      get { return (IValueParameter<DoubleValue>)Parameters[GammaParameterName]; }
     64    }
     65    public IValueParameter<IntValue> DegreeParameter {
     66      get { return (IValueParameter<IntValue>)Parameters[DegreeParameterName]; }
    6367    }
    6468    #endregion
     
    8084    public DoubleValue Gamma {
    8185      get { return GammaParameter.Value; }
     86    }
     87    public IntValue Degree {
     88      get { return DegreeParameter.Value; }
    8289    }
    8390    #endregion
     
    104111      Parameters.Add(new ValueParameter<DoubleValue>(CostParameterName, "The value of the C (cost) parameter of C-SVC.", new DoubleValue(1.0)));
    105112      Parameters.Add(new ValueParameter<DoubleValue>(GammaParameterName, "The value of the gamma parameter in the kernel function.", new DoubleValue(1.0)));
     113      Parameters.Add(new ValueParameter<IntValue>(DegreeParameterName, "The degree parameter for the polynomial kernel function.", new IntValue(3)));
    106114    }
    107115    [StorableHook(HookType.AfterDeserialization)]
    108     private void AfterDeserialization() { }
     116    private void AfterDeserialization() {
     117      #region backwards compatibility (change with 3.4)
     118      if (!Parameters.ContainsKey(DegreeParameterName))
     119        Parameters.Add(new ValueParameter<IntValue>(DegreeParameterName, "The degree parameter for the polynomial kernel function.", new IntValue(3)));
     120      #endregion
     121    }
    109122
    110123    public override IDeepCloneable Clone(Cloner cloner) {
     
    119132      int nSv;
    120133      var solution = CreateSupportVectorClassificationSolution(problemData, selectedInputVariables,
    121         SvmType.Value, KernelType.Value, Cost.Value, Nu.Value, Gamma.Value,
     134        SvmType.Value, KernelType.Value, Cost.Value, Nu.Value, Gamma.Value, Degree.Value,
    122135        out trainingAccuracy, out testAccuracy, out nSv);
    123136
     
    129142
    130143    public static SupportVectorClassificationSolution CreateSupportVectorClassificationSolution(IClassificationProblemData problemData, IEnumerable<string> allowedInputVariables,
    131       string svmType, string kernelType, double cost, double nu, double gamma,
     144      string svmType, string kernelType, double cost, double nu, double gamma, int degree,
    132145      out double trainingAccuracy, out double testAccuracy, out int nSv) {
    133146      Dataset dataset = problemData.Dataset;
     
    145158      parameter.probability = 0;
    146159      parameter.eps = 0.001;
    147       parameter.degree = 3;
     160      parameter.degree = degree;
    148161      parameter.shrinking = 1;
    149162      parameter.coef0 = 0;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegression.cs

    r8609 r8613  
    4646    private const string GammaParameterName = "Gamma";
    4747    private const string EpsilonParameterName = "Epsilon";
     48    private const string DegreeParameterName = "Degree";
    4849
    4950    #region parameter properties
     
    6566    public IValueParameter<DoubleValue> EpsilonParameter {
    6667      get { return (IValueParameter<DoubleValue>)Parameters[EpsilonParameterName]; }
     68    }
     69    public IValueParameter<IntValue> DegreeParameter {
     70      get { return (IValueParameter<IntValue>)Parameters[DegreeParameterName]; }
    6771    }
    6872    #endregion
     
    8791    public DoubleValue Epsilon {
    8892      get { return EpsilonParameter.Value; }
     93    }
     94    public IntValue Degree {
     95      get { return DegreeParameter.Value; }
    8996    }
    9097    #endregion
     
    112119      Parameters.Add(new ValueParameter<DoubleValue>(GammaParameterName, "The value of the gamma parameter in the kernel function.", new DoubleValue(1.0)));
    113120      Parameters.Add(new ValueParameter<DoubleValue>(EpsilonParameterName, "The value of the epsilon parameter for epsilon-SVR.", new DoubleValue(0.1)));
     121      Parameters.Add(new ValueParameter<IntValue>(DegreeParameterName, "The degree parameter for the polynomial kernel function.", new IntValue(3)));
    114122    }
    115123    [StorableHook(HookType.AfterDeserialization)]
    116     private void AfterDeserialization() { }
     124    private void AfterDeserialization() {
     125      #region backwards compatibility (change with 3.4)
     126      if (!Parameters.ContainsKey(DegreeParameterName))
     127        Parameters.Add(new ValueParameter<IntValue>(DegreeParameterName, "The degree parameter for the polynomial kernel function.", new IntValue(3)));
     128      #endregion
     129    }
    117130
    118131    public override IDeepCloneable Clone(Cloner cloner) {
     
    127140      int nSv;
    128141      var solution = CreateSupportVectorRegressionSolution(problemData, selectedInputVariables, SvmType.Value,
    129         KernelType.Value, Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value,
     142        KernelType.Value, Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value, Degree.Value,
    130143        out trainR2, out testR2, out nSv);
    131144
     
    137150
    138151    public static SupportVectorRegressionSolution CreateSupportVectorRegressionSolution(IRegressionProblemData problemData, IEnumerable<string> allowedInputVariables,
    139       string svmType, string kernelType, double cost, double nu, double gamma, double epsilon,
     152      string svmType, string kernelType, double cost, double nu, double gamma, double epsilon, int degree,
    140153      out double trainingR2, out double testR2, out int nSv) {
    141154      Dataset dataset = problemData.Dataset;
     
    154167      parameter.probability = 0;
    155168      parameter.eps = 0.001;
    156       parameter.degree = 3;
     169      parameter.degree = degree;
    157170      parameter.shrinking = 1;
    158171      parameter.coef0 = 0;
Note: See TracChangeset for help on using the changeset viewer.