Skip to content

Commit f3774d9

Browse files
committed
Added types to methods of ModelTuner hierarchy
- Configuration methods now return `this.type`
1 parent 0deabc5 commit f3774d9

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ import scala.util.Random
2626

2727
/**
2828
* Skeleton implementation of the Coupled Simulated Annealing algorithm
29-
* @author mandar datum 01/12/15.
30-
*/
29+
* @author mandar2812 date 01/12/15.
30+
* */
3131
abstract class AbstractCSA[M <: GloballyOptimizable, M1](model: M)
3232
extends AbstractGridSearch[M, M1](model: M) {
3333

3434
protected var MAX_ITERATIONS: Int = 10
3535

3636
protected var variant = AbstractCSA.MuSA
3737

38-
def setVariant(v: String) = {
38+
def setVariant(v: String): this.type = {
3939
variant = v
4040
this
4141
}
4242

43-
def setMaxIterations(m: Int) = {
43+
def setMaxIterations(m: Int): this.type = {
4444
MAX_ITERATIONS = m
4545
this
4646
}
@@ -116,7 +116,7 @@ abstract class AbstractCSA[M <: GloballyOptimizable, M1](model: M)
116116
def CSATRec(eLandscape: List[(Double, Map[String, Double])], it: Int): List[(Double, Map[String, Double])] =
117117
it match {
118118
case 0 => eLandscape
119-
case num =>
119+
case _ =>
120120
logger.info("**************************")
121121
logger.info("CSA Iteration: "+(MAX_ITERATIONS-it+1))
122122
//mutate each element of the grid with

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ BaseProcess <: ContinuousProcessModel[T, I, Y, W1]
6565
this
6666
}
6767

68-
protected def calculateEnergyLandscape(initialConfig: Map[String, Double], options: Map[String, String]) =
68+
protected def calculateEnergyLandscape(
69+
initialConfig: Map[String, Double],
70+
options: Map[String, String]): Seq[(Double, Map[String, Double])] =
6971
if(policy == "CSA") performCSA(initialConfig, options)
7072
else getEnergyLandscape(initialConfig, options, meanFieldPrior)
7173

72-
protected def modelProbabilities = DataPipe(ProbGPCommMachine.calculateModelWeightsSigmoid(baselinePolicy) _)
74+
protected def modelProbabilities: DataPipe[Seq[(Double, Map[String, Double])], Seq[(Double, Map[String, Double])]] =
75+
DataPipe(ProbGPCommMachine.calculateModelWeightsSigmoid(baselinePolicy))
7376

7477
override def optimize(
7578
initialConfig: Map[String, Double],

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,27 @@ trait ModelTuner[T <: GloballyOptimizable, T1] {
4444

4545
protected var meanFieldPrior: Map[String, ContinuousRVWithDistr[Double, ContinuousDistr[Double]]] = Map()
4646

47-
def setPrior(p: Map[String, ContinuousRVWithDistr[Double, ContinuousDistr[Double]]]) = {
47+
def setPrior(p: Map[String, ContinuousRVWithDistr[Double, ContinuousDistr[Double]]]): this.type = {
4848
meanFieldPrior = p
4949
this
5050
}
5151

52-
def setNumSamples(n: Int) = {
52+
def setNumSamples(n: Int): this.type = {
5353
num_samples = n
5454
this
5555
}
5656

57-
def setLogScale(t: Boolean) = {
57+
def setLogScale(t: Boolean): this.type = {
5858
logarithmicScale = t
5959
this
6060
}
6161

62-
def setGridSize(s: Int) = {
62+
def setGridSize(s: Int): this.type = {
6363
this.gridsize = s
6464
this
6565
}
6666

67-
def setStepSize(s: Double) = {
67+
def setStepSize(s: Double): this.type = {
6868
this.step = s
6969
this
7070
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ object ProbGPCommMachine {
181181

182182
def calculateModelWeightsSigmoid(
183183
baselineMethod: String = "mean")(
184-
energyLandscape: List[(Double, Map[String, Double])])
184+
energyLandscape: Seq[(Double, Map[String, Double])])
185185
: Seq[(Double, Map[String, Double])] = {
186186

187187
val h = DenseVector(energyLandscape.map(_._1).toArray)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ class ProbGPMixtureMachine[T, I: ClassTag](
2222
MixtureMachine[T, I, Double, PartitionedVector, PartitionedPSDMatrix, BlockedMultiVariateGaussian,
2323
MultGaussianPRV, AbstractGPRegressionModel[T, I]](model) {
2424

25-
2625
val (kernelPipe, noisePipe) = (system.covariance.asPipe, system.noiseModel.asPipe)
2726

2827
def blockedHypParams = system.covariance.blocked_hyper_parameters ++ system.noiseModel.blocked_hyper_parameters
2928

3029
def blockedState = system._current_state.filterKeys(blockedHypParams.contains)
3130

32-
implicit val transform: DataPipe[T, Seq[(I, Double)]] = DataPipe(system.dataAsSeq _)
31+
implicit val transform: DataPipe[T, Seq[(I, Double)]] = DataPipe(system.dataAsSeq)
3332

3433
override val confToModel = DataPipe((model_state: Map[String, Double]) =>
3534
AbstractGPRegressionModel(
@@ -39,5 +38,5 @@ class ProbGPMixtureMachine[T, I: ClassTag](
3938
override val mixturePipe = DataPipe2(
4039
(models: Seq[AbstractGPRegressionModel[T, I]], weights: DenseVector[Double]) =>
4140
StochasticProcessMixtureModel[T, I](models, weights))
42-
41+
4342
}

scripts/stochasticPriors.sc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ val gsmKernel = GaussianSpectralKernel[Double](3.5, 2.0, encoder)
3333
val n = new MAKernel(0.8)
3434

3535
val gp_prior = new LinearTrendGaussianPrior[Double](gsmKernel, n, trendEncoder, 0.0, 0.0)
36-
//gp_prior.hyperPrior_(hyp_prior)
36+
gp_prior.hyperPrior_(hyp_prior)
3737

3838
val sgp_prior = new LinearTrendESGPrior[Double](rbfc, n, trendEncoder, 0.75, 0.1, 0.0, 0.0)
3939
sgp_prior.hyperPrior_(sgp_hyp_prior)
@@ -63,13 +63,9 @@ val sgpModel = sgp_prior.posteriorModel(dataset)
6363
gp_prior.globalOptConfig_(Map("gridStep" -> "0.0", "gridSize" -> "1", "globalOpt" -> "GS", "policy" -> "GS"))
6464
val gpModel1 = gp_prior.posteriorModel(dataset)
6565

66-
val mixt_machine = new ProbGPMixtureMachine(gpModel1)
67-
.setGridSize(2)
68-
.setStepSize(0.50)
69-
.setLogScale(true)
70-
.setMaxIterations(16)
66+
val mixt_machine = new ProbGPMixtureMachine(gpModel1).setPrior(hyp_prior).setGridSize(2).setStepSize(0.50).setLogScale(true).setMaxIterations(200).setNumSamples(3)
7167

72-
val (mix_model, mixt_model_conf) = mixt_machine.optimize(gp_prior.covariance.state ++ gp_prior.noiseCovariance.state)
68+
val (mix_model, mixt_model_conf) = mixt_machine.optimize(gp_prior.covariance.effective_state ++ gp_prior.noiseCovariance.effective_state)
7369

7470

7571
val zs: MultGaussianPRV = gpModel.predictiveDistribution(xs)

0 commit comments

Comments
 (0)