Changeset 2165 for trunk/sources/HeuristicLab.SupportVectorMachines
- Timestamp:
- 07/16/09 11:34:22 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.SupportVectorMachines/3.2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMHelper.cs
r2148 r2165 9 9 namespace HeuristicLab.SupportVectorMachines { 10 10 public class SVMHelper { 11 public static SVM.Problem CreateSVMProblem(Dataset dataset, ItemList<IntData> allowedFeatures,int targetVariable, int start, int end) {11 public static SVM.Problem CreateSVMProblem(Dataset dataset, int targetVariable, int start, int end) { 12 12 int rowCount = end - start; 13 double[] samples = dataset.Samples; 13 List<int> skippedFeatures = new List<int>(); 14 for (int i = 0; i < dataset.Columns; i++) { 15 if (i != targetVariable) { 16 if (dataset.GetRange(i, start, end) == 0) 17 skippedFeatures.Add(i); 18 } 19 } 14 20 15 List<int> skippedFeatures = new List<int>(); 16 for (int i = 0; i < allowedFeatures.Count; i++) { 17 if (dataset.GetRange(allowedFeatures[i].Data, start, end) == 0) 18 skippedFeatures.Add(i); 19 } 21 int maxColumns = dataset.Columns - skippedFeatures.Count(); 20 22 21 23 double[] targetVector = new double[rowCount]; 22 24 for (int i = 0; i < rowCount; i++) { 23 double value = samples[(start + i) * dataset.Columns + targetVariable];25 double value = dataset.GetValue(start + i, targetVariable); 24 26 targetVector[i] = value; 25 27 } … … 31 33 for (int row = 0; row < rowCount; row++) { 32 34 tempRow = new List<SVM.Node>(); 33 for (int col = 0; col < allowedFeatures.Count; col++) {34 if (!skippedFeatures.Contains(col) ) {35 double value = samples[(start + row) * dataset.Columns + allowedFeatures[col].Data];35 for (int col = 0; col < dataset.Columns; col++) { 36 if (!skippedFeatures.Contains(col) && col!=targetVariable) { 37 double value = dataset.GetValue(start + row, col); 36 38 if (!double.IsNaN(value)) 37 tempRow.Add(new SVM.Node( allowedFeatures[col].Data, value));39 tempRow.Add(new SVM.Node(col, value)); 38 40 } 39 41 } 40 if (!double.IsNaN( samples[(start + row) * dataset.Columns + targetVariable])) {42 if (!double.IsNaN(dataset.GetValue(start + row, targetVariable))) { 41 43 nodes[addedRows] = tempRow.ToArray(); 42 44 addedRows++; … … 44 46 } 45 47 46 return new SVM.Problem(targetVector.Length, targetVector, nodes, allowedFeatures.Max(x => x.Data));48 return new SVM.Problem(targetVector.Length, targetVector, nodes, maxColumns); 47 49 } 48 50 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorCreator.cs
r2163 r2165 39 39 //Dataset infos 40 40 AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In)); 41 AddVariableInfo(new VariableInfo("AllowedFeatures", "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));42 41 AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In)); 43 42 AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); … … 67 66 abortRequested = false; 68 67 Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); 69 ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);70 68 int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data; 71 69 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; … … 83 81 parameter.Gamma = GetVariableValue<DoubleData>("SVMGamma", scope, true).Data; 84 82 85 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures,targetVariable, start, end);83 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end); 86 84 SVM.RangeTransform rangeTransform = SVM.Scaling.DetermineRange(problem); 87 85 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, rangeTransform); -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs
r2148 r2165 35 35 //Dataset infos 36 36 AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In)); 37 AddVariableInfo(new VariableInfo("AllowedFeatures", "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));38 37 AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In)); 39 38 AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In)); … … 47 46 public override IOperation Apply(IScope scope) { 48 47 Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true); 49 ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);50 48 int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data; 51 49 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; … … 53 51 54 52 SVMModel modelData = GetVariableValue<SVMModel>("SVMModel", scope, true); 55 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures,targetVariable, start, end);53 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end); 56 54 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, modelData.RangeTransform); 57 55 -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableEvaluationImpactCalculator.cs
r2043 r2165 38 38 39 39 40 protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures,int start, int end) {40 protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end) { 41 41 SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true); 42 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures,targetVariable, start, end);42 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end); 43 43 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform); 44 44 -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableQualityImpactCalculator.cs
r2136 r2165 37 37 } 38 38 39 protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures,int start, int end) {39 protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) { 40 40 SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true); 41 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures,targetVariable, start, end);41 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end); 42 42 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform); 43 43
Note: See TracChangeset
for help on using the changeset viewer.