Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/31/10 16:03:37 (15 years ago)
Author:
gkronber
Message:

Added linear regression and support vector machine algorithms for data analysis. #1012, #1009

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  
    3131using System.Drawing;
    3232using System.IO;
     33using HeuristicLab.Optimization;
    3334
    3435namespace HeuristicLab.Problems.DataAnalysis {
     
    3637  [Creatable("Problems")]
    3738  [StorableClass]
    38   public class DataAnalysisProblem : ParameterizedNamedItem {
     39  public class DataAnalysisProblem : ParameterizedNamedItem, IDataAnalysisProblem {
    3940    private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData";
    4041    public override Image ItemImage {
     
    9091
    9192    public override IDeepCloneable Clone(Cloner cloner) {
    92       DataAnalysisProblem clone = (DataAnalysisProblem) base.Clone(cloner);
     93      DataAnalysisProblem clone = (DataAnalysisProblem)base.Clone(cloner);
    9394      clone.RegisterParameterEvents();
    9495      clone.RegisterParameterValueEvents();
    9596      return clone;
    9697    }
     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
    97149  }
    98150}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj

    r3842 r3877  
    9898    <Compile Include="Evaluators\SimpleVarianceAccountedForEvaluator.cs" />
    9999    <Compile Include="HeuristicLabProblemsDataAnalysisPlugin.cs" />
     100    <Compile Include="Interfaces\IDataAnalysisProblem.cs" />
    100101    <Compile Include="MatrixExtensions.cs" />
    101102    <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" />
    102106    <Compile Include="SupportVectorMachine\SupportVectorMachineModel.cs" />
    103107    <Compile Include="SupportVectorMachine\SupportVectorMachineModelCreator.cs" />
     
    154158      <Name>HeuristicLab.Data-3.3</Name>
    155159    </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>
    156164    <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.3\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj">
    157165      <Project>{125D3006-67F5-48CB-913E-73C0548F17FA}</Project>
     
    169177      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
    170178      <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>
    171183    </ProjectReference>
    172184    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineModelCreator.cs

    r3842 r3877  
    4646    private const string NuParameterName = "Nu";
    4747    private const string GammaParameterName = "Gamma";
     48    private const string EpsilonParameterName = "Epsilon";
     49    private const string SamplesStartParameterName = "SamplesStart";
     50    private const string SamplesEndParameterName = "SamplesEnd";
    4851    private const string ModelParameterName = "SupportVectorMachineModel";
    4952
     
    5255      get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[DataAnalysisProblemDataParameterName]; }
    5356    }
    54     public IValueParameter<StringValue> SvmTypeParameter {
    55       get { return (IValueParameter<StringValue>)Parameters[SvmTypeParameterName]; }
     57    public IValueLookupParameter<StringValue> SvmTypeParameter {
     58      get { return (IValueLookupParameter<StringValue>)Parameters[SvmTypeParameterName]; }
    5659    }
    57     public IValueParameter<StringValue> KernelTypeParameter {
    58       get { return (IValueParameter<StringValue>)Parameters[KernelTypeParameterName]; }
     60    public IValueLookupParameter<StringValue> KernelTypeParameter {
     61      get { return (IValueLookupParameter<StringValue>)Parameters[KernelTypeParameterName]; }
    5962    }
    6063    public IValueLookupParameter<DoubleValue> NuParameter {
     
    6669    public IValueLookupParameter<DoubleValue> GammaParameter {
    6770      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]; }
    6880    }
    6981    public ILookupParameter<SupportVectorMachineModel> SupportVectorMachineModelParameter {
     
    90102      get { return GammaParameter.ActualValue; }
    91103    }
     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    }
    92113    #endregion
    93114
    94115    public SupportVectorMachineModelCreator()
    95116      : base() {
    96       #region svm types
    97       StringValue cSvcType = new StringValue("C_SVC").AsReadOnly();
    98       StringValue nuSvcType = new StringValue("NU_SVC").AsReadOnly();
    99       StringValue eSvrType = new StringValue("EPSILON_SVR").AsReadOnly();
    100117      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       #endregion
    107       #region kernel types
    108118      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       #endregion
    118119      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));
    121122      Parameters.Add(new ValueLookupParameter<DoubleValue>(NuParameterName, "The value of the nu parameter nu-SVC, one-class SVM and nu-SVR."));
    122123      Parameters.Add(new ValueLookupParameter<DoubleValue>(CostParameterName, "The value of the C (cost) parameter of C-SVC, epsilon-SVR and nu-SVR."));
    123124      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."));
    124128      Parameters.Add(new LookupParameter<SupportVectorMachineModel>(ModelParameterName, "The result model generated by the SVM."));
    125129    }
    126130
    127131    public override IOperation Apply() {
    128 
    129132      SupportVectorMachineModel model = TrainModel(DataAnalysisProblemData,
     133                             SamplesStart.Value, SamplesEnd.Value,
    130134                             SvmType.Value, KernelType.Value,
    131                              Cost.Value, Nu.Value, Gamma.Value);
     135                             Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value);
    132136      SupportVectorMachineModelParameter.ActualValue = model;
    133137
     
    135139    }
    136140
     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
    137148    public static SupportVectorMachineModel TrainModel(
    138149      DataAnalysisProblemData problemData,
     150      int start, int end,
    139151      string svmType, string kernelType,
    140       double cost, double nu, double gamma) {
     152      double cost, double nu, double gamma, double epsilon) {
    141153      int targetVariableIndex = problemData.Dataset.GetVariableIndex(problemData.TargetVariable.Value);
    142154
     
    148160      parameter.Nu = nu;
    149161      parameter.Gamma = gamma;
     162      parameter.P = epsilon;
    150163      parameter.CacheSize = 500;
    151164      parameter.Probability = false;
    152165
    153166
    154       SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, problemData.TrainingSamplesStart.Value, problemData.TrainingSamplesEnd.Value);
     167      SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData, start, end);
    155168      SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem);
    156169      SVM.Problem scaledProblem = Scaling.Scale(rangeTransform, problem);
    157170      var model = new SupportVectorMachineModel();
    158 
    159171      model.Model = SVM.Training.Train(scaledProblem, parameter);
    160172      model.RangeTransform = rangeTransform;
Note: See TracChangeset for help on using the changeset viewer.