Skip to content

Commit 7fb9ae3

Browse files
committed
Pretty print Global Optimizer state
1 parent 9c40e54 commit 7fb9ae3

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
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.33"
15+
val mainVersion = "v1.4-beta.34"
1616

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

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,18 @@ class TStudentCovFunc(private var d: Double) extends LocalSVMKernel[Double] {
4949

5050
override def evaluate(x: Double, y: Double): Double =
5151
1.0/(1.0 + math.pow(math.abs(x-y), state("d")))
52-
}
52+
}
53+
54+
class CoRegTStudentKernel(bandwidth: Double) extends LocalSVMKernel[Int] {
55+
56+
override val hyper_parameters: List[String] = List("d")
57+
58+
state = Map("d" -> bandwidth)
59+
60+
override def evaluate(x: Int, y: Int): Double = {
61+
val diff = x - y
62+
1.0/(1.0 + math.pow(math.abs(diff.toDouble), state("d")))
63+
}
64+
65+
def getD: Double = state("d")
66+
}

dynaml-core/src/main/scala-2.11/io/github/mandar2812/dynaml/optimization/CoupledSimulatedAnnealing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CoupledSimulatedAnnealing[M <: GloballyOptimizable](model: M)
6060
CoupledSimulatedAnnealing.acceptanceProbability(variant)(energy, oldEnergy, coupling, temperature)
6161

6262
protected val mutate = (config: Map[String, Double], temperature: Double) => {
63-
logger.info("Mutating configuration: "+config)
63+
logger.info("Mutating configuration: "+GlobalOptimizer.prettyPrint(config))
6464
config.map((param) => {
6565
val dist = new CauchyDistribution(0.0, temperature)
6666
val mutated = param._2 + dist.sample()

dynaml-core/src/main/scala-2.11/io/github/mandar2812/dynaml/optimization/GlobalOptimizer.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ trait GlobalOptimizer[T <: GloballyOptimizable] {
7777

7878
grid.map((config) => {
7979
val configMap = List.tabulate(config.length){i => (hyper_params(i), config(i))}.toMap
80-
logger.info("Evaluating Configuration: "+configMap)
80+
logger.info("""Evaluating Configuration: """+GlobalOptimizer.prettyPrint(configMap))
8181

8282
val configEnergy = system.energy(configMap, options)
8383

@@ -92,3 +92,10 @@ trait GlobalOptimizer[T <: GloballyOptimizable] {
9292
options: Map[String, String] = Map()): (T, Map[String, Double])
9393

9494
}
95+
96+
object GlobalOptimizer {
97+
98+
def prettyPrint(configuration: Map[String, Double]): String = configuration.foldLeft("""""")(
99+
(str, mapping) => str+""" """+mapping._1+""" = """+mapping._2.toString)
100+
101+
}

0 commit comments

Comments
 (0)