- Timestamp:
- 05/31/10 16:03:37 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModelCreator.cs
r3842 r3877 46 46 private const string NuParameterName = "Nu"; 47 47 private const string GammaParameterName = "Gamma"; 48 private const string EpsilonParameterName = "Epsilon"; 49 private const string SamplesStartParameterName = "SamplesStart"; 50 private const string SamplesEndParameterName = "SamplesEnd"; 48 51 private const string ModelParameterName = "SupportVectorMachineModel"; 49 52 … … 52 55 get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[DataAnalysisProblemDataParameterName]; } 53 56 } 54 public IValue Parameter<StringValue> SvmTypeParameter {55 get { return (IValue Parameter<StringValue>)Parameters[SvmTypeParameterName]; }57 public IValueLookupParameter<StringValue> SvmTypeParameter { 58 get { return (IValueLookupParameter<StringValue>)Parameters[SvmTypeParameterName]; } 56 59 } 57 public IValue Parameter<StringValue> KernelTypeParameter {58 get { return (IValue Parameter<StringValue>)Parameters[KernelTypeParameterName]; }60 public IValueLookupParameter<StringValue> KernelTypeParameter { 61 get { return (IValueLookupParameter<StringValue>)Parameters[KernelTypeParameterName]; } 59 62 } 60 63 public IValueLookupParameter<DoubleValue> NuParameter { … … 66 69 public IValueLookupParameter<DoubleValue> GammaParameter { 67 70 get { return (IValueLookupParameter<DoubleValue>)Parameters[GammaParameterName]; } 71 } 72 public IValueLookupParameter<DoubleValue> EpsilonParameter { 73 get { return (IValueLookupParameter<DoubleValue>)Parameters[EpsilonParameterName]; } 74 } 75 public IValueLookupParameter<IntValue> SamplesStartParameter { 76 get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; } 77 } 78 public IValueLookupParameter<IntValue> SamplesEndParameter { 79 get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; } 68 80 } 69 81 public ILookupParameter<SupportVectorMachineModel> SupportVectorMachineModelParameter { … … 90 102 get { return GammaParameter.ActualValue; } 91 103 } 104 public DoubleValue Epsilon { 105 get { return EpsilonParameter.ActualValue; } 106 } 107 public IntValue SamplesStart { 108 get { return SamplesStartParameter.ActualValue; } 109 } 110 public IntValue SamplesEnd { 111 get { return SamplesEndParameter.ActualValue; } 112 } 92 113 #endregion 93 114 94 115 public SupportVectorMachineModelCreator() 95 116 : base() { 96 #region svm types97 StringValue cSvcType = new StringValue("C_SVC").AsReadOnly();98 StringValue nuSvcType = new StringValue("NU_SVC").AsReadOnly();99 StringValue eSvrType = new StringValue("EPSILON_SVR").AsReadOnly();100 117 StringValue nuSvrType = new StringValue("NU_SVR").AsReadOnly(); 101 ItemSet<StringValue> allowedSvmTypes = new ItemSet<StringValue>();102 allowedSvmTypes.Add(cSvcType);103 allowedSvmTypes.Add(nuSvcType);104 allowedSvmTypes.Add(eSvrType);105 allowedSvmTypes.Add(nuSvrType);106 #endregion107 #region kernel types108 118 StringValue rbfKernelType = new StringValue("RBF").AsReadOnly(); 109 StringValue linearKernelType = new StringValue("LINEAR").AsReadOnly();110 StringValue polynomialKernelType = new StringValue("POLY").AsReadOnly();111 StringValue sigmoidKernelType = new StringValue("SIGMOID").AsReadOnly();112 ItemSet<StringValue> allowedKernelTypes = new ItemSet<StringValue>();113 allowedKernelTypes.Add(rbfKernelType);114 allowedKernelTypes.Add(linearKernelType);115 allowedKernelTypes.Add(polynomialKernelType);116 allowedKernelTypes.Add(sigmoidKernelType);117 #endregion118 119 Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The data analysis problem data to use for training.")); 119 Parameters.Add(new ConstrainedValueParameter<StringValue>(SvmTypeParameterName, "The type of SVM to use.", allowedSvmTypes, nuSvrType));120 Parameters.Add(new ConstrainedValueParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", allowedKernelTypes, rbfKernelType));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)); 121 122 Parameters.Add(new ValueLookupParameter<DoubleValue>(NuParameterName, "The value of the nu parameter nu-SVC, one-class SVM and nu-SVR.")); 122 123 Parameters.Add(new ValueLookupParameter<DoubleValue>(CostParameterName, "The value of the C (cost) parameter of C-SVC, epsilon-SVR and nu-SVR.")); 123 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 for 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.")); 124 128 Parameters.Add(new LookupParameter<SupportVectorMachineModel>(ModelParameterName, "The result model generated by the SVM.")); 125 129 } 126 130 127 131 public override IOperation Apply() { 128 129 132 SupportVectorMachineModel model = TrainModel(DataAnalysisProblemData, 133 SamplesStart.Value, SamplesEnd.Value, 130 134 SvmType.Value, KernelType.Value, 131 Cost.Value, Nu.Value, Gamma.Value );135 Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value); 132 136 SupportVectorMachineModelParameter.ActualValue = model; 133 137 … … 135 139 } 136 140 141 private static SupportVectorMachineModel TrainModel( 142 DataAnalysisProblemData problemData, 143 string svmType, string kernelType, 144 double cost, double nu, double gamma, double epsilon) { 145 return TrainModel(problemData, problemData.TrainingSamplesStart.Value, problemData.TrainingSamplesEnd.Value, svmType, kernelType, cost, nu, gamma, epsilon); 146 } 147 137 148 public static SupportVectorMachineModel TrainModel( 138 149 DataAnalysisProblemData problemData, 150 int start, int end, 139 151 string svmType, string kernelType, 140 double cost, double nu, double gamma ) {152 double cost, double nu, double gamma, double epsilon) { 141 153 int targetVariableIndex = problemData.Dataset.GetVariableIndex(problemData.TargetVariable.Value); 142 154 … … 148 160 parameter.Nu = nu; 149 161 parameter.Gamma = gamma; 162 parameter.P = epsilon; 150 163 parameter.CacheSize = 500; 151 164 parameter.Probability = false; 152 165 153 166 154 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, problemData.TrainingSamplesStart.Value, problemData.TrainingSamplesEnd.Value);167 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, start, end); 155 168 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 156 169 SVM.Problem scaledProblem = Scaling.Scale(rangeTransform, problem); 157 170 var model = new SupportVectorMachineModel(); 158 159 171 model.Model = SVM.Training.Train(scaledProblem, parameter); 160 172 model.RangeTransform = rangeTransform;
Note: See TracChangeset
for help on using the changeset viewer.