class_docstr: Base class for graphical representation of Structural Equation Models(SEMs).
  
  All variables are by default assumed to have an associated error latent variable, therefore
  doesn't need to be specified.
  
  Parameters
  ----------
  ebunch: list/array-like
      List of edges in form of tuples. Each tuple can be of two possible shape:
          1. (u, v): This would add an edge from u to v without setting any parameter
                     for the edge.
          2. (u, v, parameter): This would add an edge from u to v and set the edge's
                      parameter to `parameter`.
  
  latents: list/array-like
      List of nodes which are latent. All other variables are considered observed.
  
  err_corr: list/array-like
      List of tuples representing edges between error terms. It can be of the following forms:
          1. (u, v): Add correlation between error terms of `u` and `v`. Doesn't set any variance or
                     covariance values.
          2. (u, v, covar): Adds correlation between the error terms of `u` and `v` and sets the
                            parameter to `covar`.
  
  err_var: dict (variable: variance)
      Sets variance for the error terms in the model.
  
  Examples
  --------
  Defining a model (Union sentiment model[1]) without setting any paramaters.
  >>> from pgmpy.models import SEMGraph
  >>> sem = SEMGraph(ebunch=[('deferenc', 'unionsen'), ('laboract', 'unionsen'),
  ...                        ('yrsmill', 'unionsen'), ('age', 'deferenc'),
  ...                        ('age', 'laboract'), ('deferenc', 'laboract')],
  ...                latents=[],
  ...                err_corr=[('yrsmill', 'age')],
  ...                err_var={})
  
  Defining a model (Education [2]) with all the parameters set. For not setting any
  parameter `np.NaN` can be explicitly passed.
  >>> sem_edu = SEMGraph(ebunch=[('intelligence', 'academic', 0.8), ('intelligence', 'scale_1', 0.7),
  ...                            ('intelligence', 'scale_2', 0.64), ('intelligence', 'scale_3', 0.73),
  ...                            ('intelligence', 'scale_4', 0.82), ('academic', 'SAT_score', 0.98),
  ...                            ('academic', 'High_school_gpa', 0.75), ('academic', 'ACT_score', 0.87)],
  ...                    latents=['intelligence', 'academic'],
  ...                    err_corr=[],
  ...                    err_var={'intelligence': 1})
  
  References
  ----------
  [1] McDonald, A, J., & Clelland, D. A. (1984). Textile Workers and Union Sentiment.
      Social Forces, 63(2), 502–521
  [2] https://en.wikipedia.org/wiki/Structural_equation_modeling#/
      media/File:Example_Structural_equation_model.svg
  
  Attributes
  ----------
  latents: list
      List of all the latent variables in the model except the error terms.
  
  observed: list
      List of all the observed variables in the model.
  
  graph: nx.DirectedGraph
      The graphical structure of the latent and observed variables except the error terms.
      The parameters are stored in the `weight` attribute of each edge.
  
  err_graph: nx.Graph
      An undirected graph representing the relations between the error terms of the model.
      The node of the graph has the same name as the variable but represents the error terms.
      The variance is stored in the `weight` attribute of the node and the covariance are stored
      in the `weight` attribute of the edge.
  
  full_graph_struct: nx.DiGraph
      Represents the full graph structure. The names of error terms start with `.` and
      new nodes are added for each correlation which starts with `..`.
class_docstr_tok: ["Base","class","for","graphical","representation","of","Structural","Equation","Models","(","SEMs",")",".","All","variables","are","by","default","assumed","to","have","an","associated","error","latent","variable",",","therefore","does","n't","need","to","be","specified",".","Parameters","--","--","--","--","--","ebunch",":","list\/array-like","List","of","edges","in","form","of","tuples",".","Each","tuple","can","be","of","two","possible","shape",":","1",".","(","u",",","v",")",":","This","would","add","an","edge","from","u","to","v","without","setting","any","parameter","for","the","edge",".","2",".","(","u",",","v",",","parameter",")",":","This","would","add","an","edge","from","u","to","v","and","set","the","edge's","parameter","to","`","parameter","`",".","latents",":","list\/array-like","List","of","nodes","which","are","latent",".","All","other","variables","are","considered","observed",".","err_corr",":","list\/array-like","List","of","tuples","representing","edges","between","error","terms",".","It","can","be","of","the","following","forms",":","1",".","(","u",",","v",")",":","Add","correlation","between","error","terms","of","`","u","`","and","`","v","`",".","Does","n't","set","any","variance","or","covariance","values",".","2",".","(","u",",","v",",","covar",")",":","Adds","correlation","between","the","error","terms","of","`","u","`","and","`","v","`","and","sets","the","parameter","to","`","covar","`",".","err_var",":","dict","(","variable",":","variance",")","Sets","variance","for","the","error","terms","in","the","model",".","Examples","--","--","--","--","Defining","a","model","(","Union","sentiment","model","[","1","]",")","without","setting","any","paramaters",".",">",">",">","from","pgmpy.models","import","SEMGraph",">",">",">","sem","=","SEMGraph","(","ebunch=","[","(","'deferenc","'",",","'unionsen","'",")",",","(","'laboract","'",",","'unionsen","'",")",",","...","(","'yrsmill","'",",","'unionsen","'",")",",","(","'age","'",",","'deferenc","'",")",",","...","(","'age","'",",","'laboract","'",")",",","(","'deferenc","'",",","'laboract","'",")","]",",","...","latents=","[","]",",","...","err_corr=","[","(","'yrsmill","'",",","'age","'",")","]",",","...","err_var=","{","}",")","Defining","a","model","(","Education","[","2","]",")","with","all","the","parameters","set",".","For","not","setting","any","parameter","`","np.NaN","`","can","be","explicitly","passed",".",">",">",">","sem_edu","=","SEMGraph","(","ebunch=","[","(","'intelligence","'",",","'academic","'",",","0.8",")",",","(","'intelligence","'",",","'scale_1","'",",","0.7",")",",","...","(","'intelligence","'",",","'scale_2","'",",","0.64",")",",","(","'intelligence","'",",","'scale_3","'",",","0.73",")",",","...","(","'intelligence","'",",","'scale_4","'",",","0.82",")",",","(","'academic","'",",","'SAT_score","'",",","0.98",")",",","...","(","'academic","'",",","'High_school_gpa","'",",","0.75",")",",","(","'academic","'",",","'ACT_score","'",",","0.87",")","]",",","...","latents=","[","'intelligence","'",",","'academic","'","]",",","...","err_corr=","[","]",",","...","err_var=","{","'intelligence","'",":","1","}",")","References","--","--","--","--","--","[","1","]","McDonald",",","A",",","J.",",","&","Clelland",",","D.","A",".","(","1984",")",".","Textile","Workers","and","Union","Sentiment",".","Social","Forces",",","63","(","2",")",",","502\u2013521","[","2","]","https",":","\/\/en.wikipedia.org\/wiki\/Structural_equation_modeling","#","\/","media\/File",":","Example_Structural_equation_model.svg","Attributes","--","--","--","--","--","latents",":","list","List","of","all","the","latent","variables","in","the","model","except","the","error","terms",".","observed",":","list","List","of","all","the","observed","variables","in","the","model",".","graph",":","nx.DirectedGraph","The","graphical","structure","of","the","latent","and","observed","variables","except","the","error","terms",".","The","parameters","are","stored","in","the","`","weight","`","attribute","of","each","edge",".","err_graph",":","nx.Graph","An","undirected","graph","representing","the","relations","between","the","error","terms","of","the","model",".","The","node","of","the","graph","has","the","same","name","as","the","variable","but","represents","the","error","terms",".","The","variance","is","stored","in","the","`","weight","`","attribute","of","the","node","and","the","covariance","are","stored","in","the","`","weight","`","attribute","of","the","edge",".","full_graph_struct",":","nx.DiGraph","Represents","the","full","graph","structure",".","The","names","of","error","terms","start","with","`",".","`","and","new","nodes","are","added","for","each","correlation","which","starts","with","`","..","`","."]
docstr: This method is called by `get_fixed_masks` and `get_masks` methods.
  
  Parameters
  ----------
  weight: None | 'weight'
      If None: Returns a 1.0 for an edge in the graph else 0.0
      If 'weight': Returns the weight if a weight is assigned to an edge
              else 0.0
  
  var: dict
      Dict with keys eta, xi, y, and x representing the variables in them.
  
  Returns
  -------
  np.ndarray: Adjacency matrix of model's graph structure.
  
  Notes
  -----
  B: Effect matrix of eta on eta
  \gamma: Effect matrix of xi on eta
  \wedge_y: Effect matrix of eta on y
  \wedge_x: Effect matrix of xi on x
  \phi: Covariance matrix of xi
  \psi: Covariance matrix of eta errors
          heta_e: Covariance matrix of y errors
          heta_del: Covariance matrix of x errors
  
  Examples
  --------
docstr_tok: ["This","method","is","called","by","`","get_fixed_masks","`","and","`","get_masks","`","methods",".","Parameters","--","--","--","--","--","weight",":","None","|","'weight'","If","None",":","Returns","a","1.0","for","an","edge","in","the","graph","else","0.0","If","'weight","'",":","Returns","the","weight","if","a","weight","is","assigned","to","an","edge","else","0.0","var",":","dict","Dict","with","keys","eta",",","xi",",","y",",","and","x","representing","the","variables","in","them",".","Returns","--","--","--","-","np.ndarray",":","Adjacency","matrix","of","model","'s","graph","structure",".","Notes","--","--","-","B",":","Effect","matrix","of","eta","on","eta","\\gamma",":","Effect","matrix","of","xi","on","eta","\\wedge_y",":","Effect","matrix","of","eta","on","y","\\wedge_x",":","Effect","matrix","of","xi","on","x","\\phi",":","Covariance","matrix","of","xi","\\psi",":","Covariance","matrix","of","eta","errors","heta_e",":","Covariance","matrix","of","y","errors","heta_del",":","Covariance","matrix","of","x","errors","Examples","--","--","--","--"]
code: def __standard_lisrel_masks(graph, err_graph, weight, var):
      """
      This method is called by `get_fixed_masks` and `get_masks` methods.
  
      Parameters
      ----------
      weight: None | 'weight'
          If None: Returns a 1.0 for an edge in the graph else 0.0
          If 'weight': Returns the weight if a weight is assigned to an edge
                  else 0.0
  
      var: dict
          Dict with keys eta, xi, y, and x representing the variables in them.
  
      Returns
      -------
      np.ndarray: Adjacency matrix of model's graph structure.
  
      Notes
      -----
      B: Effect matrix of eta on eta
      \gamma: Effect matrix of xi on eta
      \wedge_y: Effect matrix of eta on y
      \wedge_x: Effect matrix of xi on x
      \phi: Covariance matrix of xi
      \psi: Covariance matrix of eta errors
      \theta_e: Covariance matrix of y errors
      \theta_del: Covariance matrix of x errors
  
      Examples
      --------
      """
      # Arrange the adjacency matrix in order y, x, eta, xi and then slice masks from it.
      #       y(p)   x(q)   eta(m)  xi(n)
      # y
      # x
      # eta \wedge_y          B
      # xi         \wedge_x \Gamma
      #
      # But here we are slicing from the transpose of adjacency because we want incoming
      # edges instead of outgoing because parameters come before variables in equations.
      #
      #       y(p)   x(q)   eta(m)  xi(n)
      # y                  \wedge_y
      # x                          \wedge_x
      # eta                   B    \Gamma
      # xi
      y_vars, x_vars, eta_vars, xi_vars = (
          var["y"],
          var["x"],
          var["eta"],
          var["xi"],
      )
  
      p, q, m, n = (
          len(y_vars),
          len(x_vars),
          len(eta_vars),
          len(xi_vars),
      )
  
      nodelist = y_vars + x_vars + eta_vars + xi_vars
      adj_matrix = nx.to_numpy_array(
          graph, nodelist=nodelist, weight=weight
      ).T
  
      B_mask = adj_matrix[p + q : p + q + m, p + q : p + q + m]
      gamma_mask = adj_matrix[p + q : p + q + m, p + q + m :]
      wedge_y_mask = adj_matrix[0:p, p + q : p + q + m]
      wedge_x_mask = adj_matrix[p : p + q, p + q + m :]
  
      err_nodelist = y_vars + x_vars + eta_vars + xi_vars
      err_adj_matrix = nx.to_numpy_array(
          err_graph, nodelist=err_nodelist, weight=weight
      )
  
      if not weight == "weight":
          np.fill_diagonal(err_adj_matrix, 1.0)
  
      theta_e_mask = err_adj_matrix[:p, :p]
      theta_del_mask = err_adj_matrix[p : p + q, p : p + q]
      psi_mask = err_adj_matrix[p + q : p + q + m, p + q : p + q + m]
      phi_mask = err_adj_matrix[p + q + m :, p + q + m :]
  
      return {
          "B": B_mask,
          "gamma": gamma_mask,
          "wedge_y": wedge_y_mask,
          "wedge_x": wedge_x_mask,
          "phi": phi_mask,
          "theta_e": theta_e_mask,
          "theta_del": theta_del_mask,
          "psi": psi_mask,
      }
  
imports: import itertools
  import networkx
  import numpy
  import pandas
  from networkx.algorithms.dag import descendants
  from pyparsing import OneOrMore, Optional, Suppress, Word, alphanums, nums
  from pgmpy.base import DAG
  from pgmpy.global_vars import logger
label_desc: Use image node_id 11 for calling the SEMGraph obj's underlying member method code with example usage: obj.__standard_lisrel_masks(graph, err_graph, weight, var) and returns: dict