Github user lins05 commented on a diff in the pull request:
https://github.com/apache/spark/pull/13248#discussion_r70183088
--- Diff: python/pyspark/ml/tests.py ---
@@ -1493,7 +1495,62 @@ def test_infer_schema(self):
self.assertTrue(m, self.sm1)
else:
raise ValueError("Expected a matrix but got type %r" %
type(m))
+class MultiVariateGaussianTests(PySparkTestCase):
+ def test_univariate(self) :
+ x1=Vectors.dense([0.0])
+ x2=Vectors.dense([1.5])
+
+ mu = Vectors.dense([0.0])
+ sigma1= DenseMatrix(1, 1, [1.0])
+ dist1= MultivariateGaussian(mu, sigma1)
+
+ self.assertAlmostEqual(dist1.pdf(x1),0.39894, 5)
+ self.assertAlmostEqual(dist1.pdf(x2),0.12952, 5)
+
+ sigma2= DenseMatrix(1, 1, [4.0])
+ dist2= MultivariateGaussian(mu, sigma2)
+
+ self.assertAlmostEqual(dist2.pdf(x1),0.19947, 5)
+ self.assertAlmostEqual(dist2.pdf(x2),0.15057, 5)
+
+ def test_multivariate(self) :
+ x1=Vectors.dense([0.0, 0.0])
+ x2=Vectors.dense([1.0, 1.0])
+
+ mu = Vectors.dense([0.0, 0.0])
+ sigma1= DenseMatrix(2, 2, [1.0, 0.0, 0.0, 1.0])
+ dist1= MultivariateGaussian(mu, sigma1)
+
+ self.assertAlmostEqual(dist1.pdf(x1),0.159154, 5)
+ self.assertAlmostEqual(dist1.pdf(x2),0.05855, 5)
+
+ sigma2= DenseMatrix(2, 2, [4.0, -1.0, -1.0, 2.0])
+ dist2= MultivariateGaussian(mu, sigma2)
+
+ self.assertAlmostEqual(dist2.pdf(x1),0.060155, 5)
+ self.assertAlmostEqual(dist2.pdf(x2),0.0339717, 5)
+
+ def test_multivariate_degenerate(self) :
+ x1=Vectors.dense([0.0, 0.0])
+ x2=Vectors.dense([1.0, 1.0])
+
+ mu = Vectors.dense([0.0, 0.0])
+ sigma1= DenseMatrix(2, 2, [1.0, 1.0, 1.0, 1.0])
+ dist1= MultivariateGaussian(mu, sigma1)
+
+ self.assertAlmostEqual(dist1.pdf(x1),0.11254, 5)
+ self.assertAlmostEqual(dist1.pdf(x2),0.068259, 5)
+
+ def test_SPARK_11302(self) :
+ x=Vectors.dense([629, 640, 1.7188, 618.19])
+ mu = Vectors.dense([1055.3910505836575, 1070.489299610895,
1.39020554474708, 1040.5907503867697])
+ sigma= DenseMatrix(4, 4, [166769.00466698944, 169336.6705268059,
12.820670788921873, 164243.93314092053,
+ 169336.6705268059, 172041.5670061245, 21.62590020524533,
166678.01075856484,
+ 12.820670788921873, 21.62590020524533, 0.872524191943962,
4.283255814732373,
+ 164243.93314092053, 166678.01075856484, 4.283255814732373,
161848.9196719207])
+ dist= MultivariateGaussian(mu, sigma)
--- End diff --
Please format the code better (e.g. two elements in each row).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]