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 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 | using HeuristicLab.Problems.DataAnalysis.SupportVectorMachine;
|
---|
29 | using HeuristicLab.Problems.DataAnalysis;
|
---|
30 | using HeuristicLab.Problems.DataAnalysis.Evaluators;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HeuristicLab.Optimization;
|
---|
33 | using HeuristicLab.Operators;
|
---|
34 |
|
---|
35 | namespace HeuristicLab.Problems.DataAnalysis.SupportVectorMachine.ParameterAdjustmentProblem {
|
---|
36 | [Item("SupportVectorMachineParameterAdjustmentEvaluator", "")]
|
---|
37 | [StorableClass]
|
---|
38 | public class SupportVectorMachineParameterAdjustmentEvaluator : AlgorithmOperator, ISingleObjectiveEvaluator {
|
---|
39 | private const string ParameterVectorParameterName = "ParameterVector";
|
---|
40 | private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData";
|
---|
41 | private const string SvmTypeParameterName = "SvmType";
|
---|
42 | private const string KernelTypeParameterName = "KernelType";
|
---|
43 | private const string CostParameterName = "Cost";
|
---|
44 | private const string NuParameterName = "Nu";
|
---|
45 | private const string GammaParameterName = "Gamma";
|
---|
46 | private const string EpsilonParameterName = "Epsilon";
|
---|
47 | private const string SamplesStartParameterName = "SamplesStart";
|
---|
48 | private const string SamplesEndParameterName = "SamplesEnd";
|
---|
49 | private const string NumberOfFoldsParameterName = "NumberOfFolds";
|
---|
50 | private const string QualityParameterName = "Quality";
|
---|
51 |
|
---|
52 | #region parameter properties
|
---|
53 | public ILookupParameter<RealVector> ParameterVectorParameter {
|
---|
54 | get { return (ILookupParameter<RealVector>)Parameters["ParameterVector"]; }
|
---|
55 | }
|
---|
56 | public IValueLookupParameter<DataAnalysisProblemData> DataAnalysisProblemDataParameter {
|
---|
57 | get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[DataAnalysisProblemDataParameterName]; }
|
---|
58 | }
|
---|
59 | public IValueLookupParameter<StringValue> SvmTypeParameter {
|
---|
60 | get { return (IValueLookupParameter<StringValue>)Parameters[SvmTypeParameterName]; }
|
---|
61 | }
|
---|
62 | public IValueLookupParameter<StringValue> KernelTypeParameter {
|
---|
63 | get { return (IValueLookupParameter<StringValue>)Parameters[KernelTypeParameterName]; }
|
---|
64 | }
|
---|
65 | public IValueLookupParameter<DoubleValue> NuParameter {
|
---|
66 | get { return (IValueLookupParameter<DoubleValue>)Parameters[NuParameterName]; }
|
---|
67 | }
|
---|
68 | public IValueLookupParameter<DoubleValue> CostParameter {
|
---|
69 | get { return (IValueLookupParameter<DoubleValue>)Parameters[CostParameterName]; }
|
---|
70 | }
|
---|
71 | public IValueLookupParameter<DoubleValue> GammaParameter {
|
---|
72 | get { return (IValueLookupParameter<DoubleValue>)Parameters[GammaParameterName]; }
|
---|
73 | }
|
---|
74 | public IValueLookupParameter<DoubleValue> EpsilonParameter {
|
---|
75 | get { return (IValueLookupParameter<DoubleValue>)Parameters[EpsilonParameterName]; }
|
---|
76 | }
|
---|
77 | public IValueLookupParameter<IntValue> SamplesStartParameter {
|
---|
78 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
|
---|
79 | }
|
---|
80 | public IValueLookupParameter<IntValue> SamplesEndParameter {
|
---|
81 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
|
---|
82 | }
|
---|
83 | public IValueLookupParameter<IntValue> NumberOfFoldsParameter {
|
---|
84 | get { return (IValueLookupParameter<IntValue>)Parameters[NumberOfFoldsParameterName]; }
|
---|
85 | }
|
---|
86 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
87 | get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
|
---|
88 | }
|
---|
89 | #endregion
|
---|
90 | #region properties
|
---|
91 | public RealVector ParameterVector {
|
---|
92 | get { return ParameterVectorParameter.ActualValue; }
|
---|
93 | }
|
---|
94 | public DataAnalysisProblemData DataAnalysisProblemData {
|
---|
95 | get { return DataAnalysisProblemDataParameter.ActualValue; }
|
---|
96 | }
|
---|
97 | public StringValue SvmType {
|
---|
98 | get { return SvmTypeParameter.Value; }
|
---|
99 | }
|
---|
100 | public StringValue KernelType {
|
---|
101 | get { return KernelTypeParameter.Value; }
|
---|
102 | }
|
---|
103 | public IntValue SamplesStart {
|
---|
104 | get { return SamplesStartParameter.ActualValue; }
|
---|
105 | }
|
---|
106 | public IntValue SamplesEnd {
|
---|
107 | get { return SamplesEndParameter.ActualValue; }
|
---|
108 | }
|
---|
109 | public IntValue NumberOfFolds {
|
---|
110 | get { return NumberOfFoldsParameter.ActualValue; }
|
---|
111 | }
|
---|
112 | #endregion
|
---|
113 |
|
---|
114 | public SupportVectorMachineParameterAdjustmentEvaluator()
|
---|
115 | : base() {
|
---|
116 | StringValue nuSvrType = new StringValue("NU_SVR").AsReadOnly();
|
---|
117 | StringValue rbfKernelType = new StringValue("RBF").AsReadOnly();
|
---|
118 | Parameters.Add(new LookupParameter<RealVector>(ParameterVectorParameterName, "The parameters for the SVM encoded as a real vector."));
|
---|
119 | Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The data analysis problem data to use for training."));
|
---|
120 | Parameters.Add(new ValueLookupParameter<StringValue>(SvmTypeParameterName, "The type of SVM to use.", nuSvrType));
|
---|
121 | Parameters.Add(new ValueLookupParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", rbfKernelType));
|
---|
122 | Parameters.Add(new ValueLookupParameter<DoubleValue>(NuParameterName, "The value of the nu parameter nu-SVC, one-class SVM and nu-SVR."));
|
---|
123 | Parameters.Add(new ValueLookupParameter<DoubleValue>(CostParameterName, "The value of the C (cost) parameter of C-SVC, epsilon-SVR and nu-SVR."));
|
---|
124 | Parameters.Add(new ValueLookupParameter<DoubleValue>(GammaParameterName, "The value of the gamma parameter in the kernel function."));
|
---|
125 | Parameters.Add(new ValueLookupParameter<DoubleValue>(EpsilonParameterName, "The value of the epsilon parameter of epsilon-SVR."));
|
---|
126 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The first index of the data set partition the support vector machine should use for training."));
|
---|
127 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The last index of the data set partition the support vector machine should use for training."));
|
---|
128 | Parameters.Add(new ValueLookupParameter<IntValue>(NumberOfFoldsParameterName, "The number of folds to use for cross-validation."));
|
---|
129 | Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The cross validation quality reached with the given parameters."));
|
---|
130 |
|
---|
131 |
|
---|
132 | SupportVectorMachineCrossValidationEvaluator evaluator = new SupportVectorMachineCrossValidationEvaluator();
|
---|
133 | OperatorGraph.InitialOperator = evaluator;
|
---|
134 | evaluator.Successor = null;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public override IOperation Apply() {
|
---|
138 | var point = ParameterVector;
|
---|
139 | NuParameter.Value = new DoubleValue(point[0]);
|
---|
140 | CostParameter.Value = new DoubleValue(Math.Pow(2, point[1]));
|
---|
141 | GammaParameter.Value = new DoubleValue(Math.Pow(2, point[2]));
|
---|
142 | EpsilonParameter.Value = new DoubleValue();
|
---|
143 | return base.Apply();
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|