Skip to content

Bugfix/hardwired sigmoid #3850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
renamed sigmoid to sigmoidScale
  • Loading branch information
michaelgsharp committed Jun 11, 2019
commit cb43df3473ad29e93779c99b76feaf86a9c92721
16 changes: 8 additions & 8 deletions test/Microsoft.ML.Tests/TrainerEstimators/TreeEstimators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ public void LightGbmMulticlassEstimatorCompareOva()
[LightGBMFact]
public void LightGbmMulticlassEstimatorCompareOvaUsingSigmoids()
{
var sigmoid = .790;
var sigmoidScale = .790;
// Train ML.NET LightGBM and native LightGBM and apply the trained models to the training set.
LightGbmHelper(useSoftmax: false, out string modelString, out List<GbmExample> mlnetPredictions, out double[] nativeResult1, out double[] nativeResult0, sigmoid: sigmoid);
LightGbmHelper(useSoftmax: false, out string modelString, out List<GbmExample> mlnetPredictions, out double[] nativeResult1, out double[] nativeResult0, sigmoid: sigmoidScale);

// The i-th predictor returned by LightGBM produces the raw score, denoted by z_i, of the i-th class.
// Assume that we have n classes in total. The i-th class probability can be computed via
Expand All @@ -482,11 +482,11 @@ public void LightGbmMulticlassEstimatorCompareOvaUsingSigmoids()
Assert.Equal(nativeResult0[j + i * _classNumber], mlnetPredictions[i].Score[j], 6);
if (float.IsNaN((float)nativeResult1[j + i * _classNumber]))
continue;
sum += MathUtils.SigmoidSlow((float)sigmoid * (float)nativeResult1[j + i * _classNumber]);
sum += MathUtils.SigmoidSlow((float)sigmoidScale * (float)nativeResult1[j + i * _classNumber]);
}
for (int j = 0; j < _classNumber; ++j)
{
double prob = MathUtils.SigmoidSlow((float)sigmoid * (float)nativeResult1[j + i * _classNumber]);
double prob = MathUtils.SigmoidSlow((float)sigmoidScale * (float)nativeResult1[j + i * _classNumber]);
Assert.Equal(prob / sum, mlnetPredictions[i].Score[j], 6);
}
}
Expand All @@ -501,12 +501,12 @@ public void LightGbmMulticlassEstimatorCompareOvaUsingSigmoids()
public void LightGbmMulticlassEstimatorCompareOvaUsingDifferentSigmoids()
{
// Run native implemenation twice, see that results are different with different sigmoid values.
var firstSigmoid = .790;
var secondSigmoid = .2;
var firstSigmoidScale = .790;
var secondSigmoidScale = .2;

// Train native LightGBM with both sigmoid values and apply the trained models to the training set.
LightGbmHelper(useSoftmax: false, out string firstModelString, out List<GbmExample> firstMlnetPredictions, out double[] firstNativeResult1, out double[] firstNativeResult0, sigmoid: firstSigmoid);
LightGbmHelper(useSoftmax: false, out string secondModelString, out List<GbmExample> secondMlnetPredictions, out double[] secondNativeResult1, out double[] secondNativeResult0, sigmoid: secondSigmoid);
LightGbmHelper(useSoftmax: false, out string firstModelString, out List<GbmExample> firstMlnetPredictions, out double[] firstNativeResult1, out double[] firstNativeResult0, sigmoid: firstSigmoidScale);
LightGbmHelper(useSoftmax: false, out string secondModelString, out List<GbmExample> secondMlnetPredictions, out double[] secondNativeResult1, out double[] secondNativeResult0, sigmoid: secondSigmoidScale);

// Compare native LightGBM's results when 2 different sigmoid values are used.
for (int i = 0; i < _rowNumber; ++i)
Expand Down