Skip to content

Commit

Permalink
SPARK-3278 scalastyle errors resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
zapletal-martin committed Dec 1, 2014
1 parent 8f5daf9 commit 6046550
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.spark.mllib.regression

import org.apache.spark.mllib.linalg.Vector
import org.apache.spark.mllib.regression.MonotonicityConstraint.MonotonicityConstraint.{Isotonic, MonotonicityConstraint}
import org.apache.spark.mllib.regression.MonotonicityConstraint.MonotonicityConstraint._
import org.apache.spark.rdd.RDD

/**
Expand All @@ -31,7 +31,9 @@ object MonotonicityConstraint {
object MonotonicityConstraint {

sealed trait MonotonicityConstraint {
private[regression] def holds(current: WeightedLabeledPoint, next: WeightedLabeledPoint): Boolean
private[regression] def holds(
current: WeightedLabeledPoint,
next: WeightedLabeledPoint): Boolean
}

/**
Expand Down Expand Up @@ -72,7 +74,7 @@ class IsotonicRegressionModel(
testData.map(predict)

override def predict(testData: Vector): Double = {
//take the highest of data points smaller than our feature or data point with lowest feature
// Take the highest of data points smaller than our feature or data point with lowest feature
(predictions.head +:
predictions.filter(y => y.features.toArray.head <= testData.toArray.head)).last.label
}
Expand All @@ -87,7 +89,8 @@ trait IsotonicRegressionAlgorithm
/**
* Creates isotonic regression model with given parameters
*
* @param predictions labels estimated using isotonic regression algorithm. Used for predictions on new data points.
* @param predictions labels estimated using isotonic regression algorithm.
* Used for predictions on new data points.
* @param monotonicityConstraint isotonic or antitonic
* @return isotonic regression model
*/
Expand Down Expand Up @@ -142,7 +145,7 @@ class PoolAdjacentViolators private [mllib]
in: Array[WeightedLabeledPoint],
monotonicityConstraint: MonotonicityConstraint): Array[WeightedLabeledPoint] = {

//Pools sub array within given bounds assigning weighted average value to all elements
// Pools sub array within given bounds assigning weighted average value to all elements
def pool(in: Array[WeightedLabeledPoint], start: Int, end: Int): Unit = {
val poolSubArray = in.slice(start, end + 1)

Expand All @@ -159,17 +162,17 @@ class PoolAdjacentViolators private [mllib]
while(i < in.length) {
var j = i

//find monotonicity violating sequence, if any
// Find monotonicity violating sequence, if any
while(j < in.length - 1 && !monotonicityConstraint.holds(in(j), in(j + 1))) {
j = j + 1
}

//if monotonicity was not violated, move to next data point
// If monotonicity was not violated, move to next data point
if(i == j) {
i = i + 1
} else {
//otherwise pool the violating sequence
//and check if pooling caused monotonicity violation in previously processed points
// Otherwise pool the violating sequence
// And check if pooling caused monotonicity violation in previously processed points
while (i >= 0 && !monotonicityConstraint.holds(in(i), in(i + 1))) {
pool(in, i, j)
i = i - 1
Expand Down Expand Up @@ -214,10 +217,11 @@ object IsotonicRegression {
* Label is the dependent y value
* Weight of the data point is the number of measurements. Default is 1
*
* @param input RDD of (label, array of features, weight). Each point describes a row of the data
* matrix A as well as the corresponding right hand side label y
* and weight as number of measurements
* @param monotonicityConstraint
* @param input RDD of (label, array of features, weight).
* Each point describes a row of the data
* matrix A as well as the corresponding right hand side label y
* and weight as number of measurements
* @param monotonicityConstraint Isotonic (increasing) or Antitonic (decreasing) sequence
*/
def train(
input: RDD[WeightedLabeledPoint],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ object IsotonicDataGenerator {
*/
def generateIsotonicInput(labels: Double*): Seq[WeightedLabeledPoint] = {
labels.zip(1 to labels.size)
.map(point => labeledPointToWeightedLabeledPoint(LabeledPoint(point._1, Vectors.dense(point._2))))
.map(point => labeledPointToWeightedLabeledPoint(
LabeledPoint(point._1, Vectors.dense(point._2))))
}

/**
Expand All @@ -50,7 +51,9 @@ object IsotonicDataGenerator {
* @param weights list of weights for the data points
* @return sequence of data points
*/
def generateWeightedIsotonicInput(labels: Seq[Double], weights: Seq[Double]): Seq[WeightedLabeledPoint] = {
def generateWeightedIsotonicInput(
labels: Seq[Double],
weights: Seq[Double]): Seq[WeightedLabeledPoint] = {
labels.zip(1 to labels.size).zip(weights)
.map(point => WeightedLabeledPoint(point._1._1, Vectors.dense(point._1._2), point._2))
}
Expand Down

0 comments on commit 6046550

Please sign in to comment.