Skip to content

Commit 91a5fae

Browse files
committed
Rearranged equation for part of density function
1 parent 8c35381 commit 91a5fae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mllib/src/main/scala/org/apache/spark/mllib/stat/impl/MultivariateGaussian.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class MultivariateGaussian private[mllib] (
5959
* u = log((2*pi)^(-k/2)^ * det(sigma)^(-1/2)^)
6060
*/
6161
private val (rootSigmaInv: DBM[Double], u: Double) = calculateCovarianceConstants
62-
62+
6363
/** Return the mean vector (mu) for this distribution */
6464
def getMu: Vector = Vectors.fromBreeze(mu)
6565

@@ -124,14 +124,14 @@ class MultivariateGaussian private[mllib] (
124124
val tol = MLUtils.EPSILON * max(d) * d.length
125125

126126
try {
127-
// pseudo-determinant is product of all non-zero singular values
127+
// log(pseudo-determinant) is sum of the logs of all non-zero singular values
128128
val logPseudoDetSigma = d.activeValuesIterator.filter(_ > tol).map(math.log(_)).reduce(_ + _)
129129

130130
// calculate the root-pseudo-inverse of the diagonal matrix of singular values
131131
// by inverting the square root of all non-zero values
132132
val pinvS = diag(new DBV(d.map(v => if (v > tol) math.sqrt(1.0 / v) else 0.0).toArray))
133133

134-
(pinvS * u, (-mu.length / 2.0) * math.log(2.0 * math.Pi) + -0.5 * logPseudoDetSigma)
134+
(pinvS * u, -0.5 * (mu.length * math.log(2.0 * math.Pi) + logPseudoDetSigma))
135135
} catch {
136136
case uex: UnsupportedOperationException =>
137137
throw new IllegalArgumentException("Covariance matrix has no non-zero singular values")

0 commit comments

Comments
 (0)