Skip to content

Commit aef0f81

Browse files
committed
Added to kernel pages
1 parent 6af760c commit aef0f81

File tree

9 files changed

+85
-12
lines changed

9 files changed

+85
-12
lines changed

docs/core/core_kernel_stat.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
title: Stationary Kernels
3-
---
4-
51
Stationary kernels can be expressed as a function of the difference between their inputs.
62

73
$$
@@ -48,6 +44,25 @@ $$
4844
val rbf = new SEKernel(4.0, 2.0)
4945
```
5046

47+
### Mahalanobis Kernel
48+
49+
This kernel is a further generalization of the SE kernel. It uses the [Mahalanobis distance](https://en.wikipedia.org/wiki/Mahalanobis_distance) instead of the Euclidean distance between the inputs.
50+
51+
$$
52+
C(\mathbf{x},\mathbf{y}) = h \ exp\left(-\frac{1}{2}(\mathbf{x}-\mathbf{y})^\intercal \Sigma^{-1} (\mathbf{x}-\mathbf{y})\right)
53+
$$
54+
55+
The Mahalanobis distance $(\mathbf{x}-\mathbf{y})^\intercal \Sigma^{-1} (\mathbf{x}-\mathbf{y})$ is characterized by a symmetric positive definite matrix $\Sigma$. This distance metric reduces to the Euclidean distance if $\Sigma$ is the _identity matrix_. Further, if $\Sigma$ is diagonal, the _Mahalanobis kernel_ becomes the _Automatic Relevance Determination_ version of the SE kernel (SE-ARD).
56+
57+
In DynaML the class `#!scala MahalanobisKernel` implements the SE-ARD kernel with diagonal $\Sigma$.
58+
59+
```scala
60+
val bandwidths: DenseVector[Double] = _
61+
val amp = 1.5
62+
63+
val maha_kernel = new MahalanobisKernel(bandwidths, amp)
64+
```
65+
5166
## Student T Kernel
5267

5368
$$
@@ -147,6 +162,16 @@ $$
147162
val periodic_kernel = new PeriodicKernel(lengthscale = 1.5, freq = 2.5)
148163
```
149164

165+
## Wave Kernel
166+
167+
$$
168+
C(\mathbf{x},\mathbf{y}) = \frac{\theta}{||\mathbf{x} - \mathbf{y}||^2} \times sin(\frac{||\mathbf{x} - \mathbf{y}||^2}{\theta})
169+
$$
170+
171+
```scala
172+
val wv_kernel = WaveKernel(th = 1.0)
173+
```
174+
150175
## Laplacian Kernel
151176

152177
The Laplacian kernel is the covariance function of the well known [Ornstein Ulhenbeck process](https://en.wikipedia.org/wiki/Ornstein%E2%80%93Uhlenbeck_process), samples drawn from this process are continuous and only once differentiable.

docs/core/core_kernels.md

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
---
2-
title: Kernels
3-
---
1+
!!! summary ""
42

3+
The [`dynaml.kernels`](https://transcendent-ai-labs.github.io/api_docs/DynaML/recent/dynaml-core/#io.github.mandar2812.dynaml.kernels.package) package has a highly developed API for creating kernel functions for machine learning applications. Here
4+
we give the user an in-depth introduction to its capabilities.
5+
6+
<br/>
57

68
![kernel](/images/kernel.png)
79

@@ -108,8 +110,6 @@ val kernel = CovarianceFunction(mapFunc)(
108110

109111
In machine learning it is well known that kernels can be combined to give other valid kernels. The symmetric positive semi-definite property of a kernel is preserved as long as it is added or multiplied to another valid kernel. In DynaML adding and multiplying kernels is elementary.
110112

111-
112-
113113
```scala
114114

115115
val k1 = new RBFKernel(2.5)
@@ -156,7 +156,45 @@ val kernel: LocalScalarKernel[I] = _
156156

157157
val scalingFunction: (I) => Double = _
158158

159-
val scKernel = ScaledKernel(kernel, DataPipe(scalingFunction))
159+
val scKernel = ScaledKernel(
160+
kernel, DataPipe(scalingFunction))
161+
```
162+
163+
### Advanced Composite Kernels
164+
165+
Sometimes we would like to express a kernel function as a product (or sum) of component kernels each of which act on
166+
a sub-set of the dimensions (degree of freedom) of the input attributes.
167+
168+
For example; for 4 dimensional input vector, we may define two component kernels acting on the first two and
169+
last two dimensions respectively and combine their evaluations via addition or multiplication. For this purpose the
170+
[`dynaml.kernels`](https://transcendent-ai-labs.github.io/api_docs/DynaML/recent/dynaml-core/#io.github.mandar2812.dynaml.kernels.package) package has the [`#!scala DecomposableCovariance[S]`](https://transcendent-ai-labs.github.io/api_docs/DynaML/recent/dynaml-core/#io.github.mandar2812.dynaml.kernels.DecomposableCovariance) class.
171+
172+
173+
In order to create a decomposable kernel you need three components.
174+
175+
1. The component kernels (order matters)
176+
2. An [`#!scala Encoder[S, Array[S]]`](https://transcendent-ai-labs.github.io/api_docs/DynaML/recent/dynaml-pipes/#io.github.mandar2812.dynaml.pipes.Encoder) instance which splits the input into an array of components
177+
3. A [`#!scala Reducer`](https://transcendent-ai-labs.github.io/api_docs/DynaML/recent/dynaml-pipes/#io.github.mandar2812.dynaml.pipes.Reducer$) which combines the individual kernel evaluations.
178+
179+
```scala
180+
//Not required in REPL, already imported
181+
import io.github.mandar2812.dynaml.DynaMLPipe._
182+
import io.github.mandar2812.dynaml.pipes._
183+
184+
val kernel1: LocalScalarKernel[DenseVector[Double]] = _
185+
val kernel2: LocalScalarKernel[DenseVector[Double]] = _
186+
187+
//Default Reducer is addition
188+
val decomp_kernel =
189+
new DecomposableCovariance[DenseVector[Double]](
190+
kernel1, kernel2)(
191+
breezeDVSplitEncoder(2))
192+
193+
val decomp_kernel_mult =
194+
new DecomposableCovariance[DenseVector[Double]](
195+
kernel1, kernel2)(
196+
breezeDVSplitEncoder(2),
197+
Reducer.:*:)
160198
```
161199

162200
-----

docs/core/core_prob_operations.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ histogram((1 to 1000).map(_ => multR.sample()))
2828
In many cases random variables can be expressed as functions of one another, for example chi square random variables are obtained by squaring normally distributed samples.
2929

3030
```scala
31-
val chsq = MeasurableFunction(n)(DataPipe((x: Double) => x*x))
31+
val chsq = MeasurableFunction(n, DataPipe((x: Double) => x*x))
3232

3333
//Generate a chi square distribution with one degree of freedom
3434
histogram((1 to 1000).map(_ => chsq.sample()))
3535
```
3636

3737
![histogram](/images/histogram-ch.png)
38+
39+
## Push-forward Maps
40+
41+
![pushforward](/images/randomVar.gif)

docs/images/randomVar.gif

1.58 MB
Loading

docs/scaladoc/v1.4.1/examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<meta http-equiv="REFRESH" content="0;url=https://transcendent-ai-labs.github.io/api_docs/DynaML/v1.4.1/dynaml-examples/"></HEAD>

docs/scaladoc/v1.4.2/examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<meta http-equiv="REFRESH" content="0;url=https://transcendent-ai-labs.github.io/api_docs/DynaML/v1.4.2/dynaml-examples/"></HEAD>

docs/scaladoc/v1.4/examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<meta http-equiv="REFRESH" content="0;url=https://transcendent-ai-labs.github.io/api_docs/DynaML/v1.4/dynaml-examples/"></HEAD>

docs/utils/utils_data_transforms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!!! summary
2-
Some attribute transformations are included in the DynaML distribution, here we show how to use them. All of them inherit `#!scala ReversibleScaler[I]` trait. They are contained in the `dynml.utils` package.
2+
Some attribute transformations are included in the DynaML distribution, here we show how to use them. All of them inherit [`#!scala ReversibleScaler[I]`](https://transcendent-ai-labs.github.io/api_docs/DynaML/recent/dynaml-pipes/#io.github.mandar2812.dynaml.pipes.ReversibleScaler) trait. They are contained in the [`dynml.utils`](https://transcendent-ai-labs.github.io/api_docs/DynaML/recent/dynaml-core/#io.github.mandar2812.dynaml.utils.package) package.
33

44

55
## Gaussian Centering

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ pages:
1919
- v1.4.2:
2020
- dynaml-core: 'scaladoc/v1.4.2/core.md'
2121
- dynaml-pipes: 'scaladoc/v1.4.2/pipes.md'
22+
- dynaml-examples: 'scaladoc/v1.4.2/examples.md'
2223
- v1.4.1:
2324
- dynaml-core: 'scaladoc/v1.4.1/core.md'
2425
- dynaml-pipes: 'scaladoc/v1.4.1/pipes.md'
26+
- dynaml-examples: 'scaladoc/v1.4.1/examples.md'
2527
- v1.4:
2628
- dynaml-core: 'scaladoc/v1.4/core.md'
2729
- dynaml-pipes: 'scaladoc/v1.4/pipes.md'
30+
- dynaml-examples: 'scaladoc/v1.4/examples.md'
2831
- 'User Guide':
2932
- 'Core':
3033
- Models:

0 commit comments

Comments
 (0)