class_docstr: Class for representing Structural Equation Models. This class is a wrapper over
  `SEMGraph` and `SEMAlg` to provide a consistent API over the different representations.
  
  Attributes
  ----------
  model: SEMGraph instance
      A graphical representation of the model.
class_docstr_tok: ["Class","for","representing","Structural","Equation","Models",".","This","class","is","a","wrapper","over","`","SEMGraph","`","and","`","SEMAlg","`","to","provide","a","consistent","API","over","the","different","representations",".","Attributes","--","--","--","--","--","model",":","SEMGraph","instance","A","graphical","representation","of","the","model","."]
docstr: Initializes a `SEM` instance using graphical structure.
  
  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
      Dict of the form (var: variance).
  
  Examples
  --------
  Defining a model (Union sentiment model[1]) without setting any paramaters.
  >>> from pgmpy.models import SEM
  >>> sem = SEM.from_graph(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 = SEM.from_graph(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={})
  
  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
docstr_tok: ["Initializes","a","`","SEM","`","instance","using","graphical","structure",".","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","Dict","of","the","form","(","var",":","variance",")",".","Examples","--","--","--","--","Defining","a","model","(","Union","sentiment","model","[","1","]",")","without","setting","any","paramaters",".",">",">",">","from","pgmpy.models","import","SEM",">",">",">","sem","=","SEM.from_graph","(","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","=","SEM.from_graph","(","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=","{","}",")","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"]
code: def from_graph(cls, ebunch, latents=[], err_corr=[], err_var={}):
      """
      Initializes a `SEM` instance using graphical structure.
  
      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
          Dict of the form (var: variance).
  
      Examples
      --------
      Defining a model (Union sentiment model[1]) without setting any paramaters.
      >>> from pgmpy.models import SEM
      >>> sem = SEM.from_graph(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 = SEM.from_graph(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={})
  
      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
      """
      return cls(
          syntax="graph",
          ebunch=ebunch,
          latents=latents,
          err_corr=err_corr,
          err_var=err_var,
      )
  
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 3 for calling the SEM obj's underlying member method code with example usage: obj.from_graph(cls, ebunch, latents, err_corr, err_var) and returns: cls