Changeset 5626
- Timestamp:
- 03/07/11 18:45:46 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4
- Files:
-
- 2 added
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r5624 r5626 120 120 </Compile> 121 121 <Compile Include="Properties\AssemblyInfo.cs" /> 122 <Compile Include="SupportVectorMachine\SupportVectorClassification.cs" /> 123 <Compile Include="SupportVectorMachine\SupportVectorClassificationSolution.cs" /> 124 <Compile Include="SupportVectorMachine\SupportVectorMachineModel.cs" /> 122 125 <Compile Include="SupportVectorMachine\SupportVectorMachineUtil.cs"> 123 126 <SubType>Code</SubType> 124 127 </Compile> 125 128 <Compile Include="SupportVectorMachine\SupportVectorRegression.cs"> 126 <SubType>Code</SubType>127 </Compile>128 <Compile Include="SupportVectorMachine\SupportVectorRegressionModel.cs">129 129 <SubType>Code</SubType> 130 130 </Compile> -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r5624 r5626 33 33 namespace HeuristicLab.Algorithms.DataAnalysis { 34 34 /// <summary> 35 /// Represents a support vector machine regressionmodel.35 /// Represents a support vector machine model. 36 36 /// </summary> 37 37 [StorableClass] 38 [Item("SupportVector RegressionModel", "Represents a support vector machine regressionmodel.")]39 public sealed class SupportVector RegressionModel : NamedItem, IRegressionModel {38 [Item("SupportVectorMachineModel", "Represents a support vector machine model.")] 39 public sealed class SupportVectorMachineModel : NamedItem, IRegressionModel, IClassificationModel { 40 40 [StorableConstructor] 41 private SupportVector RegressionModel(bool deserializing) : base(deserializing) { }42 private SupportVector RegressionModel(SupportVectorRegressionModel original, Cloner cloner)41 private SupportVectorMachineModel(bool deserializing) : base(deserializing) { } 42 private SupportVectorMachineModel(SupportVectorMachineModel original, Cloner cloner) 43 43 : base(original, cloner) { 44 44 // only using a shallow copy here! (gkronber) … … 46 46 this.rangeTransform = original.rangeTransform; 47 47 } 48 public SupportVector RegressionModel() : base() { }48 public SupportVectorMachineModel() : base() { } 49 49 50 50 private SVM.Model model; … … 77 77 } 78 78 } 79 #region IRegressionModel Members 80 public IEnumerable<double> GetEstimatedValues(IRegressionProblemData problemData, IEnumerable<int> rows) { 81 return GetEstimatedValues(problemData, problemData.TargetVariable, rows); 82 } 83 #endregion 84 #region IClassificationModel Members 85 public IEnumerable<double> GetEstimatedValues(IClassificationProblemData problemData, IEnumerable<int> rows) { 86 return GetEstimatedValues(problemData, problemData.TargetVariable, rows); 87 } 79 88 80 public IEnumerable<double> GetEstimatedValues(IRegressionProblemData problemData, IEnumerable<int> rows) { 89 public IEnumerable<double> GetEstimatedClassValues(IClassificationProblemData problemData, IEnumerable<int> rows) { 90 return GetEstimatedValues(problemData, problemData.TargetVariable, rows); 91 } 92 #endregion 93 private IEnumerable<double> GetEstimatedValues(IDataAnalysisProblemData problemData, string targetVariable, IEnumerable<int> rows) { 81 94 var allowedInputVariables = problemData.InputVariables.CheckedItems.Select(x => x.Value); 82 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData.Dataset, problemData.TargetVariable, allowedInputVariables, rows);95 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(problemData.Dataset, targetVariable, allowedInputVariables, rows); 83 96 SVM.Problem scaledProblem = Scaling.Scale(RangeTransform, problem); 84 97 … … 87 100 .ToList(); 88 101 } 89 90 102 #region events 91 103 public event EventHandler Changed; … … 139 151 140 152 public override IDeepCloneable Clone(Cloner cloner) { 141 return new SupportVector RegressionModel(this, cloner);153 return new SupportVectorMachineModel(this, cloner); 142 154 } 143 155 … … 145 157 /// Exports the <paramref name="model"/> in string representation to stream <paramref name="s"/> 146 158 /// </summary> 147 /// <param name="model">The support vector regressionmodel to export</param>159 /// <param name="model">The support vector machine model to export</param> 148 160 /// <param name="s">The stream to export the model to</param> 149 public static void Export(SupportVector RegressionModel model, Stream s) {161 public static void Export(SupportVectorMachineModel model, Stream s) { 150 162 StreamWriter writer = new StreamWriter(s); 151 163 writer.WriteLine("RangeTransform:"); … … 171 183 /// <param name="reader">The reader to retrieve the string representation from</param> 172 184 /// <returns>The imported support vector machine model.</returns> 173 public static SupportVector RegressionModel Import(TextReader reader) {174 SupportVector RegressionModel model = new SupportVectorRegressionModel();185 public static SupportVectorMachineModel Import(TextReader reader) { 186 SupportVectorMachineModel model = new SupportVectorMachineModel(); 175 187 while (reader.ReadLine().Trim() != "RangeTransform:") ; // read until line "RangeTransform"; 176 188 model.RangeTransform = SVM.RangeTransform.Read(reader); -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegression.cs
r5624 r5626 95 95 public SupportVectorRegression() 96 96 : base() { 97 StringValue nuSvrType = new StringValue("NU_SVR").AsReadOnly(); 98 StringValue rbfKernelType = new StringValue("RBF").AsReadOnly(); 99 Parameters.Add(new ValueParameter<StringValue>(SvmTypeParameterName, "The type of SVM to use.", nuSvrType)); 100 Parameters.Add(new ValueParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", rbfKernelType)); 101 Parameters.Add(new ValueParameter<DoubleValue>(NuParameterName, "The value of the nu parameter nu-SVC, one-class SVM and nu-SVR.", new DoubleValue(1.0))); 102 Parameters.Add(new ValueParameter<DoubleValue>(CostParameterName, "The value of the C (cost) parameter of C-SVC, epsilon-SVR and nu-SVR.", new DoubleValue(1.0))); 97 List<StringValue> svrTypes = (from type in new List<string> { "NU_SVR", "EPSILON_SVR" } 98 select new StringValue(type).AsReadOnly()) 99 .ToList(); 100 ItemSet<StringValue> svrTypeSet = new ItemSet<StringValue>(svrTypes); 101 List<StringValue> kernelTypes = (from type in new List<string> { "LINEAR", "POLY", "SIGMOID", "RBF" } 102 select new StringValue(type).AsReadOnly()) 103 .ToList(); 104 ItemSet<StringValue> kernelTypeSet = new ItemSet<StringValue>(svrTypes); 105 Parameters.Add(new ConstrainedValueParameter<StringValue>(SvmTypeParameterName, "The type of SVM to use.", svrTypeSet, svrTypes[0])); 106 Parameters.Add(new ConstrainedValueParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", kernelTypeSet, kernelTypes[3])); 107 Parameters.Add(new ValueParameter<DoubleValue>(NuParameterName, "The value of the nu parameter of the nu-SVR.", new DoubleValue(0.5))); 108 Parameters.Add(new ValueParameter<DoubleValue>(CostParameterName, "The value of the C (cost) parameter of epsilon-SVR and nu-SVR.", new DoubleValue(1.0))); 103 109 Parameters.Add(new ValueParameter<DoubleValue>(GammaParameterName, "The value of the gamma parameter in the kernel function.", new DoubleValue(1.0))); 104 Parameters.Add(new ValueParameter<DoubleValue>(EpsilonParameterName, "The value of the epsilon parameter for epsilon-SVR.", new DoubleValue( 1.0)));110 Parameters.Add(new ValueParameter<DoubleValue>(EpsilonParameterName, "The value of the epsilon parameter for epsilon-SVR.", new DoubleValue(0.1))); 105 111 } 106 112 [StorableHook(HookType.AfterDeserialization)] … … 143 149 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 144 150 SVM.Problem scaledProblem = SVM.Scaling.Scale(rangeTransform, problem); 145 var model = new SupportVector RegressionModel();151 var model = new SupportVectorMachineModel(); 146 152 model.Model = SVM.Training.Train(scaledProblem, parameter); 147 153 model.RangeTransform = rangeTransform; -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegressionSolution.cs
r5624 r5626 37 37 public sealed class SupportVectorRegressionSolution : RegressionSolution { 38 38 39 public new SupportVector RegressionModel Model {40 get { return (SupportVector RegressionModel)base.Model; }39 public new SupportVectorMachineModel Model { 40 get { return (SupportVectorMachineModel)base.Model; } 41 41 } 42 43 //IRegressionModel IRegressionSolution.Model {44 // get { return model; }45 //}46 //IDataAnalysisModel IDataAnalysisSolution.Model {47 // get { return model; }48 //}49 50 //[Storable]51 //private IRegressionProblemData problemData;52 //public IRegressionProblemData ProblemData {53 // get { return problemData; }54 //}55 //IDataAnalysisProblemData IDataAnalysisSolution.ProblemData {56 // get { return ProblemData; }57 //}58 42 59 43 [Storable] … … 76 60 } 77 61 78 79 //public event EventHandler ModelChanged;80 81 //public event EventHandler ProblemDataChanged;82 83 62 public Dataset SupportVectors { 84 63 get { return CalculateSupportVectors(); } 85 64 } 86 87 //private List<double> estimatedValues;88 65 89 66 [StorableConstructor] … … 91 68 private SupportVectorRegressionSolution(SupportVectorRegressionSolution original, Cloner cloner) 92 69 : base(original, cloner) { 93 //problemData = cloner.Clone(original.problemData);94 //model = cloner.Clone(original.model);95 70 inputVariables = new List<string>(original.inputVariables); 96 71 lowerEstimationLimit = original.lowerEstimationLimit; 97 72 upperEstimationLimit = original.upperEstimationLimit; 98 73 } 99 public SupportVectorRegressionSolution(SupportVector RegressionModel model, IRegressionProblemData problemData, IEnumerable<string> inputVariables, double lowerEstimationLimit, double upperEstimationLimit)74 public SupportVectorRegressionSolution(SupportVectorMachineModel model, IRegressionProblemData problemData, IEnumerable<string> inputVariables, double lowerEstimationLimit, double upperEstimationLimit) 100 75 : base(model, problemData) { 101 //this.problemData = problemData;102 //this.model = model;103 76 this.inputVariables = new List<string>(inputVariables); 104 77 this.lowerEstimationLimit = lowerEstimationLimit; … … 115 88 } 116 89 117 //public IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) {118 // if (estimatedValues == null) RecalculateEstimatedValues();119 // foreach (int row in rows)120 // yield return estimatedValues[row];121 //}122 123 //public override IEnumerable<double> EstimatedValues {124 // get {125 // if (estimatedValues == null) RecalculateEstimatedValues();126 // return estimatedValues;127 // }128 //}129 130 //public override IEnumerable<double> EstimatedTrainingValues {131 // get {132 // return GetEstimatedValues(ProblemData.TrainingIndizes);133 // }134 //}135 136 //public override IEnumerable<double> EstimatedTestValues {137 // get {138 // return GetEstimatedValues(ProblemData.TestIndizes);139 // }140 //}141 90 142 91 private Dataset CalculateSupportVectors() { … … 151 100 return new Dataset(ProblemData.Dataset.VariableNames, data); 152 101 } 153 154 //protected override void RecalculateEstimatedValues() {155 // Dataset dataset = problemData.Dataset;156 // string targetVariable = problemData.TargetVariable;157 // IEnumerable<string> allowedInputVariables = problemData.InputVariables.CheckedItems.Select(x => x.Value);158 // int start = 0;159 // int end = dataset.Rows;160 // IEnumerable<int> rows = Enumerable.Range(start, end - start);161 // SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows);162 // SVM.Problem scaledProblem = SVM.Scaling.Scale(Model.RangeTransform, problem);163 164 // estimatedValues = (from row in Enumerable.Range(0, scaledProblem.Count)165 // let prediction = SVM.Prediction.Predict(Model.Model, scaledProblem.X[row])166 // let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, prediction))167 // select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX).ToList();168 //}169 102 } 170 103 }
Note: See TracChangeset
for help on using the changeset viewer.