Skip to content
Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import breeze.optimize.{CachedDiffFunction, DiffFunction}

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.param.{Params, ParamMap}
import org.apache.spark.ml.param.shared.{HasTol, HasElasticNetParam, HasMaxIter,
HasRegParam}
import org.apache.spark.ml.param.shared.{HasTol, HasElasticNetParam, HasMaxIter, HasRegParam}
import org.apache.spark.mllib.stat.MultivariateOnlineSummarizer
import org.apache.spark.mllib.linalg.{Vector, Vectors}
import org.apache.spark.mllib.linalg.BLAS._
Expand Down Expand Up @@ -103,9 +102,7 @@ class LinearRegression extends Regressor[Vector, LinearRegression, LinearRegress
case LabeledPoint(label: Double, features: Vector) => (label, features)
}
val handlePersistence = dataset.rdd.getStorageLevel == StorageLevel.NONE
if (handlePersistence) {
instances.persist(StorageLevel.MEMORY_AND_DISK)
}
if (handlePersistence) instances.persist(StorageLevel.MEMORY_AND_DISK)

val (summarizer, statCounter) = instances.treeAggregate(
(new MultivariateOnlineSummarizer, new StatCounter))( {
Expand Down Expand Up @@ -146,8 +143,7 @@ class LinearRegression extends Regressor[Vector, LinearRegression, LinearRegress
val optimizer = if (paramMap(elasticNetParam) == 0.0 || effectiveRegParam == 0.0) {
new BreezeLBFGS[BDV[Double]](paramMap(maxIter), 10, paramMap(tol))
} else {
new BreezeOWLQN[Int, BDV[Double]](paramMap(maxIter), 10, effectiveL1RegParam,
paramMap(tol))
new BreezeOWLQN[Int, BDV[Double]](paramMap(maxIter), 10, effectiveL1RegParam, paramMap(tol))
}

val initialWeights = Vectors.zeros(numFeatures)
Expand Down Expand Up @@ -304,9 +300,8 @@ private class LeastSquaresAggregator(
featuresStd: Array[Double],
featuresMean: Array[Double]) extends Serializable {

private var totalCnt: Long = 0
private var totalCnt: Long = 0L
private var lossSum = 0.0
private var diffSum = 0.0

private val (effectiveWeightsArray: Array[Double], offset: Double, dim: Int) = {
val weightsArray = weights.toArray.clone()
Expand All @@ -323,9 +318,10 @@ private class LeastSquaresAggregator(
}
(weightsArray, -sum + labelMean / labelStd, weightsArray.length)
}

private val effectiveWeightsVector = Vectors.dense(effectiveWeightsArray)

private val gradientSumArray: Array[Double] = Array.ofDim[Double](dim)
private val gradientSumArray = Array.ofDim[Double](dim)

/**
* Add a new training data to this LeastSquaresAggregator, and update the loss and gradient
Expand All @@ -350,7 +346,6 @@ private class LeastSquaresAggregator(
}
}
lossSum += diff * diff / 2.0
diffSum += diff
}

totalCnt += 1
Expand All @@ -372,7 +367,6 @@ private class LeastSquaresAggregator(
if (other.totalCnt != 0) {
totalCnt += other.totalCnt
lossSum += other.lossSum
diffSum += other.diffSum

var i = 0
val localThisGradientSumArray = this.gradientSumArray
Expand Down