Kernel transformations¶
Kernel transformations are applied through the CrossKernel
methods
transf
, linop
, algop
. A
transformation returns a new kernel object derived from the input ones and
additional arguments. Example:
import lsqfitgp as lgp
K = lgp.ExpQuad()
Q = (K
.linop('scale', 2) # rescale the input
.algop('expm1') # amplify positive correlations
.linop('diff', 1, 0) # derive w.r.t. the first argument
)
A kernel can access all transformations defined in its superclasses. However, most transformations will regress the class of the output at least to the superclass which actually defines the transformation. Example:
K = lgp.ExpQuad()
assert isinstance(K, lgp.IsotropicKernel)
Q = K.linop('dim', 'a') # consider only dimension 'a' of the input
assert not isinstance(Q, lgp.IsotropicKernel)
Index¶
Method |
Name |
Classes |
---|---|---|
|
||
Transformations¶
- CrossKernel.algop('-log1p(-x)')[source]
- CrossKernel.algop('1/(1-x)')[source]
- CrossKernel.algop('1/arccos')[source]
- CrossKernel.algop('1/cos')[source]
- CrossKernel.algop('add', other)[source]
Sum of kernels. .. math: \mathrm{newkernel}(x, y) &= \mathrm{kernel}(x, y) + \mathrm{other}(x, y), \\ \mathrm{newkernel}(x, y) &= \mathrm{kernel}(x, y) + \mathrm{other}. Parameters ---------- other : CrossKernel or scalar The other kernel.
- CrossKernel.algop('arcsin')[source]
Inverse sine, element-wise. LAX-backend implementation of :func:`numpy.arcsin`. *Original docstring below.* Parameters ---------- x : array_like `y`-coordinate on the unit circle. Returns ------- angle : ndarray The inverse sine of each element in `x`, in radians and in the closed interval ``[-pi/2, pi/2]``. This is a scalar if `x` is a scalar. References ---------- Abramowitz, M. and Stegun, I. A., *Handbook of Mathematical Functions*, 10th printing, New York: Dover, 1964, pp. 79ff. https://personal.math.ubc.ca/~cbm/aands/page_79.htm
- CrossKernel.algop('arctanh')[source]
Inverse hyperbolic tangent element-wise. LAX-backend implementation of :func:`numpy.arctanh`. *Original docstring below.* Parameters ---------- x : array_like Input array. Returns ------- out : ndarray or scalar Array of the same shape as `x`. This is a scalar if `x` is a scalar. References ---------- .. [1] M. Abramowitz and I.A. Stegun, "Handbook of Mathematical Functions", 10th printing, 1964, pp. 86. https://personal.math.ubc.ca/~cbm/aands/page_86.htm .. [2] Wikipedia, "Inverse hyperbolic function", https://en.wikipedia.org/wiki/Arctanh
- CrossKernel.algop('cosh')[source]
Hyperbolic cosine, element-wise. LAX-backend implementation of :func:`numpy.cosh`. *Original docstring below.* Equivalent to ``1/2 * (np.exp(x) + np.exp(-x))`` and ``np.cos(1j*x)``. Parameters ---------- x : array_like Input array. Returns ------- out : ndarray or scalar Output array of same shape as `x`. This is a scalar if `x` is a scalar.
- CrossKernel.algop('exp')[source]
Calculate the exponential of all elements in the input array. LAX-backend implementation of :func:`numpy.exp`. *Original docstring below.* Parameters ---------- x : array_like Input values. Returns ------- out : ndarray or scalar Output array, element-wise exponential of `x`. This is a scalar if `x` is a scalar. References ---------- .. [1] Wikipedia, "Exponential function", https://en.wikipedia.org/wiki/Exponential_function .. [2] M. Abramovitz and I. A. Stegun, "Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables," Dover, 1964, p. 69, https://personal.math.ubc.ca/~cbm/aands/page_69.htm
- CrossKernel.algop('expm1')[source]
Calculate ``exp(x) - 1`` for all elements in the array. LAX-backend implementation of :func:`numpy.expm1`. *Original docstring below.* Parameters ---------- x : array_like Input values. Returns ------- out : ndarray or scalar Element-wise exponential minus one: ``out = exp(x) - 1``. This is a scalar if `x` is a scalar.
- CrossKernel.algop('expm1x')[source]
Compute accurately :math:`e^x - 1 - x = x^2/2 {}_1F_1(1, 3, x)`.
- CrossKernel.algop('i0')[source]
Modified Bessel function of order 0. LAX-backend implementation of :func:`scipy.special.i0`. *Original docstring below.* Defined as, .. math: I_0(x) = \sum_{k=0}^\infty \frac{(x^2/4)^k}{(k!)^2} = J_0(\imath x), where :math:`J_0` is the Bessel function of the first kind of order 0. Parameters ---------- x : array_like Argument (float) Returns ------- I : scalar or ndarray Value of the modified Bessel function of order 0 at `x`. References ---------- .. [1] Cephes Mathematical Functions Library, http://www.netlib.org/cephes/
- CrossKernel.algop('i1')[source]
Modified Bessel function of order 1. LAX-backend implementation of :func:`scipy.special.i1`. *Original docstring below.* Defined as, .. math: I_1(x) = \frac{1}{2}x \sum_{k=0}^\infty \frac{(x^2/4)^k}{k! (k + 1)!} = -\imath J_1(\imath x), where :math:`J_1` is the Bessel function of the first kind of order 1. Parameters ---------- x : array_like Argument (float) Returns ------- I : scalar or ndarray Value of the modified Bessel function of order 1 at `x`. References ---------- .. [1] Cephes Mathematical Functions Library, http://www.netlib.org/cephes/
- CrossKernel.algop('mul', other)[source]
Product of kernels. .. math: \mathrm{newkernel}(x, y) &= \mathrm{kernel}(x, y) \cdot \mathrm{other}(x, y), \\ \mathrm{newkernel}(x, y) &= \mathrm{kernel}(x, y) \cdot \mathrm{other}. Parameters ---------- other : CrossKernel or scalar The other kernel.
- CrossKernel.algop('pow', *, exponent)[source]
Power of the kernel. .. math: \mathrm{newkernel}(x, y) = \mathrm{kernel}(x, y)^{\mathrm{exponent}} Parameters ---------- exponent : nonnegative integer The exponent. If traced by jax, it must have unsigned integer type.
- CrossKernel.algop('rpow', *, base)[source]
Exponentiation of the kernel. .. math: \text{newkernel}(x, y) = \text{base}^{\text{kernel}(x, y)} Parameters ---------- base : scalar A number >= 1. If traced by jax, the value is not checked.
- CrossKernel.algop('sinh')[source]
Hyperbolic sine, element-wise. LAX-backend implementation of :func:`numpy.sinh`. *Original docstring below.* Equivalent to ``1/2 * (np.exp(x) - np.exp(-x))`` or ``-1j * np.sin(1j*x)``. Parameters ---------- x : array_like Input array. Returns ------- y : ndarray The corresponding hyperbolic sine values. This is a scalar if `x` is a scalar. References ---------- M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. New York, NY: Dover, 1972, pg. 83.
- CrossKernel.algop('tan')[source]
Compute tangent element-wise. LAX-backend implementation of :func:`numpy.tan`. *Original docstring below.* Equivalent to ``np.sin(x)/np.cos(x)`` element-wise. Parameters ---------- x : array_like Input array. Returns ------- y : ndarray The corresponding tangent values. This is a scalar if `x` is a scalar. References ---------- M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. New York, NY: Dover, 1972.
- CrossKernel.linop('cond', other, cond1[, cond2])[source]
Switch between two independent processes based on a condition. .. math: T(f, g)(x) = \begin{cases} f(x) & \text{if $\mathrm{cond}(x)$,} \\ g(x) & \text{otherwise.} \end{cases} Parameters ---------- cond1, cond2 : callable Function that is applied on an array of points and must return a boolean array with the same shape. other : Kernel of the process used where the condition is false.
- CrossKernel.linop('derivable', xderivable[, yderivable])[source]
Specify the degree of derivability of the function. Parameters ---------- xderivable, yderivable: int or None Degree of derivability of the function. None means unknown. Notes ----- The derivability check is hardcoded into the kernel core and it is not possible to remove it afterwards by applying ``'derivable'`` again with a higher limit.
- CrossKernel.linop('diff', xderiv[, yderiv])[source]
Derive the function. .. math: T(f)(x) = \frac{\partial^n f}{\partial x^n} (x) Parameters ---------- xderiv, yderiv : Deriv_like A `Deriv` or something that can be converted to a `Deriv`. Raises ------ RuntimeError The derivative orders are greater than the `derivative` attribute.
- CrossKernel.linop('dim', xdim[, ydim])[source]
Restrict the function to a field of a structured input: T(f)(x) = f(x[dim]) If the array is not structured, an exception is raised. If the field for name `dim` has a nontrivial shape, the array passed to the kernel is still structured but has only field `dim`. Parameters ---------- xdim, ydim: None, str, list of str Field names or lists of field names.
- CrossKernel.linop('fourier', dox[, doy])[source]
Compute the Fourier series transform of the function. .. math: T(f)(k) = \begin{cases} \frac2T \int_0^T \mathrm dx\, f(x) \cos\left(\frac{2\pi}T \frac k2 x\right) & \text{if $k$ is even} \\ \frac2T \int_0^T \mathrm dx\, f(x) \sin\left(\frac{2\pi}T \frac{k+1}2 x\right) & \text{if $k$ is odd} \end{cases} The period :math:`T` is 1.
- CrossKernel.linop('loc', xloc[, yloc])[source]
Translate the process inputs: .. math: T(f)(x) = f(x - \mathrm{loc}) Parameters ---------- xloc, yloc: None, number Translations.
- CrossKernel.linop('maxdim', xmaxdim[, ymaxdim])[source]
Restrict the process to a maximum input dimensionality. Parameters ---------- xmaxdim, ymaxdim: None, int Maximum dimensionality of the input. Notes ----- Once applied a restriction, the check is hardcoded into the kernel core and it is not possible to remove it by applying again `maxdim` with a larger limit.
- CrossKernel.linop('normalize', dox[, doy])[source]
Rescale the process to unit variance. .. math: T(f)(x) &= f(x) / \sqrt{\mathrm{Std}[f(x)]} \\ &= f(x) / \sqrt{\mathrm{kernel}(x, x)} Parameters ---------- dox, doy : bool Whether to rescale.
- CrossKernel.linop('rescale', xfun[, yfun])[source]
Rescale the output of the function. .. math: T(f)(x) = \mathrm{xfun}(x) f(x) Parameters ---------- xfun, yfun : callable or None Functions from the type of the arguments of the kernel to scalar.
- CrossKernel.linop('scale', xscale[, yscale])[source]
Rescale the process inputs: .. math: T(f)(x) = f(x / \mathrm{scale}) Parameters ---------- xscale, yscale: None, number Rescaling factors.
- CrossKernel.linop('xtransf', xfun[, yfun])[source]
Transform the inputs of the function. .. math: T(f)(x) = f(\mathrm{fun}(x)) Parameters ---------- xfun, yfun : callable or None Functions mapping a new kind of input to the kind of input accepted by the kernel.
- CrossKernel.transf('forcekron')[source]
Force the kernel to be a separate product over dimensions: .. math: \mathrm{newkernel}(x, y) = \prod_i \mathrm{kernel}(x_i, y_i) Returns ------- newkernel : Kernel The transformed kernel.