Github user BaiGang commented on a diff in the pull request:
https://github.com/apache/spark/pull/1104#discussion_r13910039
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/optimization/LBFGSSuite.scala ---
@@ -195,4 +195,39 @@ class LBFGSSuite extends FunSuite with
LocalSparkContext with Matchers {
assert(lossLBFGS3.length == 6)
assert((lossLBFGS3(4) - lossLBFGS3(5)) / lossLBFGS3(4) <
convergenceTol)
}
+
+ test("Optimize via class LBFGS.") {
+ val regParam = 0.2
+
+ // Prepare another non-zero weights to compare the loss in the first
iteration.
+ val initialWeightsWithIntercept = Vectors.dense(0.3, 0.12)
+ val convergenceTol = 1e-12
+ val maxNumIterations = 10
+
+ val lbfgsOptimizer = new LBFGS(gradient, squaredL2Updater)
+ .setNumCorrections(numCorrections)
+ .setConvergenceTol(convergenceTol)
+ .setMaxNumIterations(maxNumIterations)
+ .setRegParam(regParam)
+
+ val weightLBFGS = lbfgsOptimizer.optimize(dataRDD,
initialWeightsWithIntercept)
+
+ val numGDIterations = 50
+ val stepSize = 1.0
+ val (weightGD, _) = GradientDescent.runMiniBatchSGD(
+ dataRDD,
+ gradient,
+ squaredL2Updater,
+ stepSize,
+ numGDIterations,
+ regParam,
+ miniBatchFrac,
+ initialWeightsWithIntercept)
+
+ // for class LBFGS and the optimize method, we only look at the weights
+ assert(compareDouble(weightLBFGS(0), weightGD(0), 0.02) &&
+ compareDouble(weightLBFGS(1), weightGD(1), 0.02),
+ "The weight differences between LBFGS and GD should be within 2%.")
+
--- End diff --
Thanks @mengxr , I'll correct the indentation and remove the empty line.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---