- Timestamp:
- 03/05/14 13:46:33 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingContext.cs
r10383 r10536 79 79 80 80 private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) { 81 algorithm.Name = "Cloned " + algorithm.Name;81 algorithm.Name = algorithm.Name + "(Preprocessed)"; 82 82 algorithm.Runs.Clear(); 83 83 … … 85 85 } 86 86 87 private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup) where T : IItem { 87 private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup) 88 where T : IItem { 88 89 var creator = new ProblemDataCreator(this); 89 90 var data = creator.CreateProblemData(); … … 93 94 var problem = setup(clone); 94 95 problem.ProblemDataParameter.ActualValue = data; 95 problem.Name = " Cloned " + problem.Name;96 problem.Name = "Preprocessed " + problem.Name; 96 97 97 98 return clone; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/ProblemDataCreator.cs
r10383 r10536 21 21 22 22 using System; 23 using System.Linq; 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 23 using System.Collections.Generic; 27 24 using HeuristicLab.Problems.DataAnalysis; 28 25 … … 37 34 38 35 public IDataAnalysisProblemData CreateProblemData() { 36 var oldProblemData = context.Problem.ProblemData; 39 37 40 IDataAnalysisProblemData problemData = CloneProblemDataWithDataset(); 38 IDataAnalysisProblemData problemData = null; 39 40 var dataSet = context.Data.ExportToDataset(); 41 var inputVariables = context.Data.VariableNames; 42 43 if (oldProblemData is RegressionProblemData) { 44 problemData = CreateRegressionData((RegressionProblemData)oldProblemData, dataSet, inputVariables); 45 } else if (oldProblemData is ClassificationProblemData) { 46 problemData = CreateClassificationData((ClassificationProblemData)oldProblemData, dataSet, inputVariables); 47 } else if (oldProblemData is ClusteringProblemData) { 48 problemData = CreateClusteringData((ClusteringProblemData)oldProblemData, dataSet, inputVariables); 49 } else { 50 throw new NotImplementedException("The type of the DataAnalysisProblemData is not supported."); 51 } 41 52 42 53 SetTrainingAndTestPartition(problemData); 43 44 if (problemData is RegressionProblemData) {45 //SetRegressionData((RegressionProblemData)problemData);46 } else if (problemData is ClassificationProblemData) {47 //SetClassificationData((ClassificationProblemData)problemData);48 } else if (problemData is ClusteringProblemData) {49 throw new NotImplementedException();50 }51 54 52 55 return problemData; 53 56 } 54 57 55 private IDataAnalysisProblemData CloneProblemDataWithDataset() { 56 var cloner = new Cloner(); 58 private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData, Dataset dataSet, IEnumerable<string> inputVariables) { 59 var targetVariable = oldProblemData.TargetVariable; 60 // target variable must be double and must exist in the new dataset 61 return new RegressionProblemData(dataSet, inputVariables, targetVariable); 62 } 57 63 58 var problemData = context.Problem.ProblemData; 64 private IDataAnalysisProblemData CreateClassificationData(ClassificationProblemData oldProblemData, Dataset dataSet, IEnumerable<string> inputVariables) { 65 var targetVariable = oldProblemData.TargetVariable; 66 // target variable must be double and must exist in the new dataset 67 return new ClassificationProblemData(dataSet, inputVariables, targetVariable); 68 } 59 69 60 Dataset dataset = context.Data.ExportToDataset(); 61 62 cloner.RegisterClonedObject(problemData.Dataset, dataset); 63 64 return cloner.Clone(problemData); 70 private IDataAnalysisProblemData CreateClusteringData(ClusteringProblemData oldProblemData, Dataset dataSet, IEnumerable<string> inputVariables) { 71 return new ClusteringProblemData(dataSet, inputVariables); 65 72 } 66 73 … … 73 80 problemData.TestPartition.End = ppData.TestPartition.End; 74 81 } 75 76 private void SetRegressionData(RegressionProblemData regressionProblemData) {77 SetInputVariables(regressionProblemData, regressionProblemData.TargetVariable);78 SetTargetVariable(regressionProblemData.TargetVariableParameter);79 }80 81 private void SetClassificationData(ClassificationProblemData classificationProblemData) {82 SetInputVariables(classificationProblemData, classificationProblemData.TargetVariable);83 SetTargetVariable(classificationProblemData.TargetVariableParameter);84 }85 86 private void SetInputVariables(DataAnalysisProblemData problemData, string targetVariable) {87 //TODO: InputVariables Set is Readonly88 89 problemData.InputVariables.Clear();90 91 foreach (string variable in context.Data.VariableNames) {92 problemData.InputVariables.Add(new StringValue(variable), variable != targetVariable);93 }94 }95 96 private void SetTargetVariable(IConstrainedValueParameter<StringValue> targetVariableParameter) {97 string oldTarget = targetVariableParameter.Value.Value;98 99 var validValues = targetVariableParameter.ValidValues;100 validValues.Clear();101 102 foreach (string variable in context.Data.VariableNames.Where(x => context.Data.IsType<double>(x))) {103 validValues.Add(new StringValue(variable));104 }105 106 targetVariableParameter.ActualValue = validValues.FirstOrDefault(v => v.Value == oldTarget);107 }108 82 } 109 83 }
Note: See TracChangeset
for help on using the changeset viewer.