Changeset 3877 for trunk/sources/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 05/31/10 16:03:37 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3
- Files:
-
- 6 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblem.cs
r3545 r3877 31 31 using System.Drawing; 32 32 using System.IO; 33 using HeuristicLab.Optimization; 33 34 34 35 namespace HeuristicLab.Problems.DataAnalysis { … … 36 37 [Creatable("Problems")] 37 38 [StorableClass] 38 public class DataAnalysisProblem : ParameterizedNamedItem {39 public class DataAnalysisProblem : ParameterizedNamedItem, IDataAnalysisProblem { 39 40 private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData"; 40 41 public override Image ItemImage { … … 90 91 91 92 public override IDeepCloneable Clone(Cloner cloner) { 92 DataAnalysisProblem clone = (DataAnalysisProblem) 93 DataAnalysisProblem clone = (DataAnalysisProblem)base.Clone(cloner); 93 94 clone.RegisterParameterEvents(); 94 95 clone.RegisterParameterValueEvents(); 95 96 return clone; 96 97 } 98 99 #region IProblem Members 100 101 public virtual IParameter SolutionCreatorParameter { 102 get { return null; } 103 } 104 105 public virtual ISolutionCreator SolutionCreator { 106 get { return null; } 107 } 108 109 public virtual IParameter EvaluatorParameter { 110 get { return null; } 111 } 112 113 public virtual IEvaluator Evaluator { 114 get { return null; } 115 } 116 117 public virtual IEnumerable<IOperator> Operators { 118 get { return new IOperator[0]; } 119 } 120 121 public event EventHandler SolutionCreatorChanged; 122 protected void RaiseSolutionCreatorChanged(EventArgs e) { 123 var changed = SolutionCreatorChanged; 124 if (changed != null) 125 changed(this, e); 126 } 127 128 public event EventHandler EvaluatorChanged; 129 protected void RaiseEvaluatorChanged(EventArgs e) { 130 var changed = EvaluatorChanged; 131 if (changed != null) 132 changed(this, e); 133 } 134 135 public event EventHandler OperatorsChanged; 136 protected void RaiseOperatorsChanged(EventArgs e) { 137 var changed = OperatorsChanged; 138 if (changed != null) 139 changed(this, e); 140 } 141 142 public event EventHandler Reset; 143 protected void RaiseReset(EventArgs e) { 144 var changed = Reset; 145 if (changed != null) 146 changed(this, e); 147 } 148 #endregion 97 149 } 98 150 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj
r3842 r3877 98 98 <Compile Include="Evaluators\SimpleVarianceAccountedForEvaluator.cs" /> 99 99 <Compile Include="HeuristicLabProblemsDataAnalysisPlugin.cs" /> 100 <Compile Include="Interfaces\IDataAnalysisProblem.cs" /> 100 101 <Compile Include="MatrixExtensions.cs" /> 101 102 <Compile Include="Properties\AssemblyInfo.cs" /> 103 <Compile Include="SupportVectorMachine\ParameterAdjustmentProblem\SupportVectorRegressionParameterAdjustmentEvaluator.cs" /> 104 <Compile Include="SupportVectorMachine\ParameterAdjustmentProblem\SupportVectorRegressionParameterAdjustmentProblem.cs" /> 105 <Compile Include="SupportVectorMachine\SupportVectorMachineCrossValidationEvaluator.cs" /> 102 106 <Compile Include="SupportVectorMachine\SupportVectorMachineModel.cs" /> 103 107 <Compile Include="SupportVectorMachine\SupportVectorMachineModelCreator.cs" /> … … 154 158 <Name>HeuristicLab.Data-3.3</Name> 155 159 </ProjectReference> 160 <ProjectReference Include="..\..\HeuristicLab.Encodings.RealVectorEncoding\3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj"> 161 <Project>{BB6D334A-4BB6-4674-9883-31A6EBB32CAB}</Project> 162 <Name>HeuristicLab.Encodings.RealVectorEncoding-3.3</Name> 163 </ProjectReference> 156 164 <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.3\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj"> 157 165 <Project>{125D3006-67F5-48CB-913E-73C0548F17FA}</Project> … … 169 177 <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project> 170 178 <Name>HeuristicLab.Operators-3.3</Name> 179 </ProjectReference> 180 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 181 <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project> 182 <Name>HeuristicLab.Optimization-3.3</Name> 171 183 </ProjectReference> 172 184 <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj"> -
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.