docstr: Test whether the relation is accurate, implicitly tests sequence of
  nodes.
docstr_tok: ["Test","whether","the","relation","is","accurate",",","implicitly","tests","sequence","of","nodes","."]
code: def test_mixed_type_independence(
      self,
      seed,
      n_categories,
      weight_distribution,
      intercept_distribution,
  ):
      """
      Test whether the relation is accurate, implicitly tests sequence of
      nodes.
      """
      np.random.seed(seed)
  
      sm = StructureModel()
      nodes = list(str(x) for x in range(6))
      np.random.shuffle(nodes)
      sm.add_nodes_from(nodes)
      # binary -> categorical
      sm.add_weighted_edges_from([("0", "1", 10)])
      # binary -> continuous
      sm.add_weighted_edges_from([("2", "4", None)])
      # binary -> count
      sm.add_weighted_edges_from([("2", "6", 100)])
  
      schema = {
          "0": "binary",
          "1": f"categorical:{n_categories}",
          "2": "binary",
          "4": "continuous",
          "5": f"categorical:{n_categories}",
          "6": "count",
      }
  
      df = sem_generator(
          graph=sm,
          schema=schema,
          default_type="continuous",
          distributions={
              "weight": weight_distribution,
              "intercept": intercept_distribution,
              "count": 0.05,
          },
          noise_std=2,
          n_samples=100000,
          intercept=True,
          seed=seed,
      )
  
      atol = 0.02  # at least 2% difference bewteen joint & factored!
      # 1. dependent links
      # 0 -> 1 (we look at the class with the highest deviation from uniform
      # to avoid small values)
      c, _ = max(
          (
              (i, np.abs(df[f"1_{i}"].mean() - 1 / n_categories))
              for i in range(n_categories)
          ),
          key=operator.itemgetter(1),
      )
      joint_proba, factored_proba = calculate_proba(df, "0", f"1_{c}")
      assert not np.isclose(
          joint_proba, factored_proba, rtol=0, atol=atol
      )
      # 2 -> 4
      assert not np.isclose(
          df["4"].mean(),
          df["4"][df["2"] == 1].mean(),
          rtol=0,
          atol=atol,
      )
      # binary on count
      assert not np.isclose(
          df.loc[df["2"] == 0, "6"].mean(),
          df.loc[df["2"] == 1, "6"].mean(),
          rtol=0,
          atol=atol,
      )
  
      tol = 0.20  # at most relative tolerance of +- 20% of the
      # 2. independent links
      # categorical
      c, _ = max(
          (
              (i, np.abs(df[f"1_{i}"].mean() - 1 / n_categories))
              for i in range(n_categories)
          ),
          key=operator.itemgetter(1),
      )
      joint_proba, factored_proba = calculate_proba(df, "0", f"5_{c}")
      assert np.isclose(joint_proba, factored_proba, rtol=tol, atol=0)
  
      # binary
      joint_proba, factored_proba = calculate_proba(df, "0", "2")
      assert np.isclose(joint_proba, factored_proba, rtol=tol, atol=0)
  
      # categorical
      c, _ = max(
          (
              (i, np.abs(df[f"1_{i}"].mean() - 1 / n_categories))
              for i in range(n_categories)
          ),
          key=operator.itemgetter(1),
      )
      d, _ = max(
          (
              (d, np.abs(df[f"5_{d}"].mean() - 1 / n_categories))
              for d in range(n_categories)
          ),
          key=operator.itemgetter(1),
      )
      joint_proba, factored_proba = calculate_proba(
          df, f"1_{d}", f"5_{c}"
      )
      assert np.isclose(joint_proba, factored_proba, rtol=tol, atol=0)
  
      # continuous
      # for gaussian distributions, zero variance is equivalent to independence
      assert np.isclose(df[["3", "4"]].corr().values[0, 1], 0, atol=tol)
  
imports: import operator
  from typing import Hashable, Tuple, Union
  import networkx
  import numpy
  import pandas
  import pytest
  from networkx.algorithms.dag import is_directed_acyclic_graph
  from sklearn.gaussian_process.kernels import RBF
  from causalnex.structure.data_generators.core import _sample_binary_from_latent, _sample_count_from_latent, _sample_poisson, generate_structure, nonlinear_sem_generator, sem_generator
  from causalnex.structure.structuremodel import StructureModel
label_desc: Use image node_id 8 for calling the TestMixedDataGen obj's underlying member method code with example usage: obj.test_mixed_type_independence(seed, n_categories, weight_distribution, intercept_distribution) without return types