class_docstr: Hilbert Space Gaussian process approximation.
  
  The `gp.HSGP` class is an implementation of the Hilbert Space Gaussian process.  It is a
  reduced rank GP approximation that uses a fixed set of basis vectors whose coefficients are
  random functions of a stationary covariance function's power spectral density.  It's usage
  is largely similar to `gp.Latent`.  Like `gp.Latent`, it does not assume a Gaussian noise model
  and can be used with any likelihood, or as a component anywhere within a model.  Also like
  `gp.Latent`, it has `prior` and `conditional` methods.  It supports any sum of covariance
  functions that implement a `power_spectral_density` method. (Note, this excludes the
  `Periodic` covariance function, which uses a different set of basis functions for a
  low rank approximation, as described in `HSGPPeriodic`.).
  
  For information on choosing appropriate `m`, `L`, and `c`, refer Ruitort-Mayol et al. or to
  the PyMC examples that use HSGP.
  
  To work with the HSGP in its "linearized" form, as a matrix of basis vectors and a vector of
  coefficients, see the method `prior_linearized`.
  
  Parameters
  ----------
  m: list
      The number of basis vectors to use for each active dimension (covariance parameter
      `active_dim`).
  L: list
      The boundary of the space for each `active_dim`.  It is called the boundary condition.
      Choose L such that the domain `[-L, L]` contains all points in the column of X given by the
      `active_dim`.
  c: float
      The proportion extension factor.  Used to construct L from X.  Defined as `S = max|X|` such
      that `X` is in `[-S, S]`.  `L` is the calculated as `c * S`.  One of `c` or `L` must be
      provided.  Further information can be found in Ruitort-Mayol et al.
  drop_first: bool
      Default `False`. Sometimes the first basis vector is quite "flat" and very similar to
      the intercept term.  When there is an intercept in the model, ignoring the first basis
      vector may improve sampling. This argument will be deprecated in future versions.
  parameterization: str
      Whether to use `centred` or `noncentered` parameterization when multiplying the
      basis by the coefficients.
  cov_func: Covariance function, must be an instance of `Stationary` and implement a
      `power_spectral_density` method.
  mean_func: None, instance of Mean
      The mean function.  Defaults to zero.
  
  Examples
  --------
  .. code:: python
  
      # A three dimensional column vector of inputs.
      X = np.random.rand(100, 3)
  
      with pm.Model() as model:
          # Specify the covariance function.
          # Three input dimensions, but we only want to use the last two.
          cov_func = pm.gp.cov.ExpQuad(3, ls=0.1, active_dims=[1, 2])
  
          # Specify the HSGP.
          # Use 25 basis vectors across each active dimension for a total of 25 * 25 = 625.
          # The value `c = 4` means the boundary of the approximation
          # lies at four times the half width of the data.
          # In this example the data lie between zero and one,
          # so the boundaries occur at -1.5 and 2.5.  The data, both for
          # training and prediction should reside well within that boundary..
          gp = pm.gp.HSGP(m=[25, 25], c=4.0, cov_func=cov_func)
  
          # Place a GP prior over the function f.
          f = gp.prior("f", X=X)
  
      ...
  
      # After fitting or sampling, specify the distribution
      # at new points with .conditional
      Xnew = np.linspace(-1, 2, 50)[:, None]
  
      with model:
          fcond = gp.conditional("fcond", Xnew=Xnew)
  
  References
  ----------
  -   Ruitort-Mayol, G., and Anderson, M., and Solin, A., and Vehtari, A. (2022). Practical
      Hilbert Space Approximate Bayesian Gaussian Processes for Probabilistic Programming
  
  -   Solin, A., Sarkka, S. (2019) Hilbert Space Methods for Reduced-Rank Gaussian Process
      Regression.
class_docstr_tok: ["Hilbert","Space","Gaussian","process","approximation",".","The","`","gp.HSGP","`","class","is","an","implementation","of","the","Hilbert","Space","Gaussian","process",".","It","is","a","reduced","rank","GP","approximation","that","uses","a","fixed","set","of","basis","vectors","whose","coefficients","are","random","functions","of","a","stationary","covariance","function","'s","power","spectral","density",".","It","'s","usage","is","largely","similar","to","`","gp.Latent","`",".","Like","`","gp.Latent","`",",","it","does","not","assume","a","Gaussian","noise","model","and","can","be","used","with","any","likelihood",",","or","as","a","component","anywhere","within","a","model",".","Also","like","`","gp.Latent","`",",","it","has","`","prior","`","and","`","conditional","`","methods",".","It","supports","any","sum","of","covariance","functions","that","implement","a","`","power_spectral_density","`","method",".","(","Note",",","this","excludes","the","`","Periodic","`","covariance","function",",","which","uses","a","different","set","of","basis","functions","for","a","low","rank","approximation",",","as","described","in","`","HSGPPeriodic","`",".",")",".","For","information","on","choosing","appropriate","`","m","`",",","`","L","`",",","and","`","c","`",",","refer","Ruitort-Mayol","et","al",".","or","to","the","PyMC","examples","that","use","HSGP",".","To","work","with","the","HSGP","in","its","``","linearized","''","form",",","as","a","matrix","of","basis","vectors","and","a","vector","of","coefficients",",","see","the","method","`","prior_linearized","`",".","Parameters","--","--","--","--","--","m",":","list","The","number","of","basis","vectors","to","use","for","each","active","dimension","(","covariance","parameter","`","active_dim","`",")",".","L",":","list","The","boundary","of","the","space","for","each","`","active_dim","`",".","It","is","called","the","boundary","condition",".","Choose","L","such","that","the","domain","`","[","-L",",","L","]","`","contains","all","points","in","the","column","of","X","given","by","the","`","active_dim","`",".","c",":","float","The","proportion","extension","factor",".","Used","to","construct","L","from","X",".","Defined","as","`","S","=","max|X|","`","such","that","`","X","`","is","in","`","[","-S",",","S","]","`",".","`","L","`","is","the","calculated","as","`","c","*","S","`",".","One","of","`","c","`","or","`","L","`","must","be","provided",".","Further","information","can","be","found","in","Ruitort-Mayol","et","al",".","drop_first",":","bool","Default","`","False","`",".","Sometimes","the","first","basis","vector","is","quite","``","flat","''","and","very","similar","to","the","intercept","term",".","When","there","is","an","intercept","in","the","model",",","ignoring","the","first","basis","vector","may","improve","sampling",".","This","argument","will","be","deprecated","in","future","versions",".","parameterization",":","str","Whether","to","use","`","centred","`","or","`","noncentered","`","parameterization","when","multiplying","the","basis","by","the","coefficients",".","cov_func",":","Covariance","function",",","must","be","an","instance","of","`","Stationary","`","and","implement","a","`","power_spectral_density","`","method",".","mean_func",":","None",",","instance","of","Mean","The","mean","function",".","Defaults","to","zero",".","Examples","--","--","--","--","..","code",":",":","python","#","A","three","dimensional","column","vector","of","inputs",".","X","=","np.random.rand","(","100",",","3",")","with","pm.Model","(",")","as","model",":","#","Specify","the","covariance","function",".","#","Three","input","dimensions",",","but","we","only","want","to","use","the","last","two",".","cov_func","=","pm.gp.cov.ExpQuad","(","3",",","ls=0.1",",","active_dims=","[","1",",","2","]",")","#","Specify","the","HSGP",".","#","Use","25","basis","vectors","across","each","active","dimension","for","a","total","of","25","*","25","=","625",".","#","The","value","`","c","=","4","`","means","the","boundary","of","the","approximation","#","lies","at","four","times","the","half","width","of","the","data",".","#","In","this","example","the","data","lie","between","zero","and","one",",","#","so","the","boundaries","occur","at","-1.5","and","2.5",".","The","data",",","both","for","#","training","and","prediction","should","reside","well","within","that","boundary","..","gp","=","pm.gp.HSGP","(","m=","[","25",",","25","]",",","c=4.0",",","cov_func=cov_func",")","#","Place","a","GP","prior","over","the","function","f.","f","=","gp.prior","(","``","f","''",",","X=X",")","...","#","After","fitting","or","sampling",",","specify","the","distribution","#","at","new","points","with",".conditional","Xnew","=","np.linspace","(","-1",",","2",",","50",")","[",":",",","None","]","with","model",":","fcond","=","gp.conditional","(","``","fcond","''",",","Xnew=Xnew",")","References","--","--","--","--","--","-","Ruitort-Mayol",",","G.",",","and","Anderson",",","M.",",","and","Solin",",","A.",",","and","Vehtari",",","A",".","(","2022",")",".","Practical","Hilbert","Space","Approximate","Bayesian","Gaussian","Processes","for","Probabilistic","Programming","-","Solin",",","A.",",","Sarkka",",","S.","(","2019",")","Hilbert","Space","Methods","for","Reduced-Rank","Gaussian","Process","Regression","."]
docstr: Linearized version of the HSGP.  Returns the Laplace eigenfunctions and the square root
  of the power spectral density needed to create the GP.
  
  This function allows the user to bypass the GP interface and work directly with the basis
  and coefficients directly.  This format allows the user to create predictions using
  `pm.set_data` similarly to a linear model.  It also enables computational speed ups in
  multi-GP models since they may share the same basis.  The return values are the Laplace
  eigenfunctions `phi`, and the square root of the power spectral density.
  
  Correct results when using `prior_linearized` in tandem with `pm.set_data` and
  `pm.MutableData` require two conditions.  First, one must specify `L` instead of `c` when
  the GP is constructed.  If not, a RuntimeError is raised.  Second, the `Xs` needs to be
  zero-centered, so it's mean must be subtracted.  An example is given below.
  
  Parameters
  ----------
  Xs: array-like
      Function input values.  Assumes they have been mean subtracted or centered at zero.
  
  Returns
  -------
  phi: array-like
      Either Numpy or PyTensor 2D array of the fixed basis vectors.  There are n rows, one
      per row of `Xs` and `prod(m)` columns, one for each basis vector.
  sqrt_psd: array-like
      Either a Numpy or PyTensor 1D array of the square roots of the power spectral
      densities.
  
  Examples
  --------
  .. code:: python
  
      # A one dimensional column vector of inputs.
      X = np.linspace(0, 10, 100)[:, None]
  
      with pm.Model() as model:
          eta = pm.Exponential("eta", lam=1.0)
          ell = pm.InverseGamma("ell", mu=5.0, sigma=5.0)
          cov_func = eta**2 * pm.gp.cov.ExpQuad(1, ls=ell)
  
          # m = [200] means 200 basis vectors for the first dimension
          # L = [10] means the approximation is valid from Xs = [-10, 10]
          gp = pm.gp.HSGP(m=[200], L=[10], cov_func=cov_func)
  
          # Order is important.  First calculate the mean, then make X a shared variable,
          # then subtract the mean.  When X is mutated later, the correct mean will be
          # subtracted.
          X_mean = np.mean(X, axis=0)
          X = pm.MutableData("X", X)
          Xs = X - X_mean
  
          # Pass the zero-subtracted Xs in to the GP
          phi, sqrt_psd = gp.prior_linearized(Xs=Xs)
  
          # Specify standard normal prior in the coefficients.  The number of which
          # is given by the number of basis vectors, which is also saved in the GP object
          # as m_star.
          beta = pm.Normal("beta", size=gp._m_star)
  
          # The (non-centered) GP approximation is given by
          f = pm.Deterministic("f", phi @ (beta * sqrt_psd))
  
          ...
  
  
      # Then it works just like a linear regression to predict on new data.
      # First mutate the data X,
      x_new = np.linspace(-10, 10, 100)
      with model:
          model.set_data("X", x_new[:, None])
  
      # and then make predictions for the GP using posterior predictive sampling.
      with model:
          ppc = pm.sample_posterior_predictive(idata, var_names=["f"])
docstr_tok: ["Linearized","version","of","the","HSGP",".","Returns","the","Laplace","eigenfunctions","and","the","square","root","of","the","power","spectral","density","needed","to","create","the","GP",".","This","function","allows","the","user","to","bypass","the","GP","interface","and","work","directly","with","the","basis","and","coefficients","directly",".","This","format","allows","the","user","to","create","predictions","using","`","pm.set_data","`","similarly","to","a","linear","model",".","It","also","enables","computational","speed","ups","in","multi-GP","models","since","they","may","share","the","same","basis",".","The","return","values","are","the","Laplace","eigenfunctions","`","phi","`",",","and","the","square","root","of","the","power","spectral","density",".","Correct","results","when","using","`","prior_linearized","`","in","tandem","with","`","pm.set_data","`","and","`","pm.MutableData","`","require","two","conditions",".","First",",","one","must","specify","`","L","`","instead","of","`","c","`","when","the","GP","is","constructed",".","If","not",",","a","RuntimeError","is","raised",".","Second",",","the","`","Xs","`","needs","to","be","zero-centered",",","so","it","'s","mean","must","be","subtracted",".","An","example","is","given","below",".","Parameters","--","--","--","--","--","Xs",":","array-like","Function","input","values",".","Assumes","they","have","been","mean","subtracted","or","centered","at","zero",".","Returns","--","--","--","-","phi",":","array-like","Either","Numpy","or","PyTensor","2D","array","of","the","fixed","basis","vectors",".","There","are","n","rows",",","one","per","row","of","`","Xs","`","and","`","prod","(","m",")","`","columns",",","one","for","each","basis","vector",".","sqrt_psd",":","array-like","Either","a","Numpy","or","PyTensor","1D","array","of","the","square","roots","of","the","power","spectral","densities",".","Examples","--","--","--","--","..","code",":",":","python","#","A","one","dimensional","column","vector","of","inputs",".","X","=","np.linspace","(","0",",","10",",","100",")","[",":",",","None","]","with","pm.Model","(",")","as","model",":","eta","=","pm.Exponential","(","``","eta","''",",","lam=1.0",")","ell","=","pm.InverseGamma","(","``","ell","''",",","mu=5.0",",","sigma=5.0",")","cov_func","=","eta","*","*","2","*","pm.gp.cov.ExpQuad","(","1",",","ls=ell",")","#","m","=","[","200","]","means","200","basis","vectors","for","the","first","dimension","#","L","=","[","10","]","means","the","approximation","is","valid","from","Xs","=","[","-10",",","10","]","gp","=","pm.gp.HSGP","(","m=","[","200","]",",","L=","[","10","]",",","cov_func=cov_func",")","#","Order","is","important",".","First","calculate","the","mean",",","then","make","X","a","shared","variable",",","#","then","subtract","the","mean",".","When","X","is","mutated","later",",","the","correct","mean","will","be","#","subtracted",".","X_mean","=","np.mean","(","X",",","axis=0",")","X","=","pm.MutableData","(","``","X","''",",","X",")","Xs","=","X","-","X_mean","#","Pass","the","zero-subtracted","Xs","in","to","the","GP","phi",",","sqrt_psd","=","gp.prior_linearized","(","Xs=Xs",")","#","Specify","standard","normal","prior","in","the","coefficients",".","The","number","of","which","#","is","given","by","the","number","of","basis","vectors",",","which","is","also","saved","in","the","GP","object","#","as","m_star",".","beta","=","pm.Normal","(","``","beta","''",",","size=gp._m_star",")","#","The","(","non-centered",")","GP","approximation","is","given","by","f","=","pm.Deterministic","(","``","f","''",",","phi","@","(","beta","*","sqrt_psd",")",")","...","#","Then","it","works","just","like","a","linear","regression","to","predict","on","new","data",".","#","First","mutate","the","data","X",",","x_new","=","np.linspace","(","-10",",","10",",","100",")","with","model",":","model.set_data","(","``","X","''",",","x_new","[",":",",","None","]",")","#","and","then","make","predictions","for","the","GP","using","posterior","predictive","sampling",".","with","model",":","ppc","=","pm.sample_posterior_predictive","(","idata",",","var_names=","[","``","f","''","]",")"]
code: def prior_linearized(self, Xs: TensorLike):
      """Linearized version of the HSGP.  Returns the Laplace eigenfunctions and the square root
      of the power spectral density needed to create the GP.
  
      This function allows the user to bypass the GP interface and work directly with the basis
      and coefficients directly.  This format allows the user to create predictions using
      `pm.set_data` similarly to a linear model.  It also enables computational speed ups in
      multi-GP models since they may share the same basis.  The return values are the Laplace
      eigenfunctions `phi`, and the square root of the power spectral density.
  
      Correct results when using `prior_linearized` in tandem with `pm.set_data` and
      `pm.MutableData` require two conditions.  First, one must specify `L` instead of `c` when
      the GP is constructed.  If not, a RuntimeError is raised.  Second, the `Xs` needs to be
      zero-centered, so it's mean must be subtracted.  An example is given below.
  
      Parameters
      ----------
      Xs: array-like
          Function input values.  Assumes they have been mean subtracted or centered at zero.
  
      Returns
      -------
      phi: array-like
          Either Numpy or PyTensor 2D array of the fixed basis vectors.  There are n rows, one
          per row of `Xs` and `prod(m)` columns, one for each basis vector.
      sqrt_psd: array-like
          Either a Numpy or PyTensor 1D array of the square roots of the power spectral
          densities.
  
      Examples
      --------
      .. code:: python
  
          # A one dimensional column vector of inputs.
          X = np.linspace(0, 10, 100)[:, None]
  
          with pm.Model() as model:
              eta = pm.Exponential("eta", lam=1.0)
              ell = pm.InverseGamma("ell", mu=5.0, sigma=5.0)
              cov_func = eta**2 * pm.gp.cov.ExpQuad(1, ls=ell)
  
              # m = [200] means 200 basis vectors for the first dimension
              # L = [10] means the approximation is valid from Xs = [-10, 10]
              gp = pm.gp.HSGP(m=[200], L=[10], cov_func=cov_func)
  
              # Order is important.  First calculate the mean, then make X a shared variable,
              # then subtract the mean.  When X is mutated later, the correct mean will be
              # subtracted.
              X_mean = np.mean(X, axis=0)
              X = pm.MutableData("X", X)
              Xs = X - X_mean
  
              # Pass the zero-subtracted Xs in to the GP
              phi, sqrt_psd = gp.prior_linearized(Xs=Xs)
  
              # Specify standard normal prior in the coefficients.  The number of which
              # is given by the number of basis vectors, which is also saved in the GP object
              # as m_star.
              beta = pm.Normal("beta", size=gp._m_star)
  
              # The (non-centered) GP approximation is given by
              f = pm.Deterministic("f", phi @ (beta * sqrt_psd))
  
              ...
  
  
          # Then it works just like a linear regression to predict on new data.
          # First mutate the data X,
          x_new = np.linspace(-10, 10, 100)
          with model:
              model.set_data("X", x_new[:, None])
  
          # and then make predictions for the GP using posterior predictive sampling.
          with model:
              ppc = pm.sample_posterior_predictive(idata, var_names=["f"])
      """
  
      # Index Xs using input_dim and active_dims of covariance function
      Xs, _ = self.cov_func._slice(Xs)
  
      # If not provided, use Xs and c to set L
      if self._L is None:
          assert isinstance(
              self._c, (numbers.Real, np.ndarray, pt.TensorVariable)
          )
          self.L = pt.as_tensor(set_boundary(Xs, self._c))
      else:
          self.L = self._L
  
      eigvals = calc_eigenvalues(self.L, self._m, tl=pt)
      phi = calc_eigenvectors(Xs, self.L, eigvals, self._m, tl=pt)
      omega = pt.sqrt(eigvals)
      psd = self.cov_func.power_spectral_density(omega)
  
      i = int(self._drop_first is True)
      return phi[:, i:], pt.sqrt(psd[i:])
  
imports: import numbers
  import warnings
  from types import ModuleType
  from typing import Optional, Sequence, Union
  import numpy
  import pytensor.tensor
  import pymc
  from pymc.gp.cov import Covariance, Periodic
  from pymc.gp.gp import Base
  from pymc.gp.mean import Mean, Zero
label_desc: Use image node_id 5 for calling the HSGP obj's underlying member method code with example usage: obj.prior_linearized(Xs) and returns: phi,  pt