Skip to content

Commit 6113707

Browse files
committed
Improved implicit paramterization of Matern Covariance classes
1 parent f6adc1f commit 6113707

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

dynaml-core/src/main/scala-2.11/io/github/mandar2812/dynaml/kernels/GenericMaternKernel.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import spire.algebra.{Field, InnerProductSpace}
77
import io.github.mandar2812.dynaml.utils._
88

99
/**
10-
* @author mandar2812 date: 27/01/2017.
11-
*
1210
* Implementation of the half integer Matern
1311
* covariance function
14-
*/
12+
*
13+
* @author mandar2812 date: 27/01/2017.
14+
*
15+
*
16+
* */
1517
class GenericMaternKernel[T](private var l: Double, p: Int = 2)(
16-
implicit ev: Field[T] with InnerProductSpace[T, Double])
18+
implicit evInner: InnerProductSpace[T, Double], evField: Field[T])
1719
extends StationaryKernel[T, Double, DenseMatrix[Double]]
1820
with LocalScalarKernel[T] with Serializable { self =>
1921

@@ -31,7 +33,7 @@ class GenericMaternKernel[T](private var l: Double, p: Int = 2)(
3133
}
3234

3335
override def evalAt(config: Map[String, Double])(x: T) = {
34-
val r = math.sqrt(ev.dot(x, x))
36+
val r = math.sqrt(evInner.dot(x, x))
3537
val nu = config("p") + 0.5
3638
val lengthscale = config("l")
3739
val order = config("p").toInt
@@ -47,8 +49,8 @@ class GenericMaternKernel[T](private var l: Double, p: Int = 2)(
4749

4850
override def gradientAt(config: Map[String, Double])(x: T, y: T) = {
4951

50-
val diff = ev.minus(x, y)
51-
val r = math.sqrt(ev.dot(diff, diff))
52+
val diff = evField.minus(x, y)
53+
val r = math.sqrt(evInner.dot(diff, diff))
5254

5355
val nu = config("p") + 0.5
5456
val lengthscale = config("l")
@@ -77,13 +79,15 @@ class GenericMaternKernel[T](private var l: Double, p: Int = 2)(
7779
}
7880

7981
/**
80-
* @author mandar2812 date: 27/01/2017.
81-
*
8282
* Implementation of the half integer Matern-ARD
8383
* covariance function
84-
*/
84+
*
85+
* @author mandar2812 date: 27/01/2017.
86+
*
87+
*
88+
* */
8589
abstract class GenericMaternARDKernel[T](private var l: T, private var p: Int = 3)(
86-
implicit ev: Field[T] with InnerProductSpace[T, Double])
90+
implicit evInner: InnerProductSpace[T, Double], evField: Field[T])
8791
extends StationaryKernel[T, Double, DenseMatrix[Double]]
8892
with LocalScalarKernel[T] with Serializable { self =>
8993

0 commit comments

Comments
 (0)