Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/353#discussion_r11528239
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/optimization/LBFGSSuite.scala ---
    @@ -0,0 +1,203 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.mllib.optimization
    +
    +import org.scalatest.BeforeAndAfterAll
    +import org.scalatest.FunSuite
    +import org.scalatest.matchers.ShouldMatchers
    +
    +import org.apache.spark.mllib.regression.LabeledPoint
    +import org.apache.spark.mllib.linalg.Vectors
    +import org.apache.spark.mllib.util.LocalSparkContext
    +
    +class LBFGSSuite extends FunSuite with BeforeAndAfterAll with 
LocalSparkContext with ShouldMatchers {
    +
    +  val nPoints = 10000
    +  val A = 2.0
    +  val B = -1.5
    +
    +  val initialB = -1.0
    +  val initialWeights = Array(initialB)
    +
    +  val gradient = new LogisticGradient()
    +  val numCorrections = 10
    +  val miniBatchFrac = 1.0
    +
    +  val simpleUpdater = new SimpleUpdater()
    +  val squaredL2Updater = new SquaredL2Updater()
    +
    +  // Add an extra variable consisting of all 1.0's for the intercept.
    +  val testData = GradientDescentSuite.generateGDInput(A, B, nPoints, 42)
    +  val data = testData.map { case LabeledPoint(label, features) =>
    +    label -> Vectors.dense(1.0, features.toArray: _*)
    +  }
    +
    +  lazy val dataRDD = sc.parallelize(data, 2).cache()
    +
    +  def compareDouble(x: Double, y: Double, tol: Double = 1E-3): Boolean = {
    +    math.abs(x - y) / (math.abs(y) + 1e-15) < tol
    +  }
    +
    +  test("LBFGS loss should be decreasing and match the result of Gradient 
Descent.") {
    +    val regParam = 0
    +
    +    val initialWeightsWithIntercept = Vectors.dense(1.0, initialWeights: 
_*)
    +    val convergenceTol = 1e-12
    +    val maxNumIterations = 10
    +
    +    val (_, loss) = LBFGS.runMiniBatchLBFGS(
    +      dataRDD,
    +      gradient,
    +      simpleUpdater,
    +      numCorrections,
    +      convergenceTol,
    +      maxNumIterations,
    +      regParam,
    +      miniBatchFrac,
    +      initialWeightsWithIntercept)
    +
    +    // Since the cost function is convex, the loss is guaranteed to be 
monotonically decreasing with L-BFGS optimizer.
    --- End diff --
    
    line too long?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to