Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.