Changeset 15856
- Timestamp:
- 03/23/18 14:10:15 (7 years ago)
- Location:
- branches/2906_Transformations
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/TransformationView.cs
r15846 r15856 78 78 79 79 if (success) { 80 Content.CheckedTransformationList.Clear();80 //Content.CheckedTransformationList.Clear(); 81 81 MessageBox.Show(this, "Transformations applied.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); 82 82 } else { -
branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs
r15847 r15856 60 60 61 61 SetTrainingAndTestPartition(problemData); 62 SetAllowedInputVariables(problemData, oldProblemData.AllowedInputVariables); 62 63 // set the input variables to the correct checked state 63 var inputVariables = oldProblemData.InputVariables.ToDictionary(x => x.Value, x => x);64 foreach (var variable in problemData.InputVariables) {65 bool isChecked = inputVariables.ContainsKey(variable.Value) && oldProblemData.InputVariables.ItemChecked(inputVariables[variable.Value]);66 problemData.InputVariables.SetItemCheckedState(variable, isChecked);67 }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 //} 68 69 69 70 return problemData; … … 84 85 private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) { 85 86 // TODO: transformations (additional inputs, target changed) 86 var targetVariable = oldProblemData.TargetVariable;87 var targetVariable = RegressionProblemData.GetTransformedTragetVariable(oldProblemData.TargetVariable, Transformations); 87 88 if (!context.Data.VariableNames.Contains(targetVariable)) 88 89 targetVariable = context.Data.VariableNames.First(); … … 116 117 } 117 118 119 void SetAllowedInputVariables(IDataAnalysisProblemData problemData, IEnumerable<string> oldInputVariables) { 120 var inputs = DataAnalysisProblemData.ExtendInputVariables(oldInputVariables, Transformations); 121 122 foreach (var input in problemData.InputVariables) { 123 problemData.InputVariables.SetItemCheckedState(input, inputs.Contains(input.Value)); 124 } 125 } 126 118 127 private IEnumerable<string> GetDoubleInputVariables(string targetVariable) { 119 128 var variableNames = new List<string>(); -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r15848 r15856 438 438 <DependentUpon>TransformedRegressionModelView.cs</DependentUpon> 439 439 </Compile> 440 <Compile Include="Solution Views\TransformedRegressionSolutionView.cs"> 441 <SubType>UserControl</SubType> 442 </Compile> 443 <Compile Include="Solution Views\TransformedRegressionSolutionView.Designer.cs"> 444 <DependentUpon>TransformedRegressionSolutionView.cs</DependentUpon> 445 </Compile> 440 446 <Compile Include="Solution Views\ClassificationSolutionView.cs"> 441 447 <SubType>UserControl</SubType> -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.Designer.cs
r15846 r15856 46 46 /// </summary> 47 47 private void InitializeComponent() { 48 this. transformButton = new System.Windows.Forms.Button();48 this.TransformButton = new System.Windows.Forms.Button(); 49 49 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 50 50 this.splitContainer.Panel1.SuspendLayout(); … … 70 70 this.toolTip.SetToolTip(this.removeButton, "Remove"); 71 71 // 72 // transformButton72 // TransformButton 73 73 // 74 this. transformButton.Location = new System.Drawing.Point(117, 3);75 this. transformButton.Name = "transformButton";76 this. transformButton.Size = new System.Drawing.Size(75, 23);77 this. transformButton.TabIndex = 1;78 this. transformButton.Text = "Transform";79 this. transformButton.UseVisualStyleBackColor = true;80 this. transformButton.Click += new System.EventHandler(this.transformButton_Click);74 this.TransformButton.Location = new System.Drawing.Point(117, 3); 75 this.TransformButton.Name = "TransformButton"; 76 this.TransformButton.Size = new System.Drawing.Size(75, 23); 77 this.TransformButton.TabIndex = 1; 78 this.TransformButton.Text = "Reverse Transformations"; 79 this.TransformButton.UseVisualStyleBackColor = true; 80 this.TransformButton.Click += new System.EventHandler(this.transformButton_Click); 81 81 // 82 82 // RegressionSolutionView … … 96 96 #endregion 97 97 98 pr ivate System.Windows.Forms.Button transformButton;98 protected System.Windows.Forms.Button TransformButton; 99 99 } 100 100 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs
r15847 r15856 31 31 public RegressionSolutionView() { 32 32 InitializeComponent(); 33 flowLayoutPanel.Controls.Add( transformButton);33 flowLayoutPanel.Controls.Add(TransformButton); 34 34 } 35 35 … … 41 41 protected override void SetEnabledStateOfControls() { 42 42 base.SetEnabledStateOfControls(); 43 transformButton.Visible = Content != null && Content.ProblemData.Transformations.Any();43 TransformButton.Visible = Content != null && Content.ProblemData.Transformations.Any(); 44 44 } 45 45 … … 59 59 #endregion 60 60 61 pr ivatevoid transformButton_Click(object sender, System.EventArgs e) {61 protected virtual void transformButton_Click(object sender, System.EventArgs e) { 62 62 var transformedModel = new TransformedRegressionModel(Content.Model, Content.ProblemData.Transformations); 63 63 var originalProblemData = (IRegressionProblemData)Content.ProblemData.InverseTransform(); -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r15848 r15856 242 242 } 243 243 244 public virtual IDataAnalysisProblemData InverseTransform() { 245 var newDataset = InverseTransform(Dataset, Transformations); 244 public virtual IDataAnalysisProblemData Transform() { 245 var newDataset = Transform(Dataset, Transformations); 246 247 var extendedInputs = ExtendInputVariables(AllowedInputVariables, Transformations); 248 var checkedInputs = new CheckedItemList<StringValue>(newDataset.VariableNames.Select(x => new StringValue(x))); 249 foreach (var input in checkedInputs) checkedInputs.SetItemCheckedState(input, extendedInputs.Contains(input.Value)); 246 250 247 251 // TODO: Cannot create concrete instance here (maybe derived Create-method?) 248 252 var cloner = new Cloner(); 249 253 cloner.RegisterClonedObject(Dataset, newDataset); 250 cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>().AsReadOnly()); 254 cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly()); 255 //cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>(transformations).AsReadOnly()); 256 257 return cloner.Clone(this); 258 } 259 260 public virtual IDataAnalysisProblemData InverseTransform() { 261 var newDataset = InverseTransform(Dataset, Transformations); 262 263 var checkedInputs = new CheckedItemList<StringValue>(newDataset.VariableNames.Select(x => new StringValue(x))); 264 foreach (var input in checkedInputs) checkedInputs.SetItemCheckedState(input, AllowedInputVariables.Contains(input.Value)); 265 266 // TODO: Cannot create concrete instance here (maybe derived Create-method?) 267 var cloner = new Cloner(); 268 cloner.RegisterClonedObject(Dataset, newDataset); 269 cloner.RegisterClonedObject(InputVariables, checkedInputs.AsReadOnly()); 270 //cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList<IDataAnalysisTransformation>().AsReadOnly()); 251 271 252 272 return cloner.Clone(this); … … 281 301 var trans = (ITransformation<double>)transformation.Transformation; 282 302 283 var transformedData = modifiableDataset.GetDoubleValues(transformation.TransformedVariable); 284 285 var originalData = trans.InverseApply(transformedData).ToList(); 286 modifiableDataset.ReplaceVariable(transformation.OriginalVariable, originalData); 303 var prevTransformations = transformations.Except(transformationsStack); 304 bool originalWasChanged = prevTransformations.Any(x => x.TransformedVariable == transformation.OriginalVariable); 305 if (originalWasChanged) { 306 var transformedData = modifiableDataset.GetDoubleValues(transformation.TransformedVariable); 307 308 var originalData = trans.InverseApply(transformedData).ToList(); 309 modifiableDataset.ReplaceVariable(transformation.OriginalVariable, originalData); 310 } 287 311 288 312 bool transformedVariablePending = transformationsStack.Any(x => x.OriginalVariable == transformation.TransformedVariable); … … 293 317 return modifiableDataset; 294 318 } 319 320 public static IEnumerable<string> ExtendInputVariables(IEnumerable<string> oldInputVariables, IEnumerable<IDataAnalysisTransformation> transformations) { 321 var inputs = new HashSet<string>(oldInputVariables); 322 323 foreach (var transformation in transformations) { 324 if (inputs.Contains(transformation.OriginalVariable)) 325 inputs.Add(transformation.TransformedVariable); 326 } 327 328 return inputs; 329 } 330 331 public static IEnumerable<string> RemoveVirtualVariables(IEnumerable<string> variables, IEnumerable<IDataAnalysisTransformation> transformations) { 332 var remainingVariables = new HashSet<string>(variables); 333 334 var transformationsStack = new Stack<IDataAnalysisTransformation>(transformations); 335 336 while (transformationsStack.Any()) { 337 var transformation = transformationsStack.Pop(); 338 339 340 bool transformedVariablePending = transformationsStack.Any(x => x.OriginalVariable == transformation.TransformedVariable); 341 if (!transformedVariablePending) 342 remainingVariables.Remove(transformation.TransformedVariable); 343 } 344 345 return remainingVariables; 346 } 295 347 } 296 348 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r15847 r15856 181 181 } 182 182 183 public override IDataAnalysisProblemData Transform() { 184 var transformedProblemData = (IRegressionProblemData)base.Transform(); 185 var targetVariable = GetTransformedTragetVariable(TargetVariable, Transformations); 186 transformedProblemData.TargetVariable = targetVariable; 187 return transformedProblemData; 188 } 189 183 190 public override IDataAnalysisProblemData InverseTransform() { 184 191 var transformedProblemData = (IRegressionProblemData)base.InverseTransform(); … … 186 193 transformedProblemData.TargetVariable = targetVariable; 187 194 return transformedProblemData; 195 } 196 197 public static string GetTransformedTragetVariable(string originalTarget, IEnumerable<IDataAnalysisTransformation> transformations) { 198 var transformedTarget = originalTarget; 199 foreach (var transformation in transformations) { 200 if (transformation.OriginalVariable == transformedTarget) 201 transformedTarget = transformation.TransformedVariable; 202 } 203 return transformedTarget; 188 204 } 189 205 -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r15847 r15856 44 44 45 45 IEnumerable<IDataAnalysisTransformation> Transformations { get; } 46 IDataAnalysisProblemData Transform(); 46 47 IDataAnalysisProblemData InverseTransform(); 47 48
Note: See TracChangeset
for help on using the changeset viewer.