Changeset 12696 for branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs
- Timestamp:
- 07/09/15 16:11:52 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs
r12661 r12696 55 55 internal double[] pred; 56 56 internal double[] predTest; 57 internal double[] w;58 57 internal double[] y; 59 58 internal int[] activeIdx; … … 77 76 78 77 y = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).ToArray(); 79 // weights are all 1 for now (HL doesn't support weights yet)80 w = Enumerable.Repeat(1.0, nRows).ToArray();81 78 82 79 treeBuilder = new RegressionTreeBuilder(problemData, random); … … 85 82 86 83 var zeros = Enumerable.Repeat(0.0, nRows); 87 var ones = Enumerable.Repeat(1.0, nRows); 88 double f0 = lossFunction.GetLineSearchFunc(y, zeros, ones)(activeIdx, 0, nRows - 1); // initial constant value (mean for squared errors) 84 double f0 = lossFunction.GetLineSearchFunc(y, zeros)(activeIdx, 0, nRows - 1); // initial constant value (mean for squared errors) 89 85 pred = Enumerable.Repeat(f0, nRows).ToArray(); 90 86 predTest = Enumerable.Repeat(f0, problemData.TestIndices.Count()).ToArray(); … … 107 103 public double GetTrainLoss() { 108 104 int nRows = y.Length; 109 return lossFunction.GetLoss(y, pred , w) / nRows;105 return lossFunction.GetLoss(y, pred) / nRows; 110 106 } 111 107 public double GetTestLoss() { 112 108 var yTest = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TestIndices); 113 var wTest = problemData.TestIndices.Select(_ => 1.0); // ones114 109 var nRows = problemData.TestIndices.Count(); 115 return lossFunction.GetLoss(yTest, predTest , wTest) / nRows;110 return lossFunction.GetLoss(yTest, predTest) / nRows; 116 111 } 117 112 } … … 160 155 var yPred = gbmState.pred; 161 156 var yPredTest = gbmState.predTest; 162 var w = gbmState.w;163 157 var treeBuilder = gbmState.treeBuilder; 164 158 var y = gbmState.y; … … 168 162 // copy output of gradient function to pre-allocated rim array (pseudo-residuals) 169 163 int rimIdx = 0; 170 foreach (var g in lossFunction.GetLossGradient(y, yPred , w)) {164 foreach (var g in lossFunction.GetLossGradient(y, yPred)) { 171 165 pseudoRes[rimIdx++] = g; 172 166 } 173 167 174 var tree = treeBuilder.CreateRegressionTreeForGradientBoosting(pseudoRes, maxSize, activeIdx, lossFunction.GetLineSearchFunc(y, yPred , w), r, m);168 var tree = treeBuilder.CreateRegressionTreeForGradientBoosting(pseudoRes, maxSize, activeIdx, lossFunction.GetLineSearchFunc(y, yPred), r, m); 175 169 176 170 int i = 0;
Note: See TracChangeset
for help on using the changeset viewer.