- Timestamp:
- 10/21/16 17:59:36 (8 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r14185 r14345 269 269 } else { 270 270 // otherwise we produce a regression solution 271 Results.Add(new Result("Solution", new RegressionSolution(model, problemData)));271 Results.Add(new Result("Solution", new GradientBoostedTreesSolution(model, problemData))); 272 272 } 273 273 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesSolution.cs
r14185 r14345 20 20 #endregion 21 21 22 using System.Collections.Generic;23 using System.Linq;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs
r14185 r14345 28 28 using HeuristicLab.Common; 29 29 using HeuristicLab.Core; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 using HeuristicLab.Problems.DataAnalysis; 33 using HeuristicLab.Problems.DataAnalysis.Symbolic; 34 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 32 35 33 36 namespace HeuristicLab.Algorithms.DataAnalysis { … … 210 213 } 211 214 215 /// <summary> 216 /// Transforms the tree model to a symbolic regression solution 217 /// </summary> 218 /// <param name="problemData"></param> 219 /// <returns>A new symbolic regression solution which matches the tree model</returns> 220 public ISymbolicRegressionSolution CreateSymbolicRegressionSolution(IRegressionProblemData problemData) { 221 var rootSy = new ProgramRootSymbol(); 222 var startSy = new StartSymbol(); 223 var varCondSy = new VariableCondition() { IgnoreSlope = true }; 224 var constSy = new Constant(); 225 226 var startNode = startSy.CreateTreeNode(); 227 startNode.AddSubtree(CreateSymbolicRegressionTreeRecursive(tree, 0, varCondSy, constSy)); 228 var rootNode = rootSy.CreateTreeNode(); 229 rootNode.AddSubtree(startNode); 230 var model = new SymbolicRegressionModel(TargetVariable, new SymbolicExpressionTree(rootNode), new SymbolicDataAnalysisExpressionTreeLinearInterpreter()); 231 return model.CreateRegressionSolution(problemData); 232 } 233 234 private ISymbolicExpressionTreeNode CreateSymbolicRegressionTreeRecursive(TreeNode[] treeNodes, int nodeIdx, VariableCondition varCondSy, Constant constSy) { 235 var curNode = treeNodes[nodeIdx]; 236 if (curNode.VarName == TreeNode.NO_VARIABLE) { 237 var node = (ConstantTreeNode)constSy.CreateTreeNode(); 238 node.Value = curNode.Val; 239 return node; 240 } else { 241 var node = (VariableConditionTreeNode)varCondSy.CreateTreeNode(); 242 node.VariableName = curNode.VarName; 243 node.Threshold = curNode.Val; 244 245 var left = CreateSymbolicRegressionTreeRecursive(treeNodes, curNode.LeftIdx, varCondSy, constSy); 246 var right = CreateSymbolicRegressionTreeRecursive(treeNodes, curNode.RightIdx, varCondSy, constSy); 247 node.AddSubtree(left); 248 node.AddSubtree(right); 249 return node; 250 } 251 } 252 253 212 254 private string TreeToString(int idx, string part) { 213 255 var n = tree[idx];
Note: See TracChangeset
for help on using the changeset viewer.