Changeset 15103


Ignore:
Timestamp:
07/01/17 08:23:22 (4 months ago)
Author:
gkronber
Message:

#2690 added event-handler for double click events to open the clicked model in a new view

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GradientBoostedTreesModelView.Designer.cs

    r14345 r15103  
    7474      this.listBox.TabIndex = 1;
    7575      this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
     76      this.listBox.DoubleClick += new System.EventHandler(this.listBox_DoubleClick);
    7677      //
    7778      // GradientBoostedTreesModelView
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GradientBoostedTreesModelView.cs

    r14345 r15103  
    2121
    2222using System.Drawing;
     23using HeuristicLab.Common;
     24using HeuristicLab.Core;
    2325using HeuristicLab.MainForm;
    2426using HeuristicLab.Problems.DataAnalysis;
     
    6769      if (model == null) viewHost.Content = null;
    6870      else {
    69         var treeModel = model as RegressionTreeModel;
    70         if (treeModel != null)
    71           viewHost.Content = treeModel.CreateSymbolicRegressionSolution(Content.ProblemData);
    72         else {
    73           var regModel = model as IRegressionModel;
    74           viewHost.Content = regModel;
    75         }
     71        viewHost.Content = ConvertModel(model);
     72      }
     73    }
     74
     75    private void listBox_DoubleClick(object sender, System.EventArgs e) {
     76      var selectedItem = listBox.SelectedItem;
     77      if (selectedItem == null) return;
     78      MainFormManager.MainForm.ShowContent(ConvertModel(selectedItem));
     79    }
     80
     81    private IContent ConvertModel(object model) {
     82      var treeModel = model as RegressionTreeModel;
     83      if (treeModel != null)
     84        return treeModel.CreateSymbolicRegressionSolution(Content.ProblemData);
     85      else {
     86        var regModel = model as IRegressionModel;
     87        return regModel;
    7688      }
    7789    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.Designer.cs

    r14345 r15103  
    7979      this.listBox.TabIndex = 1;
    8080      this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
     81      this.listBox.DoubleClick += new System.EventHandler(this.listBox_DoubleClick);
    8182      //
    8283      // RandomForestModelView
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.cs

    r14345 r15103  
    1919 */
    2020#endregion
    21 
     21using System;
    2222using System.Drawing;
     23using HeuristicLab.Common;
    2324using HeuristicLab.MainForm;
    2425using HeuristicLab.Problems.DataAnalysis;
     
    6970      else {
    7071        var idx = (int)listBox.SelectedItem;
    71         idx -= 1;
    72         var rfModel = Content.Model as RandomForestModel;
    73         var regProblemData = Content.ProblemData as IRegressionProblemData;
    74         var classProblemData = Content.ProblemData as IClassificationProblemData;
    75         if (rfModel != null) {
    76           if (idx < 0 || idx >= rfModel.NumberOfTrees) return;
    77           if (regProblemData != null) {
    78             var syModel = new SymbolicRegressionModel(regProblemData.TargetVariable, rfModel.ExtractTree(idx),
    79               new SymbolicDataAnalysisExpressionTreeLinearInterpreter());
    80             viewHost.Content = syModel.CreateRegressionSolution(regProblemData);
    81           } else if (classProblemData != null) {
    82             var syModel = new SymbolicDiscriminantFunctionClassificationModel(classProblemData.TargetVariable, rfModel.ExtractTree(idx),
    83               new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), new NormalDistributionCutPointsThresholdCalculator());
    84             syModel.RecalculateModelParameters(classProblemData, classProblemData.TrainingIndices);
    85             viewHost.Content = syModel.CreateClassificationSolution(classProblemData);
    86           }
    87         }
     72        viewHost.Content = CreateModel(idx);
    8873      }
     74    }
     75
     76    private void listBox_DoubleClick(object sender, System.EventArgs e) {
     77      var selectedItem = listBox.SelectedItem;
     78      if (selectedItem == null) return;
     79      var idx = (int)listBox.SelectedItem;
     80      MainFormManager.MainForm.ShowContent(CreateModel(idx));
     81    }
     82
     83    private IContent CreateModel(int idx) {
     84      idx -= 1;
     85      var rfModel = Content.Model as RandomForestModel;
     86      if (rfModel == null) return null;
     87      var regProblemData = Content.ProblemData as IRegressionProblemData;
     88      var classProblemData = Content.ProblemData as IClassificationProblemData;
     89      if (idx < 0 || idx >= rfModel.NumberOfTrees)
     90        return null;
     91      if (regProblemData != null) {
     92        var syModel = new SymbolicRegressionModel(regProblemData.TargetVariable, rfModel.ExtractTree(idx),
     93          new SymbolicDataAnalysisExpressionTreeLinearInterpreter());
     94        return syModel.CreateRegressionSolution(regProblemData);
     95      } else if (classProblemData != null) {
     96        var syModel = new SymbolicDiscriminantFunctionClassificationModel(classProblemData.TargetVariable, rfModel.ExtractTree(idx),
     97          new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), new NormalDistributionCutPointsThresholdCalculator());
     98        syModel.RecalculateModelParameters(classProblemData, classProblemData.TrainingIndices);
     99        return syModel.CreateClassificationSolution(classProblemData);
     100      } else throw new InvalidProgramException();
    89101    }
    90102  }
Note: See TracChangeset for help on using the changeset viewer.