- Timestamp:
- 10/19/15 13:54:15 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs
r12868 r13030 23 23 using System; 24 24 using System.Collections.Generic; 25 using System.Collections.ObjectModel; 25 26 using System.Globalization; 26 27 using System.Linq; … … 52 53 public int RightIdx { get; private set; } 53 54 54 internal IList<double> Data { get; set; } // only necessary to improve efficiency of evaluation55 56 55 // necessary because the default implementation of GetHashCode for structs in .NET would only return the hashcode of val here 57 56 public override int GetHashCode() { … … 82 81 [Storable] 83 82 // to prevent storing the references to data caches in nodes 84 // seemingly it is bad (performance-wise) to persist tuples (tuples are used as keys in a dictionary) TODO83 // TODO seemingly it is bad (performance-wise) to persist tuples (tuples are used as keys in a dictionary) 85 84 private Tuple<string, double, int, int>[] SerializedTree { 86 85 get { return tree.Select(t => Tuple.Create(t.VarName, t.Val, t.LeftIdx, t.RightIdx)).ToArray(); } … … 104 103 } 105 104 106 private static double GetPredictionForRow(TreeNode[] t, int nodeIdx, int row) {105 private static double GetPredictionForRow(TreeNode[] t, ReadOnlyCollection<double>[] columnCache, int nodeIdx, int row) { 107 106 while (nodeIdx != -1) { 108 107 var node = t[nodeIdx]; … … 110 109 return node.Val; 111 110 112 if ( node.Data[row] <= node.Val)111 if (columnCache[nodeIdx][row] <= node.Val) 113 112 nodeIdx = node.LeftIdx; 114 113 else … … 124 123 public IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) { 125 124 // lookup columns for variableNames in one pass over the tree to speed up evaluation later on 125 ReadOnlyCollection<double>[] columnCache = new ReadOnlyCollection<double>[tree.Length]; 126 126 127 for (int i = 0; i < tree.Length; i++) { 127 128 if (tree[i].VarName != TreeNode.NO_VARIABLE) { 128 tree[i].Data= ds.GetReadOnlyDoubleValues(tree[i].VarName);129 columnCache[i] = ds.GetReadOnlyDoubleValues(tree[i].VarName); 129 130 } 130 131 } 131 return rows.Select(r => GetPredictionForRow(tree, 0, r));132 return rows.Select(r => GetPredictionForRow(tree, columnCache, 0, r)); 132 133 } 133 134
Note: See TracChangeset
for help on using the changeset viewer.