public void GBMHuberLoss_UpdateResiduals() { var targets = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var predictions = new double[] { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 }; var actual = new double[targets.Length]; var sut = new GradientBoostHuberLoss(0.9); sut.UpdateResiduals(targets, predictions, actual, targets.Select(t => true).ToArray()); var expected = new double[] { -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 }; CollectionAssert.AreEqual(expected, actual); }
public void GBMHuberLoss_UpdatedLeafValue_Indexed() { var targets = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var predictions = new double[] { 2.0, 1.0, 4.0, 3.0, 4.0, 5.0, 8.0, 9.0, 1.0 }; var residals = new double[targets.Length]; var inSample = new bool[] { true, false, true, false, true, false, true, false, true }; var sut = new GradientBoostHuberLoss(0.9); sut.UpdateResiduals(targets, predictions, residals, inSample); var actual = sut.UpdatedLeafValue(0.0, targets, predictions, inSample); Assert.AreEqual(-0.11999999999999977, actual, 0.001); }
public void GBMHuberLoss_UpdateResiduals_Indexed() { var targets = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var predictions = new double[] { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 }; var actual = new double[targets.Length]; var inSample = new bool[] { true, false, true, false, true, false, true, false, true }; var sut = new GradientBoostHuberLoss(0.9); sut.UpdateResiduals(targets, predictions, actual, inSample); var expected = new double[] { -4.0, 0.0, -2.0, 0.0, 0.0, 0.0, 2.0, 0.0, 4.0 }; CollectionAssert.AreEqual(expected, actual); }