Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15134


Ignore:
Timestamp:
07/06/17 10:31:09 (7 years ago)
Author:
gkronber
Message:

#2690: merged r14839,r15103:15106,r15123,r15124 from trunk to stable

Location:
stable
Files:
6 deleted
8 edited
4 copied

Legend:

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

    r15127 r15134  
    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
  • stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GradientBoostedTreesModelView.cs

    r15127 r15134  
    2020#endregion
    2121
    22 using System.Drawing;
     22using HeuristicLab.Common;
     23using HeuristicLab.Core.Views;
    2324using HeuristicLab.MainForm;
    24 using HeuristicLab.Problems.DataAnalysis;
    25 using HeuristicLab.Problems.DataAnalysis.Views;
     25using HeuristicLab.MainForm.WindowsForms;
     26using HeuristicLab.Problems.DataAnalysis;                 
    2627
    2728namespace HeuristicLab.Algorithms.DataAnalysis.Views {
    28   [View("Gradient boosted tree model")]
    29   [Content(typeof(GradientBoostedTreesSolution), false)]
    30   public partial class GradientBoostedTreesModelView : DataAnalysisSolutionEvaluationView {
    31     public override Image ViewImage {
    32       get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
    33     }
     29  [View("Gradient boosted trees model")]
     30  [Content(typeof(IGradientBoostedTreesModel), true)]
     31  public partial class GradientBoostedTreesModelView : ItemView {
    3432
    35     public new GradientBoostedTreesSolution Content {
    36       get { return (GradientBoostedTreesSolution)base.Content; }
     33    public new IGradientBoostedTreesModel Content {
     34      get { return (IGradientBoostedTreesModel)base.Content; }
    3735      set { base.Content = value; }
    3836    }
     
    5755        viewHost.Content = null;
    5856        listBox.Items.Clear();
    59         foreach (var e in Content.Model.Models) {
     57        foreach (var e in Content.Models) {
    6058          listBox.Items.Add(e);
    6159        }
     
    6765      if (model == null) viewHost.Content = null;
    6866      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         }
     67        viewHost.Content = ConvertModel(model);
     68      }
     69    }
     70
     71    private void listBox_DoubleClick(object sender, System.EventArgs e) {
     72      var selectedItem = listBox.SelectedItem;
     73      if (selectedItem == null) return;
     74      MainFormManager.MainForm.ShowContent(ConvertModel(selectedItem));
     75    }
     76
     77    private IContent ConvertModel(object model) {
     78      var treeModel = model as RegressionTreeModel;
     79      if (treeModel != null)
     80        return treeModel.CreateSymbolicRegressionModel();
     81      else {
     82        var regModel = model as IRegressionModel;
     83        return regModel;
    7684      }
    7785    }
  • stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/HeuristicLab.Algorithms.DataAnalysis.Views-3.4.csproj

    r15131 r15134  
    125125  </ItemGroup>
    126126  <ItemGroup>
     127    <Compile Include="GradientBoostedTreesModelEvaluationView.cs">
     128      <SubType>UserControl</SubType>
     129    </Compile>
     130    <Compile Include="GradientBoostedTreesModelEvaluationView.Designer.cs">
     131      <DependentUpon>GradientBoostedTreesModelEvaluationView.cs</DependentUpon>
     132    </Compile>
     133    <Compile Include="GradientBoostedTreesModelView.cs">
     134      <SubType>UserControl</SubType>
     135    </Compile>
     136    <Compile Include="GradientBoostedTreesModelView.Designer.cs">
     137      <DependentUpon>GradientBoostedTreesModelView.cs</DependentUpon>
     138    </Compile>
    127139    <Compile Include="OneFactorClassificationModelView.cs">
    128140      <SubType>UserControl</SubType>
     
    131143      <DependentUpon>OneFactorClassificationModelView.cs</DependentUpon>
    132144    </Compile>
    133     <Compile Include="RandomForestClassificationSolutionView.cs">
    134       <SubType>UserControl</SubType>
    135     </Compile>
    136     <Compile Include="RandomForestClassificationSolutionView.Designer.cs">
    137       <DependentUpon>RandomForestClassificationSolutionView.cs</DependentUpon>
    138     </Compile>
    139145    <Compile Include="RandomForestModelView.cs">
    140146      <SubType>UserControl</SubType>
     
    143149      <DependentUpon>RandomForestModelView.cs</DependentUpon>
    144150    </Compile>
    145     <Compile Include="RandomForestRegressionSolutionView.cs">
    146       <SubType>UserControl</SubType>
    147     </Compile>
    148     <Compile Include="RandomForestRegressionSolutionView.Designer.cs">
    149       <DependentUpon>RandomForestRegressionSolutionView.cs</DependentUpon>
    150     </Compile>
    151     <Compile Include="GradientBoostedTreesModelView.cs">
    152       <SubType>UserControl</SubType>
    153     </Compile>
    154     <Compile Include="GradientBoostedTreesModelView.Designer.cs">
    155       <DependentUpon>GradientBoostedTreesModelView.cs</DependentUpon>
     151    <Compile Include="RandomForestModelEvaluationView.cs">
     152      <SubType>UserControl</SubType>
     153    </Compile>
     154    <Compile Include="RandomForestModelEvaluationView.Designer.cs">
     155      <DependentUpon>RandomForestModelEvaluationView.cs</DependentUpon>
    156156    </Compile>
    157157    <Compile Include="MeanProdView.cs">
     
    222222    <Compile Include="SupportVectorMachineModelView.Designer.cs">
    223223      <DependentUpon>SupportVectorMachineModelView.cs</DependentUpon>
    224     </Compile>
    225     <Compile Include="GradientBoostedTreesSolutionView.cs">
    226       <SubType>UserControl</SubType>
    227     </Compile>
    228     <Compile Include="GradientBoostedTreesSolutionView.Designer.cs">
    229       <DependentUpon>GradientBoostedTreesSolutionView.cs</DependentUpon>
    230224    </Compile>
    231225  </ItemGroup>
  • stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.Designer.cs

    r15127 r15134  
    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
  • stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.cs

    r15127 r15134  
    1818 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1919 */
    20 #endregion
     20#endregion           
    2121
    22 using System.Drawing;
     22using HeuristicLab.Common;
     23using HeuristicLab.Core.Views;
    2324using HeuristicLab.MainForm;
    2425using HeuristicLab.Problems.DataAnalysis;
    25 using HeuristicLab.Problems.DataAnalysis.Symbolic;
    26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification;
     26using HeuristicLab.Problems.DataAnalysis.Symbolic;                       
    2727using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    28 using HeuristicLab.Problems.DataAnalysis.Views;
    2928
    3029namespace HeuristicLab.Algorithms.DataAnalysis.Views {
    3130  [View("Random forest model")]
    32   [Content(typeof(IRandomForestRegressionSolution), false)]
    33   [Content(typeof(IRandomForestClassificationSolution), false)]
    34   public partial class RandomForestModelView : DataAnalysisSolutionEvaluationView {
    35     public override Image ViewImage {
    36       get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
     31  [Content(typeof(IRandomForestModel), true)]
     32  public partial class RandomForestModelView : ItemView {
     33
     34    public new IRandomForestModel Content {
     35      get { return (IRandomForestModel)base.Content; }
     36      set { base.Content = value; }
    3737    }
    3838
     
    5656        viewHost.Content = null;
    5757        listBox.Items.Clear();
    58         var classSol = Content as IRandomForestClassificationSolution;
    59         var regSol = Content as IRandomForestRegressionSolution;
    60         var numTrees = classSol != null ? classSol.NumberOfTrees : regSol != null ? regSol.NumberOfTrees : 0;
     58        var rfModel = Content;
     59        var numTrees = rfModel.NumberOfTrees;
    6160        for (int i = 0; i < numTrees; i++) {
    6261          listBox.Items.Add(i + 1);
     
    6968      else {
    7069        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         }
     70        viewHost.Content = CreateModel(idx);
    8871      }
     72    }
     73
     74    private void listBox_DoubleClick(object sender, System.EventArgs e) {
     75      var selectedItem = listBox.SelectedItem;
     76      if (selectedItem == null) return;
     77      var idx = (int)listBox.SelectedItem;
     78      MainFormManager.MainForm.ShowContent(CreateModel(idx));
     79    }
     80
     81    private IContent CreateModel(int idx) {
     82      idx -= 1;
     83      var rfModel = Content;
     84      var rfClassModel = rfModel as IClassificationModel; // rfModel is always a IRegressionModel and a IClassificationModel
     85      var targetVariable = rfClassModel.TargetVariable;
     86      if (rfModel == null) return null;
     87      if (idx < 0 || idx >= rfModel.NumberOfTrees)
     88        return null;
     89      var syModel = new SymbolicRegressionModel(targetVariable, rfModel.ExtractTree(idx),
     90          new SymbolicDataAnalysisExpressionTreeLinearInterpreter());
     91      return syModel;
    8992    }
    9093  }
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs

    r14186 r15134  
    3131namespace HeuristicLab.Algorithms.DataAnalysis {
    3232  [StorableClass]
    33   [Item("Gradient boosted tree model", "")]
     33  [Item("Gradient boosted trees model", "")]
    3434  // this is essentially a collection of weighted regression models
    3535  public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel {
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs

    r15127 r15134  
    219219    /// <returns>A new symbolic regression solution which matches the tree model</returns>
    220220    public ISymbolicRegressionSolution CreateSymbolicRegressionSolution(IRegressionProblemData problemData) {
     221      return CreateSymbolicRegressionModel().CreateRegressionSolution(problemData);
     222    }
     223
     224    /// <summary>
     225    /// Transforms the tree model to a symbolic regression model
     226    /// </summary>
     227    /// <returns>A new symbolic regression model which matches the tree model</returns>
     228    public SymbolicRegressionModel CreateSymbolicRegressionModel() {
    221229      var rootSy = new ProgramRootSymbol();
    222230      var startSy = new StartSymbol();
     
    228236      var rootNode = rootSy.CreateTreeNode();
    229237      rootNode.AddSubtree(startNode);
    230       var model = new SymbolicRegressionModel(TargetVariable, new SymbolicExpressionTree(rootNode), new SymbolicDataAnalysisExpressionTreeLinearInterpreter());
    231       return model.CreateRegressionSolution(problemData);
     238      return new SymbolicRegressionModel(TargetVariable, new SymbolicExpressionTree(rootNode), new SymbolicDataAnalysisExpressionTreeLinearInterpreter());
    232239    }
    233240
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r15131 r15134  
    7878    }
    7979
    80     public string FormatWithMapping(ISymbolicExpressionTree symbolicExpressionTree, Dictionary<string,string> variableNameMapping)
    81     {
    82       foreach(var kvp in variableNameMapping) this.variableNameMapping.Add(kvp.Key,kvp.Value);
     80    public string FormatWithMapping(ISymbolicExpressionTree symbolicExpressionTree, Dictionary<string, string> variableNameMapping) {
     81      foreach (var kvp in variableNameMapping) this.variableNameMapping.Add(kvp.Key, kvp.Value);
    8382      var stringBuilder = new StringBuilder();
    84      
     83
    8584      stringBuilder.Append("=");
    8685      stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root));
     
    9392    }
    9493
    95     private Dictionary<string,string> CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
    96       var mapping = new Dictionary<string,string>();
     94    private Dictionary<string, string> CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
     95      var mapping = new Dictionary<string, string>();
    9796      int inputIndex = 0;
    9897      var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct().ToArray();
     
    241240      } else if (symbol is VariableCondition) {
    242241        VariableConditionTreeNode variableConditionTreeNode = node as VariableConditionTreeNode;
    243         double threshold = variableConditionTreeNode.Threshold;
    244         double slope = variableConditionTreeNode.Slope;
    245         string p = "(1 / (1 + EXP(-" + slope.ToString(CultureInfo.InvariantCulture) + " * (" + GetColumnToVariableName(variableConditionTreeNode.VariableName) + "-" + threshold.ToString(CultureInfo.InvariantCulture) + "))))";
    246         stringBuilder.Append("((");
    247         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    248         stringBuilder.Append("*");
    249         stringBuilder.Append(p);
    250         stringBuilder.Append(") + (");
    251         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    252         stringBuilder.Append("*(");
    253         stringBuilder.Append("1 - " + p + ")");
    254         stringBuilder.Append("))");
     242        if (!variableConditionTreeNode.Symbol.IgnoreSlope) {
     243          double threshold = variableConditionTreeNode.Threshold;
     244          double slope = variableConditionTreeNode.Slope;
     245          string p = "(1 / (1 + EXP(-" + slope.ToString(CultureInfo.InvariantCulture) + " * (" +
     246                     GetColumnToVariableName(variableConditionTreeNode.VariableName) + "-" +
     247                     threshold.ToString(CultureInfo.InvariantCulture) + "))))";
     248          stringBuilder.Append("((");
     249          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     250          stringBuilder.Append("*");
     251          stringBuilder.Append(p);
     252          stringBuilder.Append(") + (");
     253          stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     254          stringBuilder.Append("*(");
     255          stringBuilder.Append("1 - " + p + ")");
     256          stringBuilder.Append("))");
     257        } else {
     258          stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "(IF({0} <= {1}, {2}, {3}))",
     259            GetColumnToVariableName(variableConditionTreeNode.VariableName),
     260            variableConditionTreeNode.Threshold,
     261            FormatRecursively(node.GetSubtree(0)),
     262            FormatRecursively(node.GetSubtree(1))
     263            );
     264        }
    255265      } else if (symbol is Xor) {
    256266        stringBuilder.Append("IF(");
Note: See TracChangeset for help on using the changeset viewer.