class_docstr: Test behaviour of the learn_dynamic_structure of `from_numpy_dynamic`
class_docstr_tok: ["Test","behaviour","of","the","learn_dynamic_structure","of","`","from_numpy_dynamic","`"]
docstr: Given a small data set with p=2, all the intra-slice must be correct, and 90%+ found.
  the majority of the inter edges must be found too
docstr_tok: ["Given","a","small","data","set","with","p=2",",","all","the","intra-slice","must","be","correct",",","and","90","%","+","found",".","the","majority","of","the","inter","edges","must","be","found","too"]
code: def test_expected_structure_learned_p2(self, data_dynotears_p2):
      """
      Given a small data set with p=2, all the intra-slice must be correct, and 90%+ found.
      the majority of the inter edges must be found too
      """
  
      sm = from_numpy_dynamic(
          data_dynotears_p2["X"],
          data_dynotears_p2["Y"],
          w_threshold=0.25,
      )
      w_edges = [
          (f"{i}_lag0", f"{j}_lag0")
          for i in range(5)
          for j in range(5)
          if data_dynotears_p2["W"][i, j] != 0
      ]
      a_edges = [
          (f"{i % 5}_lag{1 + i // 5}", f"{j}_lag0")
          for i in range(5)
          for j in range(5)
          if data_dynotears_p2["A"][i, j] != 0
      ]
  
      edges_in_sm_and_a = [el for el in sm.edges if el in a_edges]
      sm_inter_edges = [el for el in sm.edges if "lag0" not in el[0]]
      sm_intra_edges = [el for el in sm.edges if "lag0" in el[0]]
  
      assert (
          len([el for el in sm_intra_edges if el not in w_edges]) == 0
      )
      assert (
          len([el for el in w_edges if el not in sm_intra_edges])
          / len(w_edges)
          <= 1.0
      )
      assert len(edges_in_sm_and_a) / len(a_edges) > 0.5
      assert len(edges_in_sm_and_a) / len(sm_inter_edges) > 0.5
  
imports: import re
  import networkx
  import numpy
  import pandas
  import pytest
  from causalnex.structure.dynotears import from_numpy_dynamic, from_pandas_dynamic
label_desc: Use image node_id 8 for calling the TestFromNumpyDynotears obj's underlying member method code with example usage: obj.test_expected_structure_learned_p2(data_dynotears_p2) without return types