def test_predict_fixed(self, iris_test_data, iris_edge_list):
        df = iris_test_data.copy()

        ground_truth = np.array([
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [2, 2, 2, 1, 1, 1, 2, 0, 1, 1],
            [0, 2, 1, 1, 0, 2, 2, 1, 1, 1],
            [2, 1, 1, 1, 1, 2, 1, 2, 1, 0],
            [1, 1, 1, 1, 2, 2, 2, 1, 2, 1],
            [1, 2, 1, 0, 1, 2, 1, 1, 0, 1],
            [2, 1, 2, 1, 2, 2, 1, 1, 1, 2],
            [2, 1, 2, 1, 1, 2, 2, 2, 1, 1],
            [2, 1, 1, 1, 2, 2, 1, 2, 1, 2],
            [1, 2, 1, 1, 1, 2, 2, 2, 2, 2],
            [2, 2, 1, 2, 2, 2, 1, 2, 2, 2],
        ])

        discretiser_params = {
            "sepal width (cm)": {
                "method": "fixed",
                "numeric_split_points": [3]
            },
            "petal length (cm)": {
                "method": "fixed",
                "numeric_split_points": [3.7]
            },
            "petal width (cm)": {
                "method": "fixed",
                "numeric_split_points": [1.2]
            },
        }

        label = df["sepal length (cm)"]
        df.drop(["sepal length (cm)"], axis=1, inplace=True)
        clf = BayesianNetworkClassifier(
            iris_edge_list,
            discretiser_kwargs=discretiser_params,
            discretiser_alg={
                "sepal width (cm)": "unsupervised",
                "petal length (cm)": "unsupervised",
                "petal width (cm)": "unsupervised",
            },
        )
        clf.fit(df, label)
        output = clf.predict(df)
        assert np.array_equal(output.reshape(15, -1), ground_truth)
    def test_dt_discretiser(self, iris_test_data, iris_edge_list):
        df = iris_test_data.copy()
        ground_truth = np.array([
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
            [1, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [2, 2, 2, 1, 1, 1, 2, 0, 1, 1],
            [0, 1, 1, 1, 1, 2, 1, 1, 1, 1],
            [2, 1, 1, 1, 1, 1, 1, 1, 1, 0],
            [1, 1, 1, 1, 1, 1, 2, 1, 1, 1],
            [1, 1, 1, 0, 1, 1, 1, 1, 0, 1],
            [2, 1, 2, 2, 2, 2, 1, 2, 2, 2],
            [2, 2, 2, 1, 1, 2, 2, 2, 2, 1],
            [2, 1, 2, 1, 2, 2, 1, 1, 2, 2],
            [2, 2, 2, 1, 2, 2, 2, 2, 1, 2],
            [2, 2, 1, 2, 2, 2, 1, 2, 2, 1],
        ])
        supervised_param = {
            "sepal width (cm)": {
                "max_depth": 2,
                "random_state": 2020
            },
            "petal length (cm)": {
                "max_depth": 2,
                "random_state": 2020
            },
            "petal width (cm)": {
                "max_depth": 2,
                "random_state": 2020
            },
        }

        label = df["sepal length (cm)"]
        df.drop(["sepal length (cm)"], axis=1, inplace=True)
        clf = BayesianNetworkClassifier(
            iris_edge_list,
            discretiser_kwargs=supervised_param,
            discretiser_alg={
                "sepal width (cm)": "tree",
                "petal length (cm)": "tree",
                "petal width (cm)": "tree",
            },
        )
        clf.fit(df, label)
        output = clf.predict(df)
        assert np.array_equal(output.reshape(15, -1), ground_truth)
    def test_shuffled_data(self, iris_test_data, iris_edge_list):
        df = iris_test_data.copy()
        df = df.sample(frac=0.5, random_state=2020)
        ground_truth = np.array([
            [2, 0, 1, 2, 2, 1, 2, 0, 0, 0, 2, 1, 0, 2, 2],
            [0, 1, 2, 2, 0, 0, 1, 2, 0, 2, 1, 1, 2, 0, 0],
            [2, 0, 0, 0, 2, 0, 0, 1, 0, 1, 0, 2, 1, 0, 2],
            [2, 1, 2, 2, 0, 0, 1, 1, 0, 2, 1, 2, 2, 1, 1],
            [0, 0, 0, 0, 1, 2, 0, 0, 1, 2, 2, 0, 0, 2, 0],
        ])
        supervised_param = {
            "sepal width (cm)": {
                "max_depth": 2,
                "random_state": 2020
            },
            "petal length (cm)": {
                "max_depth": 2,
                "random_state": 2020
            },
            "petal width (cm)": {
                "max_depth": 2,
                "random_state": 2020
            },
        }

        label = df["sepal length (cm)"]
        df.drop(["sepal length (cm)"], axis=1, inplace=True)
        clf = BayesianNetworkClassifier(
            iris_edge_list,
            discretiser_kwargs=supervised_param,
            discretiser_alg={
                "sepal width (cm)": "tree",
                "petal length (cm)": "tree",
                "petal width (cm)": "tree",
            },
        )
        clf.fit(df, label)
        output = clf.predict(df)
        assert np.isnan(output).sum() == 0
        assert (ground_truth == output.reshape(5, 15)).all()
    def test_return_probability(self, iris_test_data, iris_edge_list):
        df = iris_test_data.copy()

        discretiser_params = {
            "sepal width (cm)": {
                "method": "fixed",
                "numeric_split_points": [3]
            },
            "petal length (cm)": {
                "method": "fixed",
                "numeric_split_points": [3.7]
            },
            "petal width (cm)": {
                "method": "fixed",
                "numeric_split_points": [1.2]
            },
        }

        label = df["sepal length (cm)"]
        df.drop(["sepal length (cm)"], axis=1, inplace=True)
        clf = BayesianNetworkClassifier(
            iris_edge_list,
            discretiser_kwargs=discretiser_params,
            discretiser_alg={
                "sepal width (cm)": "unsupervised",
                "petal length (cm)": "unsupervised",
                "petal width (cm)": "unsupervised",
            },
            return_prob=True,
        )
        clf.fit(df, label)
        output = clf.predict(df.iloc[0:1])
        assert len(list(output)) == 3
        assert math.isclose(output["sepal length (cm)_0"].values,
                            0.764706,
                            abs_tol=1e-3)
        assert math.isclose(output["sepal length (cm)_1"].values,
                            0.215686,
                            abs_tol=1e-3)