Skip to content

Commit

Permalink
fix minor error and remove useless method
Browse files Browse the repository at this point in the history
  • Loading branch information
yinxusen committed Apr 10, 2014
1 parent 10cf5d3 commit 16ae684
Showing 1 changed file with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ private class ColumnStatisticsAggregator(private val n: Int)

val denominator = totalCnt - 1.0

// Sample variance is computed, if the denominator is 0, the variance is just 0.
if (denominator != 0.0) {
// Sample variance is computed, if the denominator is less than 0, the variance is just 0.
if (denominator > 0.0) {
val deltaMean = currMean
var i = 0
while (i < currM2n.size) {
Expand Down Expand Up @@ -107,8 +107,12 @@ private class ColumnStatisticsAggregator(private val n: Int)
currData.activeIterator.foreach {
case (_, 0.0) => // Skip explicit zero elements.
case (i, value) =>
if (currMax(i) < value) currMax(i) = value
if (currMin(i) > value) currMin(i) = value
if (currMax(i) < value) {
currMax(i) = value
}
if (currMin(i) > value) {
currMin(i) = value
}

val tmpPrevMean = currMean(i)
currMean(i) = (currMean(i) * nnz(i) + value) / (nnz(i) + 1.0)
Expand All @@ -125,11 +129,9 @@ private class ColumnStatisticsAggregator(private val n: Int)
* Merges another aggregator.
*/
def merge(other: ColumnStatisticsAggregator): this.type = {

require(n == other.n, s"Dimensions mismatch. Expecting $n but got ${other.n}.")

totalCnt += other.totalCnt

val deltaMean = currMean - other.currMean

var i = 0
Expand All @@ -139,22 +141,21 @@ private class ColumnStatisticsAggregator(private val n: Int)
currMean(i) = (currMean(i) * nnz(i) + other.currMean(i) * other.nnz(i)) /
(nnz(i) + other.nnz(i))
}

// merge m2n together
if (nnz(i) + other.nnz(i) != 0.0) {
currM2n(i) += other.currM2n(i) + deltaMean(i) * deltaMean(i) * nnz(i) * other.nnz(i) /
(nnz(i) + other.nnz(i))
}

if (currMax(i) < other.currMax(i)) currMax(i) = other.currMax(i)

if (currMin(i) > other.currMin(i)) currMin(i) = other.currMin(i)

if (currMax(i) < other.currMax(i)) {
currMax(i) = other.currMax(i)
}
if (currMin(i) > other.currMin(i)) {
currMin(i) = other.currMin(i)
}
i += 1
}

nnz += other.nnz

this
}
}
Expand Down Expand Up @@ -414,17 +415,6 @@ class RowMatrix(
mat
}

/** Updates or verifies the number of columns. */
private def updateNumCols(n: Int) {
if (nCols <= 0) {
nCols == n
} else {
require(nCols == n,
s"The number of columns $n is different from " +
s"what specified or previously computed: ${nCols}.")
}
}

/** Updates or verfires the number of rows. */
private def updateNumRows(m: Long) {
if (nRows <= 0) {
Expand Down

0 comments on commit 16ae684

Please sign in to comment.