Skip to content

Commit 8e5f7b4

Browse files
authored
Updated libmf and corresponding MatrixFactorizationSimpleTrainAndPredict() baselines per build (#5121)
* Updated libmf and corresponding MatrixFactorizationSimpleTrainAndPredict() baselines per build * Updated for slight variance in CentOS 7 * Remove tolerance * Updated baselines for Ubuntu and Linux, added back tolerance * Removed CentOS 7 specific check * Removed extra braces and space * Updated name of expectedLinuxMeanSquaredError * Added explanation of varying but consistent metrics
1 parent a45cc5c commit 8e5f7b4

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

test/Microsoft.ML.Tests/TrainerEstimators/MatrixFactorizationTests.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public void MatrixFactorization_Estimator()
5454
}
5555

5656
[MatrixFactorizationFact]
57-
//Skipping test temporarily. This test will be re-enabled once the cause of failures has been determined
5857
public void MatrixFactorizationSimpleTrainAndPredict()
5958
{
6059
var mlContext = new MLContext(seed: 1);
@@ -96,10 +95,10 @@ public void MatrixFactorizationSimpleTrainAndPredict()
9695
// MF produce different matrices on different platforms, so check their content on Windows.
9796
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
9897
{
99-
Assert.Equal(0.290507137775421, leftMatrix[0], 5);
100-
Assert.Equal(0.558072924613953, leftMatrix[leftMatrix.Count - 1], 5);
101-
Assert.Equal(0.270811557769775, rightMatrix[0], 5);
102-
Assert.Equal(0.376706808805466, rightMatrix[rightMatrix.Count - 1], 5);
98+
Assert.Equal(0.309137582778931, leftMatrix[0], 5);
99+
Assert.Equal(0.468956589698792, leftMatrix[leftMatrix.Count - 1], 5);
100+
Assert.Equal(0.303486406803131, rightMatrix[0], 5);
101+
Assert.Equal(0.503888845443726, rightMatrix[rightMatrix.Count - 1], 5);
103102
}
104103
// Read the test data set as an IDataView
105104
var testData = reader.Load(new MultiFileSource(GetDataPath(TestDatasets.trivialMatrixFactorization.testFilename)));
@@ -122,28 +121,30 @@ public void MatrixFactorizationSimpleTrainAndPredict()
122121
// Compute prediction errors
123122
var metrices = mlContext.Recommendation().Evaluate(prediction, labelColumnName: labelColumnName, scoreColumnName: scoreColumnName);
124123

125-
// Determine if the selected metric is reasonable for different platforms
126-
// Windows tolerance is set at 1e-7, and Linux tolerance is set at 1e-5
127-
double windowsTolerance = Math.Pow(10, -7);
124+
// Determine if the selected mean-squared error metric is reasonable on different platforms within the variation tolerance.
125+
// Windows and Mac tolerances are set at 1e-7, and Linux tolerance is set at 1e-5.
126+
// Here, each build OS has a different MSE baseline metric. While these metrics differ between builds, each build is expected to
127+
// produce the same metric. This is because of minor build differences and varying implementations of sub-functions, such as random
128+
// variables that are first obtained with the default random numger generator in libMF C++ libraries.
129+
double windowsAndMacTolerance = Math.Pow(10, -7);
128130
double linuxTolerance = Math.Pow(10, -5);
129131
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
130132
{
131133
// Linux case
132-
var expectedUnixL2Error = 0.610332110253861; // Linux baseline
133-
Assert.InRange(metrices.MeanSquaredError, expectedUnixL2Error - linuxTolerance, expectedUnixL2Error + linuxTolerance);
134+
double expectedLinuxMeanSquaredError = 0.6127260028273948; // Linux baseline
135+
Assert.InRange(metrices.MeanSquaredError, expectedLinuxMeanSquaredError - linuxTolerance, expectedLinuxMeanSquaredError + linuxTolerance);
134136
}
135137
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
136138
{
137-
// The Mac case is just broken. Should be fixed later. Re-enable when done.
138139
// Mac case
139-
//var expectedMacL2Error = 0.61192207960271; // Mac baseline
140-
//Assert.InRange(metrices.L2, expectedMacL2Error - 5e-3, expectedMacL2Error + 5e-3); // 1e-7 is too small for Mac so we try 1e-5
140+
double expectedMacMeanSquaredError = 0.616389336408704; // Mac baseline
141+
Assert.InRange(metrices.MeanSquaredError, expectedMacMeanSquaredError - windowsAndMacTolerance, expectedMacMeanSquaredError + windowsAndMacTolerance);
141142
}
142143
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
143144
{
144145
// Windows case
145-
var expectedWindowsL2Error = 0.60226203382884; // Windows baseline
146-
Assert.InRange(metrices.MeanSquaredError, expectedWindowsL2Error - windowsTolerance, expectedWindowsL2Error + windowsTolerance);
146+
double expectedWindowsMeanSquaredError = 0.600329985097577; // Windows baseline
147+
Assert.InRange(metrices.MeanSquaredError, expectedWindowsMeanSquaredError - windowsAndMacTolerance, expectedWindowsMeanSquaredError + windowsAndMacTolerance);
147148
}
148149

149150
var modelWithValidation = pipeline.Fit(data, testData);

0 commit comments

Comments
 (0)