Skip to content

Commit 6046550

Browse files
SPARK-3278 scalastyle errors resolved
1 parent 8f5daf9 commit 6046550

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

mllib/src/main/scala/org/apache/spark/mllib/regression/IsotonicRegression.scala

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.spark.mllib.regression
1919

2020
import org.apache.spark.mllib.linalg.Vector
21-
import org.apache.spark.mllib.regression.MonotonicityConstraint.MonotonicityConstraint.{Isotonic, MonotonicityConstraint}
21+
import org.apache.spark.mllib.regression.MonotonicityConstraint.MonotonicityConstraint._
2222
import org.apache.spark.rdd.RDD
2323

2424
/**
@@ -31,7 +31,9 @@ object MonotonicityConstraint {
3131
object MonotonicityConstraint {
3232

3333
sealed trait MonotonicityConstraint {
34-
private[regression] def holds(current: WeightedLabeledPoint, next: WeightedLabeledPoint): Boolean
34+
private[regression] def holds(
35+
current: WeightedLabeledPoint,
36+
next: WeightedLabeledPoint): Boolean
3537
}
3638

3739
/**
@@ -72,7 +74,7 @@ class IsotonicRegressionModel(
7274
testData.map(predict)
7375

7476
override def predict(testData: Vector): Double = {
75-
//take the highest of data points smaller than our feature or data point with lowest feature
77+
// Take the highest of data points smaller than our feature or data point with lowest feature
7678
(predictions.head +:
7779
predictions.filter(y => y.features.toArray.head <= testData.toArray.head)).last.label
7880
}
@@ -87,7 +89,8 @@ trait IsotonicRegressionAlgorithm
8789
/**
8890
* Creates isotonic regression model with given parameters
8991
*
90-
* @param predictions labels estimated using isotonic regression algorithm. Used for predictions on new data points.
92+
* @param predictions labels estimated using isotonic regression algorithm.
93+
* Used for predictions on new data points.
9194
* @param monotonicityConstraint isotonic or antitonic
9295
* @return isotonic regression model
9396
*/
@@ -142,7 +145,7 @@ class PoolAdjacentViolators private [mllib]
142145
in: Array[WeightedLabeledPoint],
143146
monotonicityConstraint: MonotonicityConstraint): Array[WeightedLabeledPoint] = {
144147

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

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

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

167-
//if monotonicity was not violated, move to next data point
170+
// If monotonicity was not violated, move to next data point
168171
if(i == j) {
169172
i = i + 1
170173
} else {
171-
//otherwise pool the violating sequence
172-
//and check if pooling caused monotonicity violation in previously processed points
174+
// Otherwise pool the violating sequence
175+
// And check if pooling caused monotonicity violation in previously processed points
173176
while (i >= 0 && !monotonicityConstraint.holds(in(i), in(i + 1))) {
174177
pool(in, i, j)
175178
i = i - 1
@@ -214,10 +217,11 @@ object IsotonicRegression {
214217
* Label is the dependent y value
215218
* Weight of the data point is the number of measurements. Default is 1
216219
*
217-
* @param input RDD of (label, array of features, weight). Each point describes a row of the data
218-
* matrix A as well as the corresponding right hand side label y
219-
* and weight as number of measurements
220-
* @param monotonicityConstraint
220+
* @param input RDD of (label, array of features, weight).
221+
* Each point describes a row of the data
222+
* matrix A as well as the corresponding right hand side label y
223+
* and weight as number of measurements
224+
* @param monotonicityConstraint Isotonic (increasing) or Antitonic (decreasing) sequence
221225
*/
222226
def train(
223227
input: RDD[WeightedLabeledPoint],

mllib/src/main/scala/org/apache/spark/mllib/util/IsotonicDataGenerator.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ object IsotonicDataGenerator {
4141
*/
4242
def generateIsotonicInput(labels: Double*): Seq[WeightedLabeledPoint] = {
4343
labels.zip(1 to labels.size)
44-
.map(point => labeledPointToWeightedLabeledPoint(LabeledPoint(point._1, Vectors.dense(point._2))))
44+
.map(point => labeledPointToWeightedLabeledPoint(
45+
LabeledPoint(point._1, Vectors.dense(point._2))))
4546
}
4647

4748
/**
@@ -50,7 +51,9 @@ object IsotonicDataGenerator {
5051
* @param weights list of weights for the data points
5152
* @return sequence of data points
5253
*/
53-
def generateWeightedIsotonicInput(labels: Seq[Double], weights: Seq[Double]): Seq[WeightedLabeledPoint] = {
54+
def generateWeightedIsotonicInput(
55+
labels: Seq[Double],
56+
weights: Seq[Double]): Seq[WeightedLabeledPoint] = {
5457
labels.zip(1 to labels.size).zip(weights)
5558
.map(point => WeightedLabeledPoint(point._1._1, Vectors.dense(point._1._2), point._2))
5659
}

0 commit comments

Comments
 (0)