code: def transition(measure, n, **measure_args):
      """
      Return a, bb transition matrices for different measures
      Args:
          measure (str): the type of measure
              legt - Legendre (translated)
              legs - Legendre (scaled)
              glagt - generalized Laguerre (translated)
              lagt, tlagt - previous versions of (tilted) Laguerre with slightly different normalization
          n (int): dimension
      """
      # Laguerre (translated)
      if measure == "lagt":
          b = measure_args.get("beta", 1.0)
          a = np.eye(n) / 2 - np.tril(np.ones((n, n)))
          bb = b * np.ones((n, 1))
      elif measure == "tlagt":
          # beta = 1 corresponds to no tilt
          b = measure_args.get("beta", 1.0)
          a = (1.0 - b) / 2 * np.eye(n) - np.tril(np.ones((n, n)))
          bb = b * np.ones((n, 1))
      # Generalized Laguerre
      # alpha 0, beta small is most stable (limits to the 'lagt' measure)
      # alpha 0, beta 1 has transition matrix A = [lower triangular 1]
      elif measure == "glagt":
          alpha = measure_args.get("alpha", 0.0)
          beta = measure_args.get("beta", 0.01)
          a = -np.eye(n) * (1 + beta) / 2 - np.tril(np.ones((n, n)), -1)
          b = ss.binom(alpha + np.arange(n), np.arange(n))[:, None]
  
          l = np.exp(
              0.5
              * (
                  ss.gammaln(np.arange(n) + alpha + 1)
                  - ss.gammaln(np.arange(n) + 1)
              )
          )
          a = (1.0 / l[:, None]) * a * l[None, :]
          bb = (
              (1.0 / l[:, None])
              * b
              * np.exp(-0.5 * ss.gammaln(1 - alpha))
              * beta ** ((1 - alpha) / 2)
          )
      # Legendre (translated)
      elif measure == "legt":
          q = np.arange(n, dtype=np.float64)
          r = (2 * q + 1) ** 0.5
          j, i = np.meshgrid(q, q)
          a = (
              r[:, None]
              * np.where(i < j, (-1.0) ** (i - j), 1)
              * r[None, :]
          )
          bb = r[:, None]
          a = -a
      # LMU: equivalent to LegT up to normalization
      elif measure == "lmu":
          q = np.arange(n, dtype=np.float64)
          r = (2 * q + 1)[:, None]  # / theta
          j, i = np.meshgrid(q, q)
          a = np.where(i < j, -1, (-1.0) ** (i - j + 1)) * r
          bb = (-1.0) ** q[:, None] * r
      # Legendre (scaled)
      elif measure == "legs":
          q = np.arange(n, dtype=np.float64)
          col, row = np.meshgrid(q, q)
          r = 2 * q + 1
          m = -(np.where(row >= col, r, 0) - np.diag(q))
          t = np.sqrt(np.diag(2 * q + 1))
          a = t @ m @ np.linalg.inv(t)
          bb = np.diag(t)[:, None]
          bb = (
              bb.copy()
          )  # Otherwise "UserWarning: given NumPY array is not writeable..." after torch.as_tensor(B)
      else:
          raise NotImplementedError
  
      return a, bb
  
file_path: towhee/towhee/models/vis4mer/utils.py
imports: import torch
  from einops import rearrange
  from scipy import special
  import numpy
  from opt_einsum import contract
  from pykeops.torch import Genred
label_desc: Use image node_id 5 for calling a global function with example usage: transition(measure, n) and returns: a,  bb