Skip to content

Commit 8d34ce9

Browse files
committed
Modifed :*: operator for kernels and random variables to :*
1 parent ff19018 commit 8d34ce9

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ packageDescription := "DynaML is a scala library/repl for implementing and worki
1212
"which can be extended easily to implement advanced models for small and large scale applications.\n\n"+
1313
"But the library can also be used as an educational/research tool for data analysis."
1414

15-
val mainVersion = "v1.4-beta.27"
15+
val mainVersion = "v1.4-beta.28"
1616

1717
val dataDirectory = settingKey[File]("The directory holding the data files for running example scripts")
1818

dynaml-core/scripts/probModels.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import spire.implicits._
99
val n = RandomVariable(Gaussian(0.0, 0.25))
1010
val n1 = RandomVariable(Laplace(0.0, 0.25))
1111

12-
val combinedDist = n :*: n1
12+
val combinedDist = n :* n1
1313

1414
val cond2 = DataPipe((xy: (Double, Double)) => RandomVariable(new Gumbel(0.4*xy._1 + 0.6*xy._2, math.sin(xy._1+xy._2)/2.0)))
1515

1616
val mod = ProbabilityModel(combinedDist, cond2)
1717

18-
val combinedDist2 = n1 :*: n
18+
val combinedDist2 = n1 :* n
1919

2020
val mod1 = ProbabilityModel(combinedDist2, cond2)
2121

@@ -43,7 +43,7 @@ val priorMean = RandomVariable(new Gaussian(0.0, 1.0))
4343

4444
val priorSigma = RandomVariable(new Gamma(7.5, 1.0))
4545

46-
val prior = priorSigma :*: priorMean
46+
val prior = priorMean :* priorSigma
4747

4848
val iidPrior = IIDRandomVarDistr(prior) _
4949

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ class MAKernel(private var noiseLevel: Double = 1.0)
6363
: KernelMatrix[DenseMatrix[Double]] =
6464
new SVMKernelMatrix(DenseMatrix.eye[Double](length)*state("noiseLevel"), length)
6565

66-
}
66+
}
67+
68+
class CoRegDiracKernel extends LocalSVMKernel[Int] {
69+
override val hyper_parameters: List[String] = List()
70+
71+
override def gradient(x: Int, y: Int): Map[String, Double] = Map()
72+
73+
override def evaluate(x: Int, y: Int): Double = if(x == y) 1.0 else 0.0
74+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ CovarianceFunction[Index, Double, DenseMatrix[Double]] {
177177
}
178178
}
179179

180-
def :*:[T1](otherKernel: LocalScalarKernel[T1]): CompositeCovariance[(Index, T1)] = {
180+
def :*[T1](otherKernel: LocalScalarKernel[T1]): CompositeCovariance[(Index, T1)] = {
181181

182182
val firstkernel = this
183183

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,17 @@ class SECovFunc(private var band: Double = 1.0, private var h: Double = 2.0)
195195
Map("amplitude" -> 2.0*state("amplitude")*super.evaluate(x,y)) ++ super.gradient(x,y)
196196

197197
}
198+
199+
class CoRegRBFKernel(bandwidth: Double) extends LocalSVMKernel[Int] {
200+
201+
override val hyper_parameters: List[String] = List("coRegB")
202+
203+
state = Map("coRegB" -> bandwidth)
204+
205+
override def gradient(x: Int, y: Int): Map[String, Double] =
206+
Map("coRegB" -> 1.0*evaluate(x,y)*math.pow(x-y,2)/math.pow(math.abs(state("coRegB")), 3))
207+
208+
override def evaluate(x: Int, y: Int): Double = {
209+
math.exp(-1.0*math.pow(x-y, 2.0)/state("coRegB"))
210+
}
211+
}

dynaml-core/src/main/scala-2.11/io/github/mandar2812/dynaml/probability/RandomVariable.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class RandomVariable[Domain] {
3636
* component of the cartesian product.
3737
*
3838
* */
39-
def :*:[Domain1](other: RandomVariable[Domain1]): RandomVariable[(Domain, Domain1)] = {
39+
def :*[Domain1](other: RandomVariable[Domain1]): RandomVariable[(Domain, Domain1)] = {
4040
val sam = this.sample
4141
RandomVariable(BifurcationPipe(sam,other.sample))
4242
}
@@ -163,7 +163,7 @@ trait RandomVarWithDistr[Domain, Dist <: Density[Domain]]
163163

164164
override val underlyingDist: Dist
165165

166-
def :*:[Domain1, Dist1 <: Density[Domain1]](other: RandomVarWithDistr[Domain1, Dist1]):
166+
def :*[Domain1, Dist1 <: Density[Domain1]](other: RandomVarWithDistr[Domain1, Dist1]):
167167
RandomVarWithDistr[(Domain, Domain1), Density[(Domain, Domain1)]] = {
168168
val sam = this.sample
169169
val dist = this.underlyingDist
@@ -190,7 +190,7 @@ abstract class ContinuousDistrRV[Domain](implicit ev: Field[Domain])
190190

191191
override val sample = DataPipe(() => underlyingDist.sample())
192192

193-
def :*:[Domain1](other: ContinuousDistrRV[Domain1])(implicit ev1: Field[Domain1])
193+
def :*[Domain1](other: ContinuousDistrRV[Domain1])(implicit ev1: Field[Domain1])
194194
: ContinuousDistrRV[(Domain, Domain1)] = {
195195
val sam = this.underlyingDist.draw _
196196
val dist = this.underlyingDist
@@ -225,7 +225,7 @@ abstract class DiscreteDistrRV[Domain]
225225

226226
override val sample = DataPipe(() => underlyingDist.sample())
227227

228-
def :*:[Domain1](other: DiscreteDistrRV[Domain1]): DiscreteDistrRV[(Domain, Domain1)] = {
228+
def :*[Domain1](other: DiscreteDistrRV[Domain1]): DiscreteDistrRV[(Domain, Domain1)] = {
229229

230230
val dist = this.underlyingDist
231231
val sam = this.underlyingDist.draw _

0 commit comments

Comments
 (0)