class_docstr: The intermediate factors in a Gaussian network can be described
  compactly using a simple parametric representation called the
  canonical form. This representation is closed under the basic
  operations used in inference: factor product, factor division,
  factor reduction, and marginalization. Thus, we define this
  CanonicalDistribution class that allows the inference process to be
  performed on joint Gaussian networks.
  
  A canonical form C (X; K,h,g) is defined as
  
  C (X; K,h,g) = exp( ((-1/2) * X.T * K * X) + (h.T * X) + g)
  
  References
  ----------
  Probabilistic Graphical Models, Principles and Techniques,
  Daphne Koller and Nir Friedman, Section 14.2, Chapter 14.
class_docstr_tok: ["The","intermediate","factors","in","a","Gaussian","network","can","be","described","compactly","using","a","simple","parametric","representation","called","the","canonical","form",".","This","representation","is","closed","under","the","basic","operations","used","in","inference",":","factor","product",",","factor","division",",","factor","reduction",",","and","marginalization",".","Thus",",","we","define","this","CanonicalDistribution","class","that","allows","the","inference","process","to","be","performed","on","joint","Gaussian","networks",".","A","canonical","form","C","(","X\u037e","K",",","h",",","g",")","is","defined","as","C","(","X\u037e","K",",","h",",","g",")","=","exp","(","(","(","-1\/2",")","*","X.T","*","K","*","X",")","+","(","h.T","*","X",")","+","g",")","References","--","--","--","--","--","Probabilistic","Graphical","Models",",","Principles","and","Techniques",",","Daphne","Koller","and","Nir","Friedman",",","Section","14.2",",","Chapter","14","."]
docstr: Parameters
  ----------
  variables: list or array-like
  The variables for wich the distribution is defined.
  
  K: n x n, 2-d array-like
  
  h : n x 1, array-like
  
  g : int, float
  
  pdf: function
  The probability density function of the distribution.
  
  The terms K, h and g are defined parameters for canonical
  factors representation.
  
  Examples
  --------
  >>> from pgmpy.factors.continuous import CanonicalDistribution
  >>> phi = CanonicalDistribution(['X', 'Y'], np.array([[1, -1], [-1, 1]]),
                            np.array([[1], [-1]]), -3)
  >>> phi.variables
  ['X', 'Y']
  
  >>> phi.K
  array([[1, -1],
         [-1, 1]])
  
  >>> phi.h
  array([[1],
         [-1]])
  
  >>> phi.g
  -3
docstr_tok: ["Parameters","--","--","--","--","--","variables",":","list","or","array-like","The","variables","for","wich","the","distribution","is","defined",".","K",":","n","x","n",",","2-d","array-like","h",":","n","x","1",",","array-like","g",":","int",",","float","pdf",":","function","The","probability","density","function","of","the","distribution",".","The","terms","K",",","h","and","g","are","defined","parameters","for","canonical","factors","representation",".","Examples","--","--","--","--",">",">",">","from","pgmpy.factors.continuous","import","CanonicalDistribution",">",">",">","phi","=","CanonicalDistribution","(","[","'","X","'",",","'","Y","'","]",",","np.array","(","[","[","1",",","-1","]",",","[","-1",",","1","]","]",")",",","np.array","(","[","[","1","]",",","[","-1","]","]",")",",","-3",")",">",">",">","phi.variables","[","'","X","'",",","'","Y","'","]",">",">",">","phi.K","array","(","[","[","1",",","-1","]",",","[","-1",",","1","]","]",")",">",">",">","phi.h","array","(","[","[","1","]",",","[","-1","]","]",")",">",">",">","phi.g","-3"]
code: def __init__(self, variables, K, h, g):
      """
      Parameters
      ----------
      variables: list or array-like
      The variables for wich the distribution is defined.
  
      K: n x n, 2-d array-like
  
      h : n x 1, array-like
  
      g : int, float
  
      pdf: function
      The probability density function of the distribution.
  
      The terms K, h and g are defined parameters for canonical
      factors representation.
  
      Examples
      --------
      >>> from pgmpy.factors.continuous import CanonicalDistribution
      >>> phi = CanonicalDistribution(['X', 'Y'], np.array([[1, -1], [-1, 1]]),
                                np.array([[1], [-1]]), -3)
      >>> phi.variables
      ['X', 'Y']
  
      >>> phi.K
      array([[1, -1],
             [-1, 1]])
  
      >>> phi.h
      array([[1],
             [-1]])
  
      >>> phi.g
      -3
  
      """
      no_of_var = len(variables)
  
      if len(h) != no_of_var:
          raise ValueError(
              "Length of h parameter vector must be equal to "
              "the number of variables."
          )
  
      self.variables = variables
      self.h = np.asarray(np.reshape(h, (no_of_var, 1)), dtype=float)
      self.g = g
      self.K = np.asarray(K, dtype=float)
  
      if self.K.shape != (no_of_var, no_of_var):
          raise ValueError(
              f"The K matrix should be a square matrix with order equal to the number of variables. Got: {self.K.shape}, Expected: {(no_of_var, no_of_var)}"
          )
  
file_path: pgmpy/pgmpy/factors/distributions/CanonicalDistribution.py
imports: import numpy
  from pgmpy.factors.distributions import BaseDistribution
  from pgmpy.factors.distributions import GaussianDistribution
label_desc: Use image node_id 1 to create a new CanonicalDistribution object from inherited base classes: BaseDistribution with example: obj = CanonicalDistribution(variables, K, h, g)