Repository: reef Updated Branches: refs/heads/master b0a47f9b7 -> 6eb3a8929
[REEF-1663] Fix TestKMeansOnDirectRunViaFileSystem failure in AppVeyor This change replaces exact comparison of floating-point numbers with comparison with some absolute error. JIRA: [REEF-1663](https://issues.apache.org/jira/browse/REEF-1663) Pull request: This closes #1187 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/6eb3a892 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/6eb3a892 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/6eb3a892 Branch: refs/heads/master Commit: 6eb3a89292016bc8325e592de60bf51ce0947d60 Parents: b0a47f9 Author: Mariia Mykhailova <[email protected]> Authored: Mon Nov 21 16:25:37 2016 -0800 Committer: Julia Wang <[email protected]> Committed: Tue Nov 22 12:46:33 2016 -0800 ---------------------------------------------------------------------- .../MachineLearning/KMeans/KMeansMasterTask.cs | 13 +++++-------- .../Functional/ML/KMeans/TestKMeans.cs | 15 ++++----------- 2 files changed, 9 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/6eb3a892/lang/cs/Org.Apache.REEF.Examples/MachineLearning/KMeans/KMeansMasterTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples/MachineLearning/KMeans/KMeansMasterTask.cs b/lang/cs/Org.Apache.REEF.Examples/MachineLearning/KMeans/KMeansMasterTask.cs index e85ecd6..d0f92db 100644 --- a/lang/cs/Org.Apache.REEF.Examples/MachineLearning/KMeans/KMeansMasterTask.cs +++ b/lang/cs/Org.Apache.REEF.Examples/MachineLearning/KMeans/KMeansMasterTask.cs @@ -32,6 +32,7 @@ namespace Org.Apache.REEF.Examples.MachineLearning.KMeans public class KMeansMasterTask : ITask { private static readonly Logger Logger = Logger.GetLogger(typeof(KMeansMasterTask)); + private const double Eps = 1E-6; private int _iteration; @@ -73,7 +74,6 @@ namespace Org.Apache.REEF.Examples.MachineLearning.KMeans _centroids = new Centroids(DataPartitionCache.ReadDataFile(centroidFile)); float loss = float.MaxValue; - float newLoss; while (true) { @@ -88,23 +88,20 @@ namespace Org.Apache.REEF.Examples.MachineLearning.KMeans ProcessedResults results = _meansReducerReceiver.Reduce(); _centroids = new Centroids(results.Means.Select(m => m.Mean).ToList()); Logger.Log(Level.Info, "Broadcasting new centroids to all slave nodes: " + _centroids); - newLoss = results.Loss; + float newLoss = results.Loss; Logger.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "The new loss value {0} at iteration {1} ", newLoss, _iteration)); - if (newLoss > loss) + if (newLoss > loss + Eps) { _controlBroadcastSender.Send(ControlMessage.STOP); throw new InvalidOperationException( string.Format(CultureInfo.InvariantCulture, "The new loss {0} is larger than previous loss {1}, while loss function must be monotonically decreasing across iterations", newLoss, loss)); } - else if (newLoss.Equals(loss)) + if (newLoss > loss - Eps) { Logger.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "KMeans clustering has converged with a loss value of {0} at iteration {1} ", newLoss, _iteration)); break; } - else - { - loss = newLoss; - } + loss = newLoss; } _controlBroadcastSender.Send(ControlMessage.RECEIVE); _dataBroadcastSender.Send(_centroids); http://git-wip-us.apache.org/repos/asf/reef/blob/6eb3a892/lang/cs/Org.Apache.REEF.Tests/Functional/ML/KMeans/TestKMeans.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/ML/KMeans/TestKMeans.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/ML/KMeans/TestKMeans.cs index 0afda40..4db2b3b 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Functional/ML/KMeans/TestKMeans.cs +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/ML/KMeans/TestKMeans.cs @@ -19,13 +19,8 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; -using Org.Apache.REEF.Common.Io; -using Org.Apache.REEF.Common.Tasks; -using Org.Apache.REEF.Driver.Bridge; using Org.Apache.REEF.Examples.MachineLearning.KMeans; using Org.Apache.REEF.Network.Group.Config; -using Org.Apache.REEF.Network.Naming; -using Org.Apache.REEF.Network.NetworkService; using Org.Apache.REEF.Tang.Implementations.Configuration; using Org.Apache.REEF.Tang.Implementations.Tang; using Org.Apache.REEF.Tang.Interface; @@ -41,6 +36,7 @@ namespace Org.Apache.REEF.Tests.Functional.ML.KMeans private const int K = 3; private const int Partitions = 2; private const string DataFileNamePrefix = "KMeansInput-"; + private const double Eps = 1E-6; public TestKMeans() { @@ -82,20 +78,17 @@ namespace Org.Apache.REEF.Tests.Functional.ML.KMeans DataVector.WriteToCentroidFile(newCentroids, executionDirectory); centroids = newCentroids; float newLoss = LegacyKMeansTask.ComputeLossFunction(centroids, labeledData); - if (newLoss > loss) + if (newLoss > loss + Eps) { throw new InvalidOperationException( string.Format(CultureInfo.InvariantCulture, "The new loss {0} is larger than previous loss {1}, while loss function must be monotonically decreasing across iterations", newLoss, loss)); } - else if (newLoss.Equals(loss)) + if (newLoss > loss - Eps) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "KMeans clustering has converged with a loss value of {0} at iteration {1} ", newLoss, iteration)); break; } - else - { - loss = newLoss; - } + loss = newLoss; iteration++; }
