Documentation
¶
Index ¶
- func Diff3D(a, b tensor.Tensor, tol float64) error
- func NewMatFromFunc(r, c int, at func(i, j int) float64, set func(i, j int, v float64)) mat.Matrix
- type ConstantKernel
- func (k ConstantKernel) Bounds() mat.Matrix
- func (k ConstantKernel) CloneWithTheta(theta mat.Matrix) Kernel
- func (k *ConstantKernel) Diag(X mat.Matrix) (K *mat.DiagDense)
- func (k *ConstantKernel) Eval(X, Y mat.Matrix, evalGradient bool) (*mat.Dense, *t.Dense)
- func (k *ConstantKernel) String() string
- func (k *ConstantKernel) Theta() mat.Matrix
- type DotProduct
- func (k DotProduct) Bounds() mat.Matrix
- func (k DotProduct) CloneWithTheta(theta mat.Matrix) Kernel
- func (k *DotProduct) Diag(X mat.Matrix) (K *mat.DiagDense)
- func (k *DotProduct) Eval(X, Y mat.Matrix, evalGradient bool) (K *mat.Dense, Kg *t.Dense)
- func (k *DotProduct) IsStationary() bool
- func (k *DotProduct) String() string
- func (k *DotProduct) Theta() mat.Matrix
- type Exponentiation
- type Kernel
- type KernelOperator
- func (k KernelOperator) Bounds() mat.Matrix
- func (k KernelOperator) CloneWithTheta(theta mat.Matrix) Kernel
- func (k KernelOperator) Diag(X mat.Matrix) *mat.DiagDense
- func (k KernelOperator) Eval(X, Y mat.Matrix, evalGradient bool) (*mat.Dense, *t.Dense)
- func (k KernelOperator) IsStationary() bool
- func (k KernelOperator) String() string
- func (k KernelOperator) Theta() mat.Matrix
- type NormalizedKernelMixin
- type Product
- type RBF
- type StationaryKernelMixin
- type Sum
- type WhiteKernel
- func (k WhiteKernel) Bounds() mat.Matrix
- func (k WhiteKernel) CloneWithTheta(theta mat.Matrix) Kernel
- func (k *WhiteKernel) Diag(X mat.Matrix) *mat.DiagDense
- func (k *WhiteKernel) Eval(X, Y mat.Matrix, evalGradient bool) (*mat.Dense, *t.Dense)
- func (k *WhiteKernel) String() string
- func (k *WhiteKernel) Theta() mat.Matrix
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConstantKernel ¶
type ConstantKernel struct { ConstantValue float64 ConstantValueBounds [2]float64 StationaryKernelMixin }
ConstantKernel can be used as part of a product-kernel where it scales the magnitude of the other factor (kernel) or as part of a sum-kernel, where it modifies the mean of the Gaussian process. k(x_1, x_2) = constant_value for all x_1, x_2
Example ¶
// np.random.seed(1) state := randomkit.NewRandomkitSource(1) // X=np.reshape(np.random.sample(6),(3,2)) X, Y := sample(state, 3, 2), sample(state, 3, 2) K := &ConstantKernel{ConstantValue: 1.23} fmt.Printf("K=%s, stationary:%v\n", K, K.IsStationary()) KXY, _ := K.Eval(X, Y, false) KXX := K.Diag(X) fmt.Printf("X=\n%.8f\nY=\n%.8f\nK(X,Y)=\n%.8f\nK(X,X)=\n%.8f\n", mat.Formatted(X), mat.Formatted(Y), mat.Formatted(KXY), mat.Formatted(KXX))
Output: K=1.11**2, stationary:true X= ⎡0.41702200 0.72032449⎤ ⎢0.00011437 0.30233257⎥ ⎣0.14675589 0.09233859⎦ Y= ⎡0.18626021 0.34556073⎤ ⎢0.39676747 0.53881673⎥ ⎣0.41919451 0.68521950⎦ K(X,Y)= ⎡1.23000000 1.23000000 1.23000000⎤ ⎢1.23000000 1.23000000 1.23000000⎥ ⎣1.23000000 1.23000000 1.23000000⎦ K(X,X)= ⎡1.23000000 0.00000000 0.00000000⎤ ⎢0.00000000 1.23000000 0.00000000⎥ ⎣0.00000000 0.00000000 1.23000000⎦
func (ConstantKernel) CloneWithTheta ¶
func (k ConstantKernel) CloneWithTheta(theta mat.Matrix) Kernel
CloneWithTheta ...
func (*ConstantKernel) Diag ¶
func (k *ConstantKernel) Diag(X mat.Matrix) (K *mat.DiagDense)
Diag returns the diagonal of the kernel k(X, X).
func (*ConstantKernel) Eval ¶
Eval returns K : array, shape (n_samples_X, n_samples_Y) Kernel k(X, Y)
func (*ConstantKernel) String ¶
func (k *ConstantKernel) String() string
String returns string representation of kernel
type DotProduct ¶
DotProduct kernel The DotProduct kernel is non-stationary and can be obtained from linear regression by putting N(0, 1) priors on the coefficients of x_d (d = 1, . . . , D) and a prior of N(0, \sigma_0^2) on the bias. The DotProduct kernel is invariant to a rotation of the coordinates about the origin, but not translations. It is parameterized by a parameter sigma_0^2. For sigma_0^2 =0, the kernel is called the homogeneous linear kernel, otherwise it is inhomogeneous. The kernel is given by k(x_i, x_j) = sigma_0 ^ 2 + x_i \cdot x_j The DotProduct kernel is commonly combined with exponentiation.
Example ¶
// np.random.seed(1) state := randomkit.NewRandomkitSource(1) // X=np.reshape(np.random.sample(6),(3,2)) X, Y := sample(state, 3, 2), sample(state, 3, 2) // K=DotProduct(sigma_0=1.23) K := &DotProduct{Sigma0: 1.23} fmt.Printf("K=%s, stationary:%v\n", K, K.IsStationary()) KXY, _ := K.Eval(X, Y, false) KXX := K.Diag(X) fmt.Printf("X=\n%.8f\nY=\n%.8f\nK(X,Y)=\n%.8f\nK(X,X)=\n%.8f\n", mat.Formatted(X), mat.Formatted(Y), mat.Formatted(KXY), mat.Formatted(KXX))
Output: K=DotProduct(sigma_0=1.23), stationary:false X= ⎡0.41702200 0.72032449⎤ ⎢0.00011437 0.30233257⎥ ⎣0.14675589 0.09233859⎦ Y= ⎡0.18626021 0.34556073⎤ ⎢0.39676747 0.53881673⎥ ⎣0.41919451 0.68521950⎦ K(X,Y)= ⎡1.83949046 2.06648366 2.18129373⎤ ⎢1.61739557 1.67584723 1.72011212⎥ ⎣1.57214338 1.62088154 1.63769147⎦ K(X,X)= ⎡2.20567473 0.00000000 0.00000000⎤ ⎢0.00000000 1.60430500 0.00000000⎥ ⎣0.00000000 0.00000000 1.54296371⎦
func (DotProduct) CloneWithTheta ¶
func (k DotProduct) CloneWithTheta(theta mat.Matrix) Kernel
CloneWithTheta ...
func (*DotProduct) Diag ¶
func (k *DotProduct) Diag(X mat.Matrix) (K *mat.DiagDense)
Diag returns the diagonal of the kernel k(X, X)
func (*DotProduct) IsStationary ¶
func (k *DotProduct) IsStationary() bool
IsStationary returns whether the kernel is stationary
func (*DotProduct) String ¶
func (k *DotProduct) String() string
String returns string representation of kernel
type Exponentiation ¶
Exponentiation exponentiate kernel by given exponent
func (*Exponentiation) Diag ¶
func (k *Exponentiation) Diag(X mat.Matrix) *mat.DiagDense
Diag returns the diagonal of the kernel k(X, X)
type Kernel ¶
type Kernel interface { Theta() mat.Matrix Bounds() mat.Matrix CloneWithTheta(theta mat.Matrix) Kernel Eval(X, Y mat.Matrix, evalGradient bool) (*mat.Dense, *t.Dense) Diag(X mat.Matrix) (K *mat.DiagDense) IsStationary() bool String() string // contains filtered or unexported methods }
Kernel interface
type KernelOperator ¶
type KernelOperator struct {
K1, K2 Kernel
}
KernelOperator is a kernel based on two others
func (KernelOperator) CloneWithTheta ¶
func (k KernelOperator) CloneWithTheta(theta mat.Matrix) Kernel
CloneWithTheta ...
func (KernelOperator) IsStationary ¶
func (k KernelOperator) IsStationary() bool
IsStationary returns whether the kernel is stationary
type NormalizedKernelMixin ¶
type NormalizedKernelMixin struct{}
NormalizedKernelMixin is Mixin for kernels which are normalized: k(X, X)=1
type Product ¶
type Product struct {
KernelOperator
}
Product kernel K1 * K2 of two kernels K1 and K2
Example ¶
// np.random.seed(1) state := randomkit.NewRandomkitSource(1) // X=np.reshape(np.random.sample(6),(3,2)) X, Y := sample(state, 3, 2), sample(state, 3, 2) // K=DotProduct(sigma_0=1.23) K := &Product{KernelOperator{ K1: &ConstantKernel{ConstantValue: 1.23}, K2: &DotProduct{Sigma0: 1.23}}, } fmt.Printf("K=%s, stationary:%v\n", K, K.IsStationary()) KXY, _ := K.Eval(X, Y, false) KXX := K.Diag(X) fmt.Printf("X=\n%.8f\nY=\n%.8f\nK(X,Y)=\n%.8f\nK(X,X)=\n%.8f\n", mat.Formatted(X), mat.Formatted(Y), mat.Formatted(KXY), mat.Formatted(KXX))
Output: K=1.11**2 * DotProduct(sigma_0=1.23), stationary:false X= ⎡0.41702200 0.72032449⎤ ⎢0.00011437 0.30233257⎥ ⎣0.14675589 0.09233859⎦ Y= ⎡0.18626021 0.34556073⎤ ⎢0.39676747 0.53881673⎥ ⎣0.41919451 0.68521950⎦ K(X,Y)= ⎡2.26257327 2.54177490 2.68299128⎤ ⎢1.98939655 2.06129209 2.11573791⎥ ⎣1.93373635 1.99368430 2.01436051⎦ K(X,X)= ⎡2.71297992 0.00000000 0.00000000⎤ ⎢0.00000000 1.97329515 0.00000000⎥ ⎣0.00000000 0.00000000 1.89784536⎦
func (Product) CloneWithTheta ¶
CloneWithTheta ...
type RBF ¶
type RBF struct { LengthScale []float64 LengthScaleBounds [][2]float64 StationaryKernelMixin NormalizedKernelMixin }
RBF kernel is a stationary kernel. It is also known as the "squared exponential" kernel. It is parameterized by a length-scale parameter length_scale>0, which can either be a scalar (isotropic variant of the kernel) or a vector with the same number of dimensions as the inputs X (anisotropic variant of the kernel). The kernel is given by: k(x_i, x_j) = exp(-1 / 2 d(x_i / length_scale, x_j / length_scale)^2) This kernel is infinitely differentiable, which implies that GPs with this kernel as covariance function have mean square derivatives of all orders, and are thus very smooth.
Example ¶
// np.random.seed(1) state := randomkit.NewRandomkitSource(1) // X=np.reshape(np.random.sample(6),(3,2)) X, Y := sample(state, 3, 2), sample(state, 3, 2) // K=DotProduct(sigma_0=1.23) K := &RBF{LengthScale: []float64{1.23}} fmt.Printf("K=%s, stationary:%v\n", K, K.IsStationary()) KXY, _ := K.Eval(X, Y, false) KXX := K.Diag(X) fmt.Printf("X=\n%.8f\nY=\n%.8f\nK(X,Y)=\n%.8f\nK(X,X)=\n%.8f\n", mat.Formatted(X), mat.Formatted(Y), mat.Formatted(KXY), mat.Formatted(KXX))
Output: K=RBF([1.23]), stationary:true X= ⎡0.41702200 0.72032449⎤ ⎢0.00011437 0.30233257⎥ ⎣0.14675589 0.09233859⎦ Y= ⎡0.18626021 0.34556073⎤ ⎢0.39676747 0.53881673⎥ ⎣0.41919451 0.68521950⎦ K(X,Y)= ⎡0.93799022 0.98903690 0.99959124⎤ ⎢0.98800335 0.93194636 0.89898014⎥ ⎣0.97852658 0.91710014 0.86874975⎦ K(X,X)= ⎡1.00000000 0.00000000 0.00000000⎤ ⎢0.00000000 1.00000000 0.00000000⎥ ⎣0.00000000 0.00000000 1.00000000⎦
type StationaryKernelMixin ¶
type StationaryKernelMixin struct{}
StationaryKernelMixin mixin for kernels which are stationary: k(X, Y)= f(X-Y)
func (StationaryKernelMixin) IsStationary ¶
func (StationaryKernelMixin) IsStationary() bool
IsStationary returns whether the kernel is stationary
type Sum ¶
type Sum struct {
KernelOperator
}
Sum kernel K1 + K2 of two kernels K1 and K2
Example ¶
// np.random.seed(1) state := randomkit.NewRandomkitSource(1) // X=np.reshape(np.random.sample(6),(3,2)) X, Y := sample(state, 3, 2), sample(state, 3, 2) // K=DotProduct(sigma_0=1.23) K := &Sum{KernelOperator{K1: &ConstantKernel{ConstantValue: 1.23}, K2: &WhiteKernel{NoiseLevel: 1.23}}} fmt.Printf("K=%s, stationary:%v\n", K, K.IsStationary()) KXY, _ := K.Eval(X, Y, false) KXX := K.Diag(X) fmt.Printf("X=\n%.8f\nY=\n%.8f\nK(X,Y)=\n%.8f\nK(X,X)=\n%.8f\n", mat.Formatted(X), mat.Formatted(Y), mat.Formatted(KXY), mat.Formatted(KXX))
Output: K=1.11**2 + WhiteKernel(noise_level=1.23), stationary:true X= ⎡0.41702200 0.72032449⎤ ⎢0.00011437 0.30233257⎥ ⎣0.14675589 0.09233859⎦ Y= ⎡0.18626021 0.34556073⎤ ⎢0.39676747 0.53881673⎥ ⎣0.41919451 0.68521950⎦ K(X,Y)= ⎡1.23000000 1.23000000 1.23000000⎤ ⎢1.23000000 1.23000000 1.23000000⎥ ⎣1.23000000 1.23000000 1.23000000⎦ K(X,X)= ⎡2.46000000 0.00000000 0.00000000⎤ ⎢0.00000000 2.46000000 0.00000000⎥ ⎣0.00000000 0.00000000 2.46000000⎦
type WhiteKernel ¶
type WhiteKernel struct { NoiseLevel float64 NoiseLevelBounds [2]float64 StationaryKernelMixin }
WhiteKernel ... The main use-case of this kernel is as part of a sum-kernel where it explains the noise-component of the signal. Tuning its parameter corresponds to estimating the noise-level. k(x_1, x_2) = noise_level if x_1 == x_2 else 0
Example ¶
// np.random.seed(1) state := randomkit.NewRandomkitSource(1) // X=np.reshape(np.random.sample(6),(3,2)) X, Y := sample(state, 3, 2), sample(state, 3, 2) K := &WhiteKernel{NoiseLevel: 1.23} fmt.Printf("K=%s, stationary:%v\n", K, K.IsStationary()) KXY, _ := K.Eval(X, Y, false) KXX := K.Diag(X) fmt.Printf("X=\n%.8f\nY=\n%.8f\nK(X,Y)=\n%.8f\nK(X,X)=\n%.8f\n", mat.Formatted(X), mat.Formatted(Y), mat.Formatted(KXY), mat.Formatted(KXX))
Output: K=WhiteKernel(noise_level=1.23), stationary:true X= ⎡0.41702200 0.72032449⎤ ⎢0.00011437 0.30233257⎥ ⎣0.14675589 0.09233859⎦ Y= ⎡0.18626021 0.34556073⎤ ⎢0.39676747 0.53881673⎥ ⎣0.41919451 0.68521950⎦ K(X,Y)= ⎡0.00000000 0.00000000 0.00000000⎤ ⎢0.00000000 0.00000000 0.00000000⎥ ⎣0.00000000 0.00000000 0.00000000⎦ K(X,X)= ⎡1.23000000 0.00000000 0.00000000⎤ ⎢0.00000000 1.23000000 0.00000000⎥ ⎣0.00000000 0.00000000 1.23000000⎦
func (WhiteKernel) CloneWithTheta ¶
func (k WhiteKernel) CloneWithTheta(theta mat.Matrix) Kernel
CloneWithTheta ...
func (*WhiteKernel) Diag ¶
func (k *WhiteKernel) Diag(X mat.Matrix) *mat.DiagDense
Diag returns the diagonal of the kernel k(X, X)
func (*WhiteKernel) String ¶
func (k *WhiteKernel) String() string
String returns string representation of kernel