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/SupportVectorMachine
Files:
4 added
1 edited

Legend:

Unmodified
Added
Removed
  • 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.