Liking cljdoc? Tell your friends :D

fastmath.kernel.vector

Vector kernels: functions of two vectors (or two numbers) returning a double.

A vector kernel measures similarity (or, for the conditionally positive definite ones, a negated dissimilarity) of two points. Every constructor takes an optional map of parameters, returns a function (fn [x y] ...) and accepts one dimensional input as plain numbers as well as vectors. Constructors which use a distance take a :distance key, a function of two points returning a double (default: fastmath.vector/dist, euclidean).

Positive definiteness is stated for every kernel: positive definite (PD, every Gram matrix is positive semi-definite), conditionally positive definite (CPD, the Gram matrix is positive semi-definite on vectors with zero sum) or neither. Only PD kernels are valid covariance functions of a Gaussian process; CPD ones need a constant (or polynomial) term.

Kernels: linear, polynomial, gaussian, exponential, laplacian, anova, hyperbolic-tangent, rational-quadratic, multiquadratic, inverse-multiquadratic, geometric, wave, periodic, power, log, spline, b-spline, bessel, bessel2, cauchy, chi-square, chi-square2, histogram, generalized-histogram, generalized-t-student, dirichlet, hellinger, pearson, hyperbolic-secant, matern; rbf->kernel converts a radial basis function into a vector kernel.

Literature: Genton, Classes of Kernels for Machine Learning: A Statistics Perspective, JMLR 2 (2001), http://www.jmlr.org/papers/volume2/genton01a/genton01a.pdf; http://crsouza.com/2010/03/17/kernel-functions-for-machine-learning-applications/ .

Vector kernels: functions of two vectors (or two numbers) returning a double.

A vector kernel measures similarity (or, for the conditionally positive definite ones, a negated dissimilarity) of two points. Every constructor takes an optional map of parameters, returns a function `(fn [x y] ...)` and accepts one dimensional input as plain numbers as well as vectors. Constructors which use a distance take a `:distance` key, a function of two points returning a double (default: [[fastmath.vector/dist]], euclidean).

Positive definiteness is stated for every kernel: positive definite (PD, every Gram matrix is positive semi-definite), conditionally positive definite (CPD, the Gram matrix is positive semi-definite on vectors with zero sum) or neither. Only PD kernels are valid covariance functions of a Gaussian process; CPD ones need a constant (or polynomial) term.

Kernels: [[linear]], [[polynomial]], [[gaussian]], [[exponential]], [[laplacian]], [[anova]], [[hyperbolic-tangent]], [[rational-quadratic]], [[multiquadratic]], [[inverse-multiquadratic]], [[geometric]], [[wave]], [[periodic]], [[power]], [[log]], [[spline]], [[b-spline]], [[bessel]], [[bessel2]], [[cauchy]], [[chi-square]], [[chi-square2]], [[histogram]], [[generalized-histogram]], [[generalized-t-student]], [[dirichlet]], [[hellinger]], [[pearson]], [[hyperbolic-secant]], [[matern]]; [[rbf->kernel]] converts a radial basis function into a vector kernel.

Literature: Genton, Classes of Kernels for Machine Learning: A Statistics Perspective, JMLR 2 (2001), http://www.jmlr.org/papers/volume2/genton01a/genton01a.pdf; http://crsouza.com/2010/03/17/kernel-functions-for-machine-learning-applications/ .
raw docstring

anovaclj

(anova)
(anova {:keys [sigma k d] :or {sigma 1.0 k 1.0 d 1.0}})

Creates the ANOVA kernel, a sum over the components of a Gaussian term: sum_i exp(-sigma (x_i^k - y_i^k)^2)^d.

Parameters:

  • :sigma - multiplier of the squared difference (default: 1.0)
  • :k - power applied to every component before the difference is taken (default: 1.0)
  • :d - power applied to every term of the sum (default: 1.0)

Returns a function (fn [x y]) returning a double; K(x, x) is the dimension of the vector. The power :d acts on every term, not on the sum as in the anovadot kernel of the R package kernlab: both agree for :d 1.0. The power :k of a negative component is NaN unless :k is an integer. The sum of Gaussian terms is positive definite for positive sigma. This is not the elementary symmetric polynomial form of the ANOVA decomposition.

See also gaussian.

Creates the ANOVA kernel, a sum over the components of a Gaussian term: `sum_i exp(-sigma (x_i^k - y_i^k)^2)^d`.

Parameters:

- `:sigma` - multiplier of the squared difference (default: `1.0`)
- `:k` - power applied to every component before the difference is taken (default: `1.0`)
- `:d` - power applied to every term of the sum (default: `1.0`)

Returns a function `(fn [x y])` returning a double; K(x, x) is the dimension of the vector. The power `:d` acts on every term, not on the sum as in the anovadot kernel of the R package kernlab: both agree for `:d 1.0`. The power `:k` of a negative component is `NaN` unless `:k` is an integer. The sum of Gaussian terms is positive definite for positive `sigma`. This is not the elementary symmetric polynomial form of the ANOVA decomposition.

See also [[gaussian]].
raw docstring

b-splineclj

(b-spline)
(b-spline {:keys [n] :or {n 2.0}})

Creates the B-spline kernel, a product over the components of the centered cardinal B-spline of degree 2 n + 1 evaluated at the difference of the components.

Parameters:

  • :n - half of the degree minus one, a non-negative integer (default: 2); the degree of the spline is 2 n + 1

Returns a function (fn [x y]) returning a double. The kernel is supported on the components with abs(x_i - y_i) < n + 1; it is exactly 0.0 at and beyond the edge of the support in every component. The kernel is positive definite (the Fourier transform of the odd degree cardinal B-spline is a non-negative power of sinc). It is not normalised: K(x, x) is the central value of the spline for one component, for example 2/3 for n = 1.

Throws ex-info when :n is negative.

See also spline.

Creates the B-spline kernel, a product over the components of the centered cardinal B-spline of degree `2 n + 1` evaluated at the difference of the components.

Parameters:

- `:n` - half of the degree minus one, a non-negative integer (default: `2`); the degree of the spline is `2 n + 1`

Returns a function `(fn [x y])` returning a double. The kernel is supported on the components with `abs(x_i - y_i) < n + 1`; it is exactly `0.0` at and beyond the edge of the support in every component. The kernel is positive definite (the Fourier transform of the odd degree cardinal B-spline is a non-negative power of sinc). It is not normalised: K(x, x) is the central value of the spline for one component, for example `2/3` for `n = 1`.

Throws `ex-info` when `:n` is negative.

See also [[spline]].
raw docstring

besselclj

(bessel)
(bessel {:keys [sigma n v distance]
         :or {sigma 1.0 n 2.0 v -1.0 distance v/dist}})

Creates the Bessel kernel J_{v+1}(sigma d) d^(n (v+1)), where J is the Bessel function of the first kind and d is the distance of the points.

Parameters:

  • :sigma - scale (default: 1.0)
  • :n - exponent factor (default: 2.0)
  • :v - order of the Bessel function minus one (default: -1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double. The kernel is the one of http://crsouza.com/2010/03/17/kernel-functions-for-machine-learning-applications/ and is not normalised: for v > -1 the kernel is 0 at d = 0, K(x, x) = 0, only for the default v = -1 it is 1. The kernel is not positive definite in general (11 of 12 settings tried had Gram matrices with negative eigenvalues).

See also bessel2.

Creates the Bessel kernel `J_{v+1}(sigma d) d^(n (v+1))`, where `J` is the Bessel function of the first kind and `d` is the distance of the points.

Parameters:

- `:sigma` - scale (default: `1.0`)
- `:n` - exponent factor (default: `2.0`)
- `:v` - order of the Bessel function minus one (default: `-1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double. The kernel is the one of http://crsouza.com/2010/03/17/kernel-functions-for-machine-learning-applications/ and is not normalised: for `v > -1` the kernel is `0` at `d = 0`, K(x, x) = 0, only for the default `v = -1` it is `1`. The kernel is not positive definite in general (11 of 12 settings tried had Gram matrices with negative eigenvalues).

See also [[bessel2]].
raw docstring

bessel2clj

(bessel2)
(bessel2 {:keys [sigma order degree distance]
          :or {sigma 1.0 order 0.0 degree 1.0 distance v/dist}})

Creates the Bessel kernel of the R package kernlab: (J_order(b) b^(-order) / lim)^degree, where b = sigma d, d is the distance of the points and lim = 1 / (Gamma(order + 1) 2^order) is the limit of the numerator at zero.

Parameters:

  • :sigma - scale (default: 1.0)
  • :degree - exponent (default: 1.0)
  • :order - order of the Bessel function of the first kind (default: 0.0); the default of kernlab is 1
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double; K(x, x) = 1. For b < 1e-5 the limit 1.0 is returned (kernlab switches at 1e-4, which gives differences of about 1e-9). The kernel is positive definite in the euclidean space of dimension up to 2 order + 2 (for an integer degree); with the default order this is the plane, so Gram matrices of points in 3 or 5 dimensions are not positive semi-definite.

See also bessel, wave.

Creates the Bessel kernel of the R package kernlab: `(J_order(b) b^(-order) / lim)^degree`, where `b = sigma d`, `d` is the distance of the points and `lim = 1 / (Gamma(order + 1) 2^order)` is the limit of the numerator at zero.

Parameters:

- `:sigma` - scale (default: `1.0`)
- `:degree` - exponent (default: `1.0`)
- `:order` - order of the Bessel function of the first kind (default: `0.0`); the default of kernlab is `1`
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double; K(x, x) = 1. For `b < 1e-5` the limit `1.0` is returned (kernlab switches at `1e-4`, which gives differences of about `1e-9`). The kernel is positive definite in the euclidean space of dimension up to `2 order + 2` (for an integer `degree`); with the default order this is the plane, so Gram matrices of points in 3 or 5 dimensions are not positive semi-definite.

See also [[bessel]], [[wave]].
raw docstring

cauchyclj

(cauchy)
(cauchy {:keys [sigma distance] :or {sigma 1.0 distance v/dist}})

Creates the Cauchy kernel 1 / (1 + (d / sigma)^2), where d is the distance of the points.

Parameters:

  • :sigma - scale (default: 1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance. Equal to rational-quadratic with c = sigma^2.

See also rational-quadratic, generalized-t-student.

Creates the Cauchy kernel `1 / (1 + (d / sigma)^2)`, where `d` is the distance of the points.

Parameters:

- `:sigma` - scale (default: `1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance. Equal to [[rational-quadratic]] with `c = sigma^2`.

See also [[rational-quadratic]], [[generalized-t-student]].
raw docstring

chi-squareclj

(chi-square)
(chi-square _)

Creates the chi-square kernel sum_i 2 x_i y_i / (x_i + y_i) for non-negative vectors, for example histograms.

Parameters:

  • params (optional) - ignored, accepted for a uniform signature.

Returns a function (fn [x y]) returning a double. A component with x_i + y_i = 0 contributes 0 (not NaN), as in the additive chi-square kernel of scikit-learn. With A = additive_chi2_kernel, which is the negative sum (x_i - y_i)^2 / (x_i + y_i), the kernel equals sum (x_i + y_i) / 2 + A / 2. The kernel is positive definite on non-negative input.

See also chi-square2, histogram, hellinger.

Creates the chi-square kernel `sum_i 2 x_i y_i / (x_i + y_i)` for non-negative vectors, for example histograms.

Parameters:

- `params` (optional) - ignored, accepted for a uniform signature.

Returns a function `(fn [x y])` returning a double. A component with `x_i + y_i = 0` contributes `0` (not `NaN`), as in the additive chi-square kernel of scikit-learn. With `A = additive_chi2_kernel`, which is the negative `sum (x_i - y_i)^2 / (x_i + y_i)`, the kernel equals `sum (x_i + y_i) / 2 + A / 2`. The kernel is positive definite on non-negative input.

See also [[chi-square2]], [[histogram]], [[hellinger]].
raw docstring

chi-square2clj

(chi-square2)
(chi-square2 _)

Creates the second chi-square kernel 1 - sum_i (x_i - y_i)^2 / (0.5 (x_i + y_i)) for non-negative vectors.

Parameters:

  • params (optional) - ignored, accepted for a uniform signature.

Returns a function (fn [x y]) returning a double. A component with x_i + y_i = 0 contributes 0 (not NaN), as in the additive chi-square kernel of scikit-learn. With A = additive_chi2_kernel, which is the negative sum (x_i - y_i)^2 / (x_i + y_i), the kernel equals 1 + 2 A. The kernel is conditionally positive definite and is not positive definite.

See also chi-square, histogram.

Creates the second chi-square kernel `1 - sum_i (x_i - y_i)^2 / (0.5 (x_i + y_i))` for non-negative vectors.

Parameters:

- `params` (optional) - ignored, accepted for a uniform signature.

Returns a function `(fn [x y])` returning a double. A component with `x_i + y_i = 0` contributes `0` (not `NaN`), as in the additive chi-square kernel of scikit-learn. With `A = additive_chi2_kernel`, which is the negative `sum (x_i - y_i)^2 / (x_i + y_i)`, the kernel equals `1 + 2 A`. The kernel is conditionally positive definite and is not positive definite.

See also [[chi-square]], [[histogram]].
raw docstring

dirichletclj

(dirichlet)
(dirichlet {:keys [n] :or {n 1.0}})

Creates the Dirichlet kernel, a product over the components of sin((n + 1/2) delta) / (2 sin(delta / 2)), where delta = x_i - y_i.

Parameters:

  • :n - order (default: 1.0)

Returns a function (fn [x y]) returning a double. The kernel is not normalised: for every component the value at delta = 0 is n + 1/2. For an integer n the kernel is positive definite (a half of the Dirichlet kernel is the sum of cosines with non-negative coefficients), for a non-integer n positive definiteness is not guaranteed.

See also periodic.

Creates the Dirichlet kernel, a product over the components of `sin((n + 1/2) delta) / (2 sin(delta / 2))`, where `delta = x_i - y_i`.

Parameters:

- `:n` - order (default: `1.0`)

Returns a function `(fn [x y])` returning a double. The kernel is not normalised: for every component the value at `delta = 0` is `n + 1/2`. For an integer `n` the kernel is positive definite (a half of the Dirichlet kernel is the sum of cosines with non-negative coefficients), for a non-integer `n` positive definiteness is not guaranteed.

See also [[periodic]].
raw docstring

exponentialclj

(exponential)
(exponential {:keys [sigma distance] :or {sigma 1.0 distance v/dist}})

Creates the exponential kernel exp(-d / (2 sigma^2)), where d is the distance of the points.

Parameters:

  • :sigma - scale (default: 1.0); note that sigma enters squared
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance. It equals laplacian with sigma_L = 2 sigma^2 and the Matern kernel of order 1 (the sklearn Matern with nu = 0.5) with a length scale 2 sigma^2. Genton writes the kernel as exp(-d / theta); use laplacian with :sigma theta for that form.

See also laplacian, gaussian, matern.

Creates the exponential kernel `exp(-d / (2 sigma^2))`, where `d` is the distance of the points.

Parameters:

- `:sigma` - scale (default: `1.0`); note that `sigma` enters squared
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance. It equals [[laplacian]] with `sigma_L = 2 sigma^2` and the Matern kernel of order 1 (the sklearn Matern with `nu = 0.5`) with a length scale `2 sigma^2`. Genton writes the kernel as `exp(-d / theta)`; use [[laplacian]] with `:sigma theta` for that form.

See also [[laplacian]], [[gaussian]], [[matern]].
raw docstring

gaussianclj

(gaussian)
(gaussian {:keys [sigma distance] :or {sigma 1.0 distance v/dist}})

Creates the Gaussian (squared exponential, RBF) kernel exp(-d^2 / (2 sigma^2)), where d is the distance of the points.

Parameters:

  • :sigma - length scale (default: 1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance. Equal to the scikit-learn RBF kernel with length_scale = sigma (the gamma of rbf_kernel is 1 / (2 sigma^2)).

See also exponential, laplacian, cauchy, matern.

Creates the Gaussian (squared exponential, RBF) kernel `exp(-d^2 / (2 sigma^2))`, where `d` is the distance of the points.

Parameters:

- `:sigma` - length scale (default: `1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance. Equal to the scikit-learn RBF kernel with `length_scale = sigma` (the `gamma` of `rbf_kernel` is `1 / (2 sigma^2)`).

See also [[exponential]], [[laplacian]], [[cauchy]], [[matern]].
raw docstring

generalized-histogramclj

(generalized-histogram)
(generalized-histogram {:keys [p] :or {p 2.0}})

Creates the generalized histogram intersection kernel sum_i min(abs(x_i)^p, abs(y_i)^p).

Parameters:

  • :p - exponent (default: 2.0)

Returns a function (fn [x y]) returning a double. The kernel is positive definite for a positive p.

See also histogram.

Creates the generalized histogram intersection kernel `sum_i min(abs(x_i)^p, abs(y_i)^p)`.

Parameters:

- `:p` - exponent (default: `2.0`)

Returns a function `(fn [x y])` returning a double. The kernel is positive definite for a positive `p`.

See also [[histogram]].
raw docstring

generalized-t-studentclj

(generalized-t-student)
(generalized-t-student {:keys [p distance] :or {p 2.0 distance v/dist}})

Creates the generalized t-student kernel 1 / (1 + d^p), where d is the distance of the points.

Parameters:

  • :p - exponent (default: 2.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance and 0 < p <= 2. With p = 2 it equals cauchy with sigma = 1.

See also cauchy, power, log.

Creates the generalized t-student kernel `1 / (1 + d^p)`, where `d` is the distance of the points.

Parameters:

- `:p` - exponent (default: `2.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance and `0 < p <= 2`. With `p = 2` it equals [[cauchy]] with `sigma = 1`.

See also [[cauchy]], [[power]], [[log]].
raw docstring

geometricclj

(geometric)
(geometric {:keys [n r distance] :or {r 1.0 distance v/dist}})

Creates the geometric compactly supported kernel: the volume of the intersection of two n-dimensional balls of radius r, divided by the volume of one ball.

The kernel is a function of the distance d of the points, it decreases from 1 at d = 0 to 0 at d = 2 r and is zero beyond. Dimensions 1, 2 and 3 have names in the registry: triangular, circular and spherical.

Parameters:

  • :n - dimension of the balls (required, integer, at least 1)
  • :r - radius of the balls (default: 1.0, must be positive); the support radius of the kernel is 2 r
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in [0, 1]; K(x, x) = 1 for every n, in particular the circular kernel (n = 2) is normalised by 2 / pi. The kernel is positive definite in the euclidean space of dimension n and lower. For n >= 4 the value is computed with a recursion in n, so the cost of one evaluation grows linearly with n; results which are slightly negative by rounding near the edge of the support are returned as 0.0.

Throws ex-info when :n is missing or smaller than 1, or when :r is not positive.

See also rational-quadratic, pearson.

Creates the geometric compactly supported kernel: the volume of the intersection of two n-dimensional balls of radius `r`, divided by the volume of one ball.

The kernel is a function of the distance `d` of the points, it decreases from `1` at `d = 0` to `0` at `d = 2 r` and is zero beyond. Dimensions `1`, `2` and `3` have names in the registry: triangular, circular and spherical.

Parameters:

- `:n` - dimension of the balls (required, integer, at least `1`)
- `:r` - radius of the balls (default: `1.0`, must be positive); the support radius of the kernel is `2 r`
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `[0, 1]`; K(x, x) = 1 for every `n`, in particular the circular kernel (`n = 2`) is normalised by `2 / pi`. The kernel is positive definite in the euclidean space of dimension `n` and lower. For `n >= 4` the value is computed with a recursion in `n`, so the cost of one evaluation grows linearly with `n`; results which are slightly negative by rounding near the edge of the support are returned as `0.0`.

Throws `ex-info` when `:n` is missing or smaller than `1`, or when `:r` is not positive.

See also [[rational-quadratic]], [[pearson]].
raw docstring

hellingerclj

(hellinger)
(hellinger _)

Creates the Hellinger kernel sum_i sqrt(x_i y_i) for non-negative vectors.

Parameters:

  • params (optional) - ignored, accepted for a uniform signature.

Returns a function (fn [x y]) returning a double. A negative product x_i y_i contributes 0. The kernel is the dot product of the square roots of the vectors, so it is positive definite on non-negative input.

See also chi-square, histogram.

Creates the Hellinger kernel `sum_i sqrt(x_i y_i)` for non-negative vectors.

Parameters:

- `params` (optional) - ignored, accepted for a uniform signature.

Returns a function `(fn [x y])` returning a double. A negative product `x_i y_i` contributes `0`. The kernel is the dot product of the square roots of the vectors, so it is positive definite on non-negative input.

See also [[chi-square]], [[histogram]].
raw docstring

histogramclj

(histogram)
(histogram _)

Creates the histogram intersection kernel sum_i min(x_i, y_i).

Parameters:

  • params (optional) - ignored, accepted for a uniform signature.

Returns a function (fn [x y]) returning a double. The kernel is positive definite on non-negative input.

See also generalized-histogram, chi-square.

Creates the histogram intersection kernel `sum_i min(x_i, y_i)`.

Parameters:

- `params` (optional) - ignored, accepted for a uniform signature.

Returns a function `(fn [x y])` returning a double. The kernel is positive definite on non-negative input.

See also [[generalized-histogram]], [[chi-square]].
raw docstring

hyperbolic-secantclj

(hyperbolic-secant)
(hyperbolic-secant {:keys [a distance] :or {a 1.0 distance v/dist}})

Creates the hyperbolic secant kernel sech(a d), where d is the distance of the points.

Parameters:

  • :a - scaling factor (default: 1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for one dimensional input.

See also gaussian, cauchy.

Creates the hyperbolic secant kernel `sech(a d)`, where `d` is the distance of the points.

Parameters:

- `:a` - scaling factor (default: `1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for one dimensional input.

See also [[gaussian]], [[cauchy]].
raw docstring

hyperbolic-tangentclj

(hyperbolic-tangent)
(hyperbolic-tangent {:keys [alpha c] :or {alpha 1.0 c 0.0}})

Creates the hyperbolic tangent (sigmoid) kernel tanh(c + alpha <x, y>).

Parameters:

  • :alpha - dot product multiplier (default: 1.0)
  • :c - shift (default: 0.0)

Returns a function (fn [x y]) returning a double in (-1, 1). The kernel is not positive definite in general (Gram matrices with a minimum eigenvalue near -1 were found), it is only conditionally positive definite for some parameters. Corresponds to the sigmoid kernel of scikit-learn with gamma = alpha and coef0 = c.

See also polynomial, linear.

Creates the hyperbolic tangent (sigmoid) kernel `tanh(c + alpha <x, y>)`.

Parameters:

- `:alpha` - dot product multiplier (default: `1.0`)
- `:c` - shift (default: `0.0`)

Returns a function `(fn [x y])` returning a double in `(-1, 1)`. The kernel is not positive definite in general (Gram matrices with a minimum eigenvalue near -1 were found), it is only conditionally positive definite for some parameters. Corresponds to the sigmoid kernel of scikit-learn with `gamma = alpha` and `coef0 = c`.

See also [[polynomial]], [[linear]].
raw docstring

inverse-multiquadraticclj

(inverse-multiquadratic)
(inverse-multiquadratic {:keys [c distance] :or {c 1.0 distance v/dist}})

Creates the inverse multiquadratic kernel 1 / sqrt(d^2 + c^2).

Parameters:

  • :c - shift (default: 1.0); it is a distance, compare rational-quadratic where c is a squared distance
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1/abs(c)]; K(x, x) = 1 / abs(c). The kernel is positive definite for a euclidean distance.

See also multiquadratic, rational-quadratic.

Creates the inverse multiquadratic kernel `1 / sqrt(d^2 + c^2)`.

Parameters:

- `:c` - shift (default: `1.0`); it is a distance, compare [[rational-quadratic]] where `c` is a squared distance
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1/abs(c)]`; K(x, x) = `1 / abs(c)`. The kernel is positive definite for a euclidean distance.

See also [[multiquadratic]], [[rational-quadratic]].
raw docstring

laplacianclj

(laplacian)
(laplacian {:keys [sigma distance] :or {sigma 1.0 distance v/dist}})

Creates the Laplacian kernel exp(-d / sigma), where d is the distance of the points.

Parameters:

  • :sigma - scale (default: 1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance and for the manhattan distance. The default distance is euclidean, while the scikit-learn laplacian_kernel uses the manhattan (L1) distance with gamma = 1 / sigma: pass :distance v/dist-abs to get it. With the euclidean distance the kernel equals the Matern kernel of order 1 with the length scale sigma.

See also exponential, gaussian, matern.

Creates the Laplacian kernel `exp(-d / sigma)`, where `d` is the distance of the points.

Parameters:

- `:sigma` - scale (default: `1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance and for the manhattan distance. The default distance is euclidean, while the scikit-learn `laplacian_kernel` uses the manhattan (L1) distance with `gamma = 1 / sigma`: pass `:distance v/dist-abs` to get it. With the euclidean distance the kernel equals the Matern kernel of order 1 with the length scale `sigma`.

See also [[exponential]], [[gaussian]], [[matern]].
raw docstring

linearclj

(linear)
(linear _)

Creates the linear kernel, the dot product of two vectors.

Parameters:

  • params (optional) - ignored, accepted for a uniform signature.

Returns a function (fn [x y]) returning <x, y> as a double. The kernel is positive definite. The values are not normalised: K(x, x) is the squared norm of x.

See also polynomial, hyperbolic-tangent.

Creates the linear kernel, the dot product of two vectors.

Parameters:

- `params` (optional) - ignored, accepted for a uniform signature.

Returns a function `(fn [x y])` returning `<x, y>` as a double. The kernel is positive definite. The values are not normalised: K(x, x) is the squared norm of `x`.

See also [[polynomial]], [[hyperbolic-tangent]].
raw docstring

logclj

(log)
(log {:keys [p distance] :or {p 2.0 distance v/dist}})

Creates the logarithmic kernel -log(1 + d^p), where d is the distance of the points.

Parameters:

  • :p - exponent (default: 2.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double; K(x, x) = -0.0. The kernel is conditionally positive definite for 0 < p <= 2 and is not positive definite.

See also power, generalized-t-student.

Creates the logarithmic kernel `-log(1 + d^p)`, where `d` is the distance of the points.

Parameters:

- `:p` - exponent (default: `2.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double; K(x, x) = `-0.0`. The kernel is conditionally positive definite for `0 < p <= 2` and is not positive definite.

See also [[power]], [[generalized-t-student]].
raw docstring

maternclj

(matern)
(matern {:keys [order theta distance] :or {order 1 theta 1.0 distance v/dist}})

Creates the Matern kernel of the half-integer smoothness nu = order / 2, 2^(1-nu) / Gamma(nu) v^nu K_nu(v) with v = 2 sqrt(nu) d / theta, where K is the modified Bessel function of the second kind and d is the distance of the points.

This is the parametrisation of Handcock and Stein: theta = sqrt(2) ell, where ell is the length scale of the Matern kernel of scikit-learn (Matern(length_scale = theta / sqrt(2), nu = order / 2), whose argument is sqrt(2 nu) d / ell). The registry presets are :matern-12 (order 1, equal to exponential in the form exp(-sqrt(2) d / theta)), :matern-32 (order 3) and :matern-52 (order 5).

Parameters:

  • :order - twice the smoothness, an odd positive integer (default: 1); 5 gives the Matern 5/2 kernel
  • :theta - scale (default: 1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance and an odd :order. At a distance so large that the intermediate power overflows (above v = 700) the result is 0.0.

Throws ex-info when :order is not an odd positive integer: the even orders (integer smoothness) are not supported by the half-integer Bessel function.

See also exponential, laplacian, gaussian.

Creates the Matern kernel of the half-integer smoothness `nu = order / 2`, `2^(1-nu) / Gamma(nu) v^nu K_nu(v)` with `v = 2 sqrt(nu) d / theta`, where `K` is the modified Bessel function of the second kind and `d` is the distance of the points.

This is the parametrisation of Handcock and Stein: `theta = sqrt(2) ell`, where `ell` is the length scale of the Matern kernel of scikit-learn (`Matern(length_scale = theta / sqrt(2), nu = order / 2)`, whose argument is `sqrt(2 nu) d / ell`). The registry presets are `:matern-12` (`order` 1, equal to [[exponential]] in the form `exp(-sqrt(2) d / theta)`), `:matern-32` (`order` 3) and `:matern-52` (`order` 5).

Parameters:

- `:order` - twice the smoothness, an odd positive integer (default: `1`); `5` gives the Matern 5/2 kernel
- `:theta` - scale (default: `1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance and an odd `:order`. At a distance so large that the intermediate power overflows (above `v = 700`) the result is `0.0`.

Throws `ex-info` when `:order` is not an odd positive integer: the even orders (integer smoothness) are not supported by the half-integer Bessel function.

See also [[exponential]], [[laplacian]], [[gaussian]].
raw docstring

multiquadraticclj

(multiquadratic)
(multiquadratic {:keys [c distance] :or {c 1.0 distance v/dist}})

Creates the multiquadratic kernel sqrt(d^2 + c^2).

Parameters:

  • :c - shift (default: 1.0); it is a distance, compare rational-quadratic where c is a squared distance
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double; K(x, x) = abs(c). The kernel increases with the distance and is not positive definite: it is conditionally negative definite, so its negation is conditionally positive definite of order 1.

See also inverse-multiquadratic, rational-quadratic.

Creates the multiquadratic kernel `sqrt(d^2 + c^2)`.

Parameters:

- `:c` - shift (default: `1.0`); it is a distance, compare [[rational-quadratic]] where `c` is a squared distance
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double; K(x, x) = `abs(c)`. The kernel increases with the distance and is not positive definite: it is conditionally negative definite, so its negation is conditionally positive definite of order 1.

See also [[inverse-multiquadratic]], [[rational-quadratic]].
raw docstring

pearsonclj

(pearson)
(pearson {:keys [sigma omega distance]
          :or {sigma 1.0 omega 1.0 distance v/dist}})

Creates the Pearson VII kernel (PUK) 1 / (1 + (2 d sqrt(2^(1/omega) - 1) / sigma)^2)^omega, where d is the distance of the points.

The scale is chosen so that sigma is the full width at half maximum of the peak for every omega: the kernel is 1/2 at d = sigma / 2. This is the form of Ustun et al. (2006) and of the PUK kernel in Weka.

Parameters:

  • :sigma - width of the peak (default: 1.0)
  • :omega - tailing factor (default: 1.0); omega = 1 gives the Lorentzian, cauchy with sigma / 2 and a large omega approaches gaussian
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance.

See also cauchy, gaussian.

Creates the Pearson VII kernel (PUK) `1 / (1 + (2 d sqrt(2^(1/omega) - 1) / sigma)^2)^omega`, where `d` is the distance of the points.

The scale is chosen so that `sigma` is the full width at half maximum of the peak for every `omega`: the kernel is `1/2` at `d = sigma / 2`. This is the form of Ustun et al. (2006) and of the PUK kernel in Weka.

Parameters:

- `:sigma` - width of the peak (default: `1.0`)
- `:omega` - tailing factor (default: `1.0`); `omega = 1` gives the Lorentzian, [[cauchy]] with `sigma / 2` and a large `omega` approaches [[gaussian]]
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance.

See also [[cauchy]], [[gaussian]].
raw docstring

periodicclj

(periodic)
(periodic {:keys [sigma periodicity distance]
           :or {sigma 1.0 periodicity 1.0 distance v/dist}})

Creates the periodic kernel exp(-2 sin^2(pi d / periodicity) / sigma^2), where d is the distance of the points.

Parameters:

  • :sigma - scale (default: 1.0)
  • :periodicity - period (default: 1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1 and K = 1 at every distance which is a multiple of the period. The kernel is positive definite for one dimensional input; for vectors of higher dimension the euclidean distance gives a kernel which is not positive definite (Gram matrices with negative eigenvalues exist). Equal to the scikit-learn ExpSineSquared kernel with length_scale = sigma.

See also gaussian, wave.

Creates the periodic kernel `exp(-2 sin^2(pi d / periodicity) / sigma^2)`, where `d` is the distance of the points.

Parameters:

- `:sigma` - scale (default: `1.0`)
- `:periodicity` - period (default: `1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1 and K = 1 at every distance which is a multiple of the period. The kernel is positive definite for one dimensional input; for vectors of higher dimension the euclidean distance gives a kernel which is not positive definite (Gram matrices with negative eigenvalues exist). Equal to the scikit-learn ExpSineSquared kernel with `length_scale = sigma`.

See also [[gaussian]], [[wave]].
raw docstring

polynomialclj

(polynomial)
(polynomial {:keys [alpha c p] :or {alpha 1.0 c 0.0 p 2.0}})

Creates the polynomial kernel, a power of the shifted and scaled dot product: (c + alpha <x, y>)^p.

Parameters:

  • :alpha - dot product multiplier (default: 1.0)
  • :c - shift (default: 0.0)
  • :p - exponent (default: 2.0)

Returns a function (fn [x y]) returning a double. Without arguments the kernel is <x, y>^2. The kernel is positive definite for a positive integer :p, alpha >= 0 and c >= 0; a non-integer :p gives NaN for a negative base and no guarantee of positive definiteness. Corresponds to the polynomial kernel of scikit-learn with gamma = alpha, coef0 = c and degree = p.

See also linear, hyperbolic-tangent.

Creates the polynomial kernel, a power of the shifted and scaled dot product: `(c + alpha <x, y>)^p`.

Parameters:

- `:alpha` - dot product multiplier (default: `1.0`)
- `:c` - shift (default: `0.0`)
- `:p` - exponent (default: `2.0`)

Returns a function `(fn [x y])` returning a double. Without arguments the kernel is `<x, y>^2`. The kernel is positive definite for a positive integer `:p`, `alpha >= 0` and `c >= 0`; a non-integer `:p` gives `NaN` for a negative base and no guarantee of positive definiteness. Corresponds to the polynomial kernel of scikit-learn with `gamma = alpha`, `coef0 = c` and `degree = p`.

See also [[linear]], [[hyperbolic-tangent]].
raw docstring

powerclj

(power)
(power {:keys [p distance] :or {p 2.0 distance v/dist}})

Creates the power kernel, the negative power of the distance -d^p.

Parameters:

  • :p - exponent (default: 2.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double; K(x, x) = -0.0 for a positive p. The kernel is conditionally positive definite for 0 < p <= 2 and is not positive definite.

See also log, generalized-t-student.

Creates the power kernel, the negative power of the distance `-d^p`.

Parameters:

- `:p` - exponent (default: `2.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double; K(x, x) = `-0.0` for a positive `p`. The kernel is conditionally positive definite for `0 < p <= 2` and is not positive definite.

See also [[log]], [[generalized-t-student]].
raw docstring

rational-quadraticclj

(rational-quadratic)
(rational-quadratic {:keys [c distance] :or {c 1.0 distance v/dist}})

Creates the rational quadratic kernel 1 - d^2 / (d^2 + c), which equals c / (d^2 + c).

Parameters:

  • :c - shift (default: 1.0); it is a squared distance, compare multiquadratic where c is a distance
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in (0, 1]; K(x, x) = 1. The kernel is positive definite for a euclidean distance. Equal to cauchy with sigma = sqrt(c) and to the scikit-learn RationalQuadratic kernel with alpha = 1 and length_scale = sqrt(c / 2).

See also cauchy, multiquadratic, inverse-multiquadratic.

Creates the rational quadratic kernel `1 - d^2 / (d^2 + c)`, which equals `c / (d^2 + c)`.

Parameters:

- `:c` - shift (default: `1.0`); it is a squared distance, compare [[multiquadratic]] where `c` is a distance
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `(0, 1]`; K(x, x) = 1. The kernel is positive definite for a euclidean distance. Equal to [[cauchy]] with `sigma = sqrt(c)` and to the scikit-learn RationalQuadratic kernel with `alpha = 1` and `length_scale = sqrt(c / 2)`.

See also [[cauchy]], [[multiquadratic]], [[inverse-multiquadratic]].
raw docstring

rbf->kernelclj

(rbf->kernel rbf-kernel)
(rbf->kernel rbf-kernel distance)

Converts a radial basis function into a vector kernel using a distance function.

Parameters:

  • rbf-kernel - a function of one double (the distance), for example created by fastmath.kernel/rbf
  • distance (optional) - distance function of two points (default: euclidean)

Returns a function (fn [x y]) which applies rbf-kernel to the distance of x and y.

See also gaussian, matern.

Converts a radial basis function into a vector kernel using a distance function.

Parameters:

- `rbf-kernel` - a function of one double (the distance), for example created by `fastmath.kernel/rbf`
- `distance` (optional) - distance function of two points (default: euclidean)

Returns a function `(fn [x y])` which applies `rbf-kernel` to the distance of `x` and `y`.

See also [[gaussian]], [[matern]].
raw docstring

splineclj

(spline)
(spline _)

Creates the spline kernel, a product over the components of 1 + x y + x y min(x, y) - (x + y) min(x, y)^2 / 2 + min(x, y)^3 / 3.

Parameters:

  • params (optional) - ignored, accepted for a uniform signature.

Returns a function (fn [x y]) returning a double. The components are expected to be non-negative. The kernel is positive definite on non-negative input and equals the splinedot kernel of the R package kernlab.

See also b-spline.

Creates the spline kernel, a product over the components of `1 + x y + x y min(x, y) - (x + y) min(x, y)^2 / 2 + min(x, y)^3 / 3`.

Parameters:

- `params` (optional) - ignored, accepted for a uniform signature.

Returns a function `(fn [x y])` returning a double. The components are expected to be non-negative. The kernel is positive definite on non-negative input and equals the splinedot kernel of the R package kernlab.

See also [[b-spline]].
raw docstring

waveclj

(wave)
(wave {:keys [sigma distance] :or {sigma 1.0 distance v/dist}})

Creates the wave (sinc) kernel (sigma / d) sin(d / sigma), where d is the distance of the points.

Parameters:

  • :sigma - scale (default: 1.0)
  • :distance - distance function (default: euclidean)

Returns a function (fn [x y]) returning a double in [-0.22, 1]; K(x, x) = 1. The kernel is positive definite in the euclidean space of dimension 3 and lower only; in higher dimensions Gram matrices with negative eigenvalues exist.

See also periodic, bessel2.

Creates the wave (sinc) kernel `(sigma / d) sin(d / sigma)`, where `d` is the distance of the points.

Parameters:

- `:sigma` - scale (default: `1.0`)
- `:distance` - distance function (default: euclidean)

Returns a function `(fn [x y])` returning a double in `[-0.22, 1]`; K(x, x) = 1. The kernel is positive definite in the euclidean space of dimension 3 and lower only; in higher dimensions Gram matrices with negative eigenvalues exist.

See also [[periodic]], [[bessel2]].
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close