Repository: pgmpy/pgmpy

Issue:
Unable to run MMPC function in MMHC estimator
### Subject of the issue
`estimators.mmhc.mmpc()` crashes regardless of dataset used.

### Your environment
* pgmpy version 0.1.11.dev0
* Python version 3.6.9
* Operating System macOS catalina

### Steps to reproduce
Tell us how to reproduce this issue. Please provide a **minimal reproducible code** of
the issue you are facing if possible.

```
import pandas as pd
import numpy as np

import pgmpy
from pgmpy.estimators import MmhcEstimator

df = pd.DataFrame(
    np.random.randint(0, 2, size=(15000, 3)), columns=list("XYZ")
)
df['sum'] = df.sum(axis=1)
mmhc = MmhcEstimator(df)
skeleton = mmhc.mmpc()
```

### Expected behaviour
Tell us what should happen
Function should return an `UndirectedGraph` object.

### Actual behaviour
```
Traceback (most recent call last):
  File "explore.py", line 12, in <module>
    skeleton = mmhc.mmpc()
  File "/.../lib/python3.6/site-packages/pgmpy-0.1.11.dev0-py3.6.egg/pgmpy/estimators/MmhcEstimator.py", line 186, in mmpc
  File "/.../lib/python3.6/site-packages/pgmpy-0.1.11.dev0-py3.6.egg/pgmpy/estimators/MmhcEstimator.py", line 171, in max_min_heuristic
  File "/.../lib/python3.6/site-packages/pgmpy-0.1.11.dev0-py3.6.egg/pgmpy/estimators/MmhcEstimator.py", line 163, in min_assoc
  File "/.../lib/python3.6/site-packages/pgmpy-0.1.11.dev0-py3.6.egg/pgmpy/estimators/MmhcEstimator.py", line 163, in <genexpr>
  File "/.../lib/python3.6/site-packages/pgmpy-0.1.11.dev0-py3.6.egg/pgmpy/estimators/MmhcEstimator.py", line 159, in assoc
  File "/.../lib/python3.6/site-packages/pgmpy-0.1.11.dev0-py3.6.egg/pgmpy/estimators/CITests.py", line 154, in chi_square
KeyError: 'significance_level'
```

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/pgmpy/pgmpy/pull/1341?src=pr&el=h1) Report
> Merging [#1341](https://codecov.io/gh/pgmpy/pgmpy/pull/1341?src=pr&el=desc) into [dev](https://codecov.io/gh/pgmpy/pgmpy/commit/6b74695ecdb464480ab35d70c839964c7a4e7bee?el=desc) will **not change** coverage.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/pgmpy/pgmpy/pull/1341/graphs/tree.svg?width=650&height=150&src=pr&token=UaJMCdHaEF)](https://codecov.io/gh/pgmpy/pgmpy/pull/1341?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##              dev    #1341   +/-   ##
=======================================
  Coverage   93.10%   93.10%           
=======================================
  Files         132      132           
  Lines       13234    13234           
=======================================
  Hits        12322    12322           
  Misses        912      912           
```


| [Impacted Files](https://codecov.io/gh/pgmpy/pgmpy/pull/1341?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pgmpy/estimators/MmhcEstimator.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1341/diff?src=pr&el=tree#diff-cGdtcHkvZXN0aW1hdG9ycy9NbWhjRXN0aW1hdG9yLnB5) | `18.51% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pgmpy/pgmpy/pull/1341?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pgmpy/pgmpy/pull/1341?src=pr&el=footer). Last update [6b74695...4eb231a](https://codecov.io/gh/pgmpy/pgmpy/pull/1341?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pgmpy/estimators/MmhcEstimator.py b/pgmpy/estimators/MmhcEstimator.py
index 56f5c4f0..a67708c1 100644
--- a/pgmpy/estimators/MmhcEstimator.py
+++ b/pgmpy/estimators/MmhcEstimator.py
@@ -156,7 +156,7 @@ class MmhcEstimator(StructureEstimator):
             """Measure for (conditional) association between variables. Use negative
             p-value of independence test.
             """
-            return 1 - chi_square(X, Y, Zs, self.data)[1]
+            return 1 - chi_square(X, Y, Zs, self.data, boolean=False)[1]
 
         def min_assoc(X, Y, Zs):
             "Minimal association of X, Y given any subset of Zs."
diff --git a/pgmpy/factors/continuous/LinearGaussianCPD.py b/pgmpy/factors/continuous/LinearGaussianCPD.py
index 6db05852..aa45b670 100644
--- a/pgmpy/factors/continuous/LinearGaussianCPD.py
+++ b/pgmpy/factors/continuous/LinearGaussianCPD.py
@@ -79,9 +79,9 @@ class LinearGaussianCPD(BaseFactor):
         self.evidence = evidence
         self.sigma_yx = None
 
-        variables = [variable] + evidence
+        self.variables = [variable] + evidence
         super(LinearGaussianCPD, self).__init__(
-            variables, pdf="gaussian", mean=self.mean, covariance=self.variance
+            self.variables, pdf="gaussian", mean=self.mean, covariance=self.variance
         )
 
     def sum_of_product(self, xi, xj):


Test patch:
diff --git a/pgmpy/tests/test_models/test_LinearGaussianBayesianNetwork.py b/pgmpy/tests/test_models/test_LinearGaussianBayesianNetwork.py
index de711894..d282a46a 100644
--- a/pgmpy/tests/test_models/test_LinearGaussianBayesianNetwork.py
+++ b/pgmpy/tests/test_models/test_LinearGaussianBayesianNetwork.py
@@ -9,13 +9,23 @@ from pgmpy.models import LinearGaussianBayesianNetwork
 
 
 class TestLGBNMethods(unittest.TestCase):
-    @unittest.skip("TODO")
     def setUp(self):
         self.model = LinearGaussianBayesianNetwork([("x1", "x2"), ("x2", "x3")])
         self.cpd1 = LinearGaussianCPD("x1", [1], 4)
         self.cpd2 = LinearGaussianCPD("x2", [-5, 0.5], 4, ["x1"])
         self.cpd3 = LinearGaussianCPD("x3", [4, -1], 3, ["x2"])
 
+    def test_cpds_simple(self):
+        self.assertEqual("x1", self.cpd1.variable)
+        self.assertEqual(4, self.cpd1.variance)
+        self.assertEqual([1], self.cpd1.mean)
+
+        self.model.add_cpds(self.cpd1)
+        cpd = self.model.get_cpds("x1")
+        self.assertEqual(cpd.variable, self.cpd1.variable)
+        self.assertEqual(cpd.variance, self.cpd1.variance)
+        self.assertEqual(cpd.mean, self.cpd1.mean)
+
     @unittest.skip("TODO")
     def test_add_cpds(self):
         self.model.add_cpds(self.cpd1)