Changeset 15134
- Timestamp:
- 07/06/17 10:31:09 (7 years ago)
- 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 74 74 this.listBox.TabIndex = 1; 75 75 this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged); 76 this.listBox.DoubleClick += new System.EventHandler(this.listBox_DoubleClick); 76 77 // 77 78 // GradientBoostedTreesModelView -
stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GradientBoostedTreesModelView.cs
r15127 r15134 20 20 #endregion 21 21 22 using System.Drawing; 22 using HeuristicLab.Common; 23 using HeuristicLab.Core.Views; 23 24 using HeuristicLab.MainForm; 24 using HeuristicLab. Problems.DataAnalysis;25 using HeuristicLab.Problems.DataAnalysis .Views;25 using HeuristicLab.MainForm.WindowsForms; 26 using HeuristicLab.Problems.DataAnalysis; 26 27 27 28 namespace 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 { 34 32 35 public new GradientBoostedTreesSolutionContent {36 get { return ( GradientBoostedTreesSolution)base.Content; }33 public new IGradientBoostedTreesModel Content { 34 get { return (IGradientBoostedTreesModel)base.Content; } 37 35 set { base.Content = value; } 38 36 } … … 57 55 viewHost.Content = null; 58 56 listBox.Items.Clear(); 59 foreach (var e in Content.Model .Models) {57 foreach (var e in Content.Models) { 60 58 listBox.Items.Add(e); 61 59 } … … 67 65 if (model == null) viewHost.Content = null; 68 66 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; 76 84 } 77 85 } -
stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/HeuristicLab.Algorithms.DataAnalysis.Views-3.4.csproj
r15131 r15134 125 125 </ItemGroup> 126 126 <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> 127 139 <Compile Include="OneFactorClassificationModelView.cs"> 128 140 <SubType>UserControl</SubType> … … 131 143 <DependentUpon>OneFactorClassificationModelView.cs</DependentUpon> 132 144 </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>139 145 <Compile Include="RandomForestModelView.cs"> 140 146 <SubType>UserControl</SubType> … … 143 149 <DependentUpon>RandomForestModelView.cs</DependentUpon> 144 150 </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> 156 156 </Compile> 157 157 <Compile Include="MeanProdView.cs"> … … 222 222 <Compile Include="SupportVectorMachineModelView.Designer.cs"> 223 223 <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>230 224 </Compile> 231 225 </ItemGroup> -
stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.Designer.cs
r15127 r15134 79 79 this.listBox.TabIndex = 1; 80 80 this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged); 81 this.listBox.DoubleClick += new System.EventHandler(this.listBox_DoubleClick); 81 82 // 82 83 // RandomForestModelView -
stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.cs
r15127 r15134 18 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 19 */ 20 #endregion 20 #endregion 21 21 22 using System.Drawing; 22 using HeuristicLab.Common; 23 using HeuristicLab.Core.Views; 23 24 using HeuristicLab.MainForm; 24 25 using HeuristicLab.Problems.DataAnalysis; 25 using HeuristicLab.Problems.DataAnalysis.Symbolic; 26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification; 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 27 27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 28 using HeuristicLab.Problems.DataAnalysis.Views;29 28 30 29 namespace HeuristicLab.Algorithms.DataAnalysis.Views { 31 30 [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; } 37 37 } 38 38 … … 56 56 viewHost.Content = null; 57 57 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; 61 60 for (int i = 0; i < numTrees; i++) { 62 61 listBox.Items.Add(i + 1); … … 69 68 else { 70 69 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); 88 71 } 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; 89 92 } 90 93 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
r14186 r15134 31 31 namespace HeuristicLab.Algorithms.DataAnalysis { 32 32 [StorableClass] 33 [Item("Gradient boosted tree model", "")]33 [Item("Gradient boosted trees model", "")] 34 34 // this is essentially a collection of weighted regression models 35 35 public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel { -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs
r15127 r15134 219 219 /// <returns>A new symbolic regression solution which matches the tree model</returns> 220 220 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() { 221 229 var rootSy = new ProgramRootSymbol(); 222 230 var startSy = new StartSymbol(); … … 228 236 var rootNode = rootSy.CreateTreeNode(); 229 237 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()); 232 239 } 233 240 -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r15131 r15134 78 78 } 79 79 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); 83 82 var stringBuilder = new StringBuilder(); 84 83 85 84 stringBuilder.Append("="); 86 85 stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root)); … … 93 92 } 94 93 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>(); 97 96 int inputIndex = 0; 98 97 var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct().ToArray(); … … 241 240 } else if (symbol is VariableCondition) { 242 241 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 } 255 265 } else if (symbol is Xor) { 256 266 stringBuilder.Append("IF(");
Note: See TracChangeset
for help on using the changeset viewer.