Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/ParameterAdjustmentProblem/SupportVectorMachineParameterAdjustmentEvaluator.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 7.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.DataAnalysis.SupportVectorMachine.ParameterAdjustmentProblem {
32  [Item("SupportVectorMachineParameterAdjustmentEvaluator", "")]
33  [StorableClass]
34  public class SupportVectorMachineParameterAdjustmentEvaluator : AlgorithmOperator, ISingleObjectiveEvaluator {
35    private const string ParameterVectorParameterName = "ParameterVector";
36    private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData";
37    private const string SvmTypeParameterName = "SvmType";
38    private const string KernelTypeParameterName = "KernelType";
39    private const string CostParameterName = "Cost";
40    private const string NuParameterName = "Nu";
41    private const string GammaParameterName = "Gamma";
42    private const string EpsilonParameterName = "Epsilon";
43    private const string SamplesStartParameterName = "SamplesStart";
44    private const string SamplesEndParameterName = "SamplesEnd";
45    private const string NumberOfFoldsParameterName = "NumberOfFolds";
46    private const string QualityParameterName = "Quality";
47
48    #region parameter properties
49    public ILookupParameter<RealVector> ParameterVectorParameter {
50      get { return (ILookupParameter<RealVector>)Parameters["ParameterVector"]; }
51    }
52    public IValueLookupParameter<DataAnalysisProblemData> DataAnalysisProblemDataParameter {
53      get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[DataAnalysisProblemDataParameterName]; }
54    }
55    public IValueLookupParameter<StringValue> SvmTypeParameter {
56      get { return (IValueLookupParameter<StringValue>)Parameters[SvmTypeParameterName]; }
57    }
58    public IValueLookupParameter<StringValue> KernelTypeParameter {
59      get { return (IValueLookupParameter<StringValue>)Parameters[KernelTypeParameterName]; }
60    }
61    public IValueLookupParameter<DoubleValue> NuParameter {
62      get { return (IValueLookupParameter<DoubleValue>)Parameters[NuParameterName]; }
63    }
64    public IValueLookupParameter<DoubleValue> CostParameter {
65      get { return (IValueLookupParameter<DoubleValue>)Parameters[CostParameterName]; }
66    }
67    public IValueLookupParameter<DoubleValue> GammaParameter {
68      get { return (IValueLookupParameter<DoubleValue>)Parameters[GammaParameterName]; }
69    }
70    public IValueLookupParameter<DoubleValue> EpsilonParameter {
71      get { return (IValueLookupParameter<DoubleValue>)Parameters[EpsilonParameterName]; }
72    }
73    public IValueLookupParameter<IntValue> SamplesStartParameter {
74      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
75    }
76    public IValueLookupParameter<IntValue> SamplesEndParameter {
77      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
78    }
79    public IValueLookupParameter<IntValue> NumberOfFoldsParameter {
80      get { return (IValueLookupParameter<IntValue>)Parameters[NumberOfFoldsParameterName]; }
81    }
82    public ILookupParameter<DoubleValue> QualityParameter {
83      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
84    }
85    #endregion
86    #region properties
87    public RealVector ParameterVector {
88      get { return ParameterVectorParameter.ActualValue; }
89    }
90    public DataAnalysisProblemData DataAnalysisProblemData {
91      get { return DataAnalysisProblemDataParameter.ActualValue; }
92    }
93    public StringValue SvmType {
94      get { return SvmTypeParameter.Value; }
95    }
96    public StringValue KernelType {
97      get { return KernelTypeParameter.Value; }
98    }
99    public IntValue SamplesStart {
100      get { return SamplesStartParameter.ActualValue; }
101    }
102    public IntValue SamplesEnd {
103      get { return SamplesEndParameter.ActualValue; }
104    }
105    public IntValue NumberOfFolds {
106      get { return NumberOfFoldsParameter.ActualValue; }
107    }
108    #endregion
109
110    public SupportVectorMachineParameterAdjustmentEvaluator()
111      : base() {
112      StringValue nuSvrType = new StringValue("NU_SVR").AsReadOnly();
113      StringValue rbfKernelType = new StringValue("RBF").AsReadOnly();
114      Parameters.Add(new LookupParameter<RealVector>(ParameterVectorParameterName, "The parameters for the SVM encoded as a real vector."));
115      Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The data analysis problem data to use for training."));
116      Parameters.Add(new ValueLookupParameter<StringValue>(SvmTypeParameterName, "The type of SVM to use.", nuSvrType));
117      Parameters.Add(new ValueLookupParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", rbfKernelType));
118      Parameters.Add(new ValueLookupParameter<DoubleValue>(NuParameterName, "The value of the nu parameter nu-SVC, one-class SVM and nu-SVR."));
119      Parameters.Add(new ValueLookupParameter<DoubleValue>(CostParameterName, "The value of the C (cost) parameter of C-SVC, epsilon-SVR and nu-SVR."));
120      Parameters.Add(new ValueLookupParameter<DoubleValue>(GammaParameterName, "The value of the gamma parameter in the kernel function."));
121      Parameters.Add(new ValueLookupParameter<DoubleValue>(EpsilonParameterName, "The value of the epsilon parameter of epsilon-SVR."));
122      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The first index of the data set partition the support vector machine should use for training."));
123      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The last index of the data set partition the support vector machine should use for training."));
124      Parameters.Add(new ValueLookupParameter<IntValue>(NumberOfFoldsParameterName, "The number of folds to use for cross-validation."));
125      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The cross validation quality reached with the given parameters."));
126
127
128      SupportVectorMachineCrossValidationEvaluator evaluator = new SupportVectorMachineCrossValidationEvaluator();
129      OperatorGraph.InitialOperator = evaluator;
130      evaluator.Successor = null;
131    }
132
133    public override IOperation Apply() {
134      var point = ParameterVector;
135      NuParameter.Value = new DoubleValue(point[0]);
136      CostParameter.Value = new DoubleValue(Math.Pow(2, point[1]));
137      GammaParameter.Value = new DoubleValue(Math.Pow(2, point[2]));
138      EpsilonParameter.Value = new DoubleValue();
139      return base.Apply();
140    }
141  }
142}
Note: See TracBrowser for help on using the repository browser.