Changeset 10383 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/ProblemDataCreator.cs
- Timestamp:
- 01/22/14 16:53:31 (11 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/ProblemDataCreator.cs
r10382 r10383 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 26 using HeuristicLab.Optimization;27 27 using HeuristicLab.Problems.DataAnalysis; 28 28 29 29 namespace HeuristicLab.DataPreprocessing { 30 internal class Pr eprocessingCloner {30 internal class ProblemDataCreator { 31 31 32 32 private readonly IPreprocessingContext context; 33 33 34 public Pr eprocessingCloner(IPreprocessingContext context) {34 public ProblemDataCreator(IPreprocessingContext context) { 35 35 this.context = context; 36 36 } 37 37 38 public IItem GenerateAlteredClone(IItem obj) { 39 IPreprocessingData data = context.Data; 38 public IDataAnalysisProblemData CreateProblemData() { 40 39 41 Dataset dataset = data.ExportToDataset(); 42 var variables = new CheckedItemList<StringValue>(data.VariableNames.Select(s => new StringValue(s))).AsReadOnly(); 40 IDataAnalysisProblemData problemData = CloneProblemDataWithDataset(); 43 41 42 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 52 return problemData; 53 } 54 55 private IDataAnalysisProblemData CloneProblemDataWithDataset() { 44 56 var cloner = new Cloner(); 45 57 46 cloner.RegisterClonedObject(context.DataAnalysisProblemData.Dataset, dataset); 47 cloner.RegisterClonedObject(context.DataAnalysisProblemData.TrainingPartition, data.TrainingPartition); 48 cloner.RegisterClonedObject(context.DataAnalysisProblemData.TestPartition, data.TestPartition); 49 cloner.RegisterClonedObject(context.DataAnalysisProblemData.InputVariables, variables); 50 if (context.Algorithm != null) { 51 cloner.RegisterClonedObject(context.Algorithm.Runs, new RunCollection { OptimizerName = context.Algorithm.Name }); 58 var problemData = context.Problem.ProblemData; 59 60 Dataset dataset = context.Data.ExportToDataset(); 61 62 cloner.RegisterClonedObject(problemData.Dataset, dataset); 63 64 return cloner.Clone(problemData); 65 } 66 67 private void SetTrainingAndTestPartition(IDataAnalysisProblemData problemData) { 68 var ppData = context.Data; 69 70 problemData.TrainingPartition.Start = ppData.TrainingPartition.Start; 71 problemData.TrainingPartition.End = ppData.TrainingPartition.End; 72 problemData.TestPartition.Start = ppData.TestPartition.Start; 73 problemData.TestPartition.End = ppData.TestPartition.End; 74 } 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 Readonly 88 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)); 52 104 } 53 105 54 return cloner.Clone(obj);106 targetVariableParameter.ActualValue = validValues.FirstOrDefault(v => v.Value == oldTarget); 55 107 } 56 108 }
Note: See TracChangeset
for help on using the changeset viewer.