Skip to content
Closed
Show file tree
Hide file tree
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
unit test update
  • Loading branch information
YY-OnCall committed Aug 20, 2017
commit 3d7bfce704efb252c93f599b8af0829555c5fe7f
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,13 @@ class LinearSVC @Since("2.2.0") (
}

val featuresStd = summarizer.variance.toArray.map(math.sqrt)
val getFeaturesStd = (j: Int) => featuresStd(j)
val regParamL2 = $(regParam)
val bcFeaturesStd = instances.context.broadcast(featuresStd)
val regularization = if (regParamL2 != 0.0) {
val shouldApply = (idx: Int) => idx >= 0 && idx < numFeatures
Some(new L2Regularization(regParamL2, shouldApply,
if ($(standardization)) None else Some(featuresStd)))
if ($(standardization)) None else Some(getFeaturesStd)))
} else {
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class LinearSVCSuite extends SparkFunSuite with MLlibTestSparkContext with Defau
assert(model2.intercept !== 0.0)
}

test("sparse coefficients in SVCAggregator") {
test("sparse coefficients in HingeAggregator") {
val bcCoefficients = spark.sparkContext.broadcast(Vectors.sparse(2, Array(0), Array(1.0)))
val bcFeaturesStd = spark.sparkContext.broadcast(Array(1.0))
val agg = new HingeAggregator(bcFeaturesStd, true)(bcCoefficients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HingeAggregatorSuite extends SparkFunSuite with MLlibTestSparkContext {
import DifferentiableLossAggregatorSuite.getClassificationSummarizers

@transient var instances: Array[Instance] = _
@transient var instancesConstantFeature: Array[Instance] = _

override def beforeAll(): Unit = {
super.beforeAll()
Expand All @@ -35,6 +36,10 @@ class HingeAggregatorSuite extends SparkFunSuite with MLlibTestSparkContext {
Instance(1.0, 0.5, Vectors.dense(1.5, 1.0)),
Instance(0.0, 0.3, Vectors.dense(4.0, 0.5))
)
instancesConstantFeature = Array(
Instance(0.0, 0.1, Vectors.dense(1.0, 2.0)),
Instance(1.0, 0.5, Vectors.dense(1.0, 1.0)),
Instance(1.0, 0.3, Vectors.dense(1.0, 0.5)))
}

/** Get summary statistics for some data and create a new HingeAggregator. */
Expand Down Expand Up @@ -74,7 +79,7 @@ class HingeAggregatorSuite extends SparkFunSuite with MLlibTestSparkContext {
}
}

test("check sizes binomial") {
test("check sizes") {
val rng = new scala.util.Random
val numFeatures = instances.head.features.size
val coefWithIntercept = Vectors.dense(Array.fill(numFeatures + 1)(rng.nextDouble))
Expand All @@ -89,8 +94,7 @@ class HingeAggregatorSuite extends SparkFunSuite with MLlibTestSparkContext {
assert(aggNoIntercept.gradient.size === numFeatures)
}


test("check correctness binomial") {
test("check correctness") {
val coefArray = Array(1.0, 2.0)
val intercept = 1.0
val numFeatures = instances.head.features.size
Expand Down Expand Up @@ -134,10 +138,6 @@ class HingeAggregatorSuite extends SparkFunSuite with MLlibTestSparkContext {
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other aggregator tests have one for "zero standard deviation". We should add one here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Added.

test("check with zero standard deviation") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we found out in #18896, this test is not thorough enough. We should check all elements of the gradient for correctness.

val instancesConstantFeature = Array(
Instance(0.0, 0.1, Vectors.dense(1.0, 2.0)),
Instance(1.0, 0.5, Vectors.dense(1.0, 1.0)),
Instance(1.0, 0.3, Vectors.dense(1.0, 0.5)))
val binaryCoefArray = Array(1.0, 2.0)
val intercept = 1.0
val aggConstantFeatureBinary = getNewAggregator(instancesConstantFeature,
Expand Down