|
1 | | ---- |
2 | | -title: Kernels |
3 | | ---- |
| 1 | +!!! summary "" |
4 | 2 |
|
| 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/> |
5 | 7 |
|
6 | 8 |  |
7 | 9 |
|
@@ -108,8 +110,6 @@ val kernel = CovarianceFunction(mapFunc)( |
108 | 110 |
|
109 | 111 | 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. |
110 | 112 |
|
111 | | - |
112 | | - |
113 | 113 | ```scala |
114 | 114 |
|
115 | 115 | val k1 = new RBFKernel(2.5) |
@@ -156,7 +156,45 @@ val kernel: LocalScalarKernel[I] = _ |
156 | 156 |
|
157 | 157 | val scalingFunction: (I) => Double = _ |
158 | 158 |
|
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.:*:) |
160 | 198 | ``` |
161 | 199 |
|
162 | 200 | ----- |
|
0 commit comments