- Timestamp:
- 04/04/18 17:18:02 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs
r15880 r15884 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common;26 25 using HeuristicLab.Problems.DataAnalysis; 27 26 … … 46 45 47 46 IDataAnalysisProblemData problemData; 48 49 47 if (oldProblemData is TimeSeriesPrognosisProblemData) { 50 48 problemData = CreateTimeSeriesPrognosisData((TimeSeriesPrognosisProblemData)oldProblemData); … … 59 57 } 60 58 61 SetTrainingAndTestPartition(problemData); 62 SetAllowedInputVariables(problemData, oldProblemData.AllowedInputVariables); 63 // set the input variables to the correct checked state 64 //var inputVariables = oldProblemData.InputVariables.ToDictionary(x => x.Value, x => x); 65 //foreach (var variable in problemData.InputVariables) { 66 // bool isChecked = inputVariables.ContainsKey(variable.Value) && oldProblemData.InputVariables.ItemChecked(inputVariables[variable.Value]); 67 // problemData.InputVariables.SetItemCheckedState(variable, isChecked); 68 //} 59 SetTrainingAndTestPartition(problemData, context.Data); 60 SetAllowedInputVariables(problemData, oldProblemData); 69 61 70 62 return problemData; … … 75 67 if (!context.Data.VariableNames.Contains(targetVariable)) 76 68 targetVariable = context.Data.VariableNames.First(); 77 var inputVariables = GetDoubleInputVariables(targetVariable); 78 var newProblemData = new TimeSeriesPrognosisProblemData(ExportedDataset, inputVariables, targetVariable, CreateDataAnalysisTransformation()) { 69 var newProblemData = new TimeSeriesPrognosisProblemData(ExportedDataset, Enumerable.Empty<string>(), targetVariable, CreateDataAnalysisTransformation()) { 79 70 TrainingHorizon = oldProblemData.TrainingHorizon, 80 71 TestHorizon = oldProblemData.TestHorizon … … 84 75 85 76 private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) { 86 // TODO: transformations (additional inputs, target changed) 87 var targetVariable = RegressionTransformationModel.GetTransformedTragetVariable(oldProblemData.TargetVariable, CreateDataAnalysisTransformation()); 77 var targetVariable = DataAnalysisTransformation.GetLastTransitiveVariable(oldProblemData.TargetVariable, CreateDataAnalysisTransformation()); 88 78 if (!context.Data.VariableNames.Contains(targetVariable)) 89 79 targetVariable = context.Data.VariableNames.First(); 90 var inputVariables = GetDoubleInputVariables(targetVariable); 91 var newProblemData = new RegressionProblemData(ExportedDataset, inputVariables, targetVariable, CreateDataAnalysisTransformation()); 80 var newProblemData = new RegressionProblemData(ExportedDataset, Enumerable.Empty<string>(), targetVariable, CreateDataAnalysisTransformation()); 92 81 return newProblemData; 93 82 } … … 97 86 if (!context.Data.VariableNames.Contains(targetVariable)) 98 87 targetVariable = context.Data.VariableNames.First(); 99 var inputVariables = GetDoubleInputVariables(targetVariable); 100 var newProblemData = new ClassificationProblemData(ExportedDataset, inputVariables, targetVariable, CreateDataAnalysisTransformation()) { 88 var newProblemData = new ClassificationProblemData(ExportedDataset, Enumerable.Empty<string>(), targetVariable, CreateDataAnalysisTransformation()) { 101 89 PositiveClass = oldProblemData.PositiveClass 102 90 }; … … 105 93 106 94 private IDataAnalysisProblemData CreateClusteringData(ClusteringProblemData oldProblemData) { 107 return new ClusteringProblemData(ExportedDataset, GetDoubleInputVariables(String.Empty), CreateDataAnalysisTransformation());95 return new ClusteringProblemData(ExportedDataset, Enumerable.Empty<string>(), CreateDataAnalysisTransformation()); 108 96 } 109 97 110 private void SetTrainingAndTestPartition(IDataAnalysisProblemData problemData) { 111 var ppData = context.Data; 112 98 private static void SetTrainingAndTestPartition(IDataAnalysisProblemData problemData, IPreprocessingData ppData) { 113 99 problemData.TrainingPartition.Start = ppData.TrainingPartition.Start; 114 100 problemData.TrainingPartition.End = ppData.TrainingPartition.End; … … 117 103 } 118 104 119 void SetAllowedInputVariables(IDataAnalysisProblemData problemData, IEnumerable<string> oldInputVariables) {120 var inputs = DataAnalysisTransformationModel.ExtendInputVariables(oldInputVariables, problemData.Transformations);121 105 private static void SetAllowedInputVariables(IDataAnalysisProblemData problemData, IDataAnalysisProblemData oldProblemData) { 106 // original inputs + extended(transitive) inputs 107 var inputs = DataAnalysisTransformation.ExtendVariables(oldProblemData.AllowedInputVariables, problemData.Transformations).ToList(); 122 108 foreach (var input in problemData.InputVariables) { 123 109 problemData.InputVariables.SetItemCheckedState(input, inputs.Contains(input.Value)); 124 110 } 125 }126 111 127 private IEnumerable<string> GetDoubleInputVariables(string targetVariable) { 128 var variableNames = new List<string>(); 129 for (int i = 0; i < context.Data.Columns; ++i) { 130 var variableName = context.Data.GetVariableName(i); 131 if (context.Data.VariableHasType<double>(i) 132 && variableName != targetVariable 133 && IsNotConstantInputVariable(context.Data.GetValues<double>(i))) { 134 135 variableNames.Add(variableName); 136 } 112 // new variables that were not created via transformations 113 var originalAndVirtualVariables = DataAnalysisTransformation.ExtendVariables(oldProblemData.Dataset.VariableNames, problemData.Transformations); 114 var newVariables = problemData.Dataset.VariableNames.Except(originalAndVirtualVariables).ToList(); 115 foreach (var input in problemData.InputVariables) { 116 if (newVariables.Contains(input.Value)) 117 problemData.InputVariables.SetItemCheckedState(input, true); 137 118 } 138 return variableNames;139 }140 141 private bool IsNotConstantInputVariable(IList<double> list) {142 return context.Data.TrainingPartition.End - context.Data.TrainingPartition.Start > 1 || list.Range() > 0;143 119 } 144 120
Note: See TracChangeset
for help on using the changeset viewer.