Free cookie consent management tool by TermsFeed Policy Generator

# Changeset 12607

Ignore:
Timestamp:
07/06/15 15:20:28 (8 years ago)
Message:

#2261: also use line search function for the initial estimation f0, changed logistic regression loss function to match description in GBM paper, comments and code improvements

Location:
Files:
6 edited

### Legend:

Unmodified
Removed

 r12597 activeIdx = Enumerable.Range(0, nRows).ToArray(); // prepare arrays (allocate only once) double f0 = y.Average(); // default prediction (constant) var zeros = Enumerable.Repeat(0.0, nRows); var ones = Enumerable.Repeat(1.0, nRows); double f0 = lossFunction.GetLineSearchFunc(y, zeros, ones)(activeIdx, 0, nRows - 1); // initial constant value (mean for squared errors) pred = Enumerable.Repeat(f0, nRows).ToArray(); predTest = Enumerable.Repeat(f0, problemData.TestIndices.Count()).ToArray();

 r12597 while (targetEnum.MoveNext() & predEnum.MoveNext() & weightEnum.MoveNext()) { double res = targetEnum.Current - predEnum.Current; s += weightEnum.Current * Math.Abs(res); s += weightEnum.Current * Math.Abs(res);  // w * |res| } if (targetEnum.MoveNext() | predEnum.MoveNext() | weightEnum.MoveNext()) while (targetEnum.MoveNext() & predEnum.MoveNext() & weightEnum.MoveNext()) { // weight * sign(res) // dL(y, f(x)) / df(x) = weight * sign(res) var res = targetEnum.Current - predEnum.Current; if (res > 0) yield return weightEnum.Current; var predArr = pred.ToArray(); var weightArr = weight.ToArray(); // weights are not supported yet // when weights are supported we need to calculate a weighted median // the optimal constant value that should be added to the predictions is the median of the residuals // weights are not supported yet (need to calculate a weighted median) Debug.Assert(weightArr.All(w => w.IsAlmost(1.0))); int nRows = endIdx - startIdx + 1; var res = new double[nRows]; for (int offset = 0; offset < nRows; offset++) { var i = startIdx + offset; for (int i = startIdx; i <= endIdx; i++) { var row = idx[i]; res[offset] = targetArr[row] - predArr[row]; res[i - startIdx] = targetArr[row] - predArr[row]; } return res.Median();