Skip to content

Commit 95ebe6f

Browse files
committed
Minor clean up to mcmc example script
1 parent 83fc0cf commit 95ebe6f

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import breeze.stats.mcmc.BaseMetropolisHastings
66
import io.github.mandar2812.dynaml.probability.LikelihoodModel
77

88
/**
9-
* Created by mandar on 06/01/2017.
10-
*/
9+
* @author mandar2812 date 06/01/2017.
10+
* */
1111
case class GeneralMetropolisHastings[T](
1212
logLikelihoodF: LikelihoodModel[T], proposalStep: ContinuousDistr[T],
1313
init: T, burnIn: Long = 0, dropCount: Int = 0)(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Distr <: ContinuousDistr[Double]](
2020

2121
val encoder: ConfigEncoding = ConfigEncoding(hyper_prior.keys.toList)
2222

23-
implicit val vector_field = VectorField(hyper_prior.size)
23+
implicit private val vector_field = VectorField(hyper_prior.size)
2424

25-
val processed_prior = EncodedContDistrRV(getPriorMapDistr(hyper_prior), encoder)
25+
private val processed_prior = EncodedContDistrRV(getPriorMapDistr(hyper_prior), encoder)
2626

2727
private val logLikelihoodFunction = (candidate: DenseVector[Double]) => {
2828
processed_prior.underlyingDist.logPdf(candidate) - system.energy(encoder.i(candidate))

scripts/gp_mcmc_santafe.sc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import breeze.linalg.{DenseMatrix, DenseVector}
22
import breeze.stats.distributions.{ContinuousDistr, Gamma}
33
import io.github.mandar2812.dynaml.DynaMLPipe._
44
import io.github.mandar2812.dynaml.analysis.VectorField
5-
import io.github.mandar2812.dynaml.kernels.{DiracKernel, SEKernel}
5+
import io.github.mandar2812.dynaml.kernels.{DiracKernel, LaplacianKernel, SEKernel}
66
import io.github.mandar2812.dynaml.modelpipe.GPRegressionPipe
77
import io.github.mandar2812.dynaml.pipes.{DataPipe, StreamDataPipe}
88
import io.github.mandar2812.dynaml.probability.MultGaussianRV
@@ -19,6 +19,7 @@ type Data = Stream[(Features, Features)]
1919
implicit val f = VectorField(deltaT)
2020

2121
val kernel = new SEKernel(1.5, 1.5)
22+
val kernel2 = new LaplacianKernel(2.0)
2223
val noise_kernel = new DiracKernel(1.0)
2324

2425
val data_size = 500
@@ -42,7 +43,7 @@ val prepare_data = {
4243

4344
val create_gp_model = GPRegressionPipe(
4445
(d: Data) => d.toSeq.map(p => (p._1, p._2(0))),
45-
kernel, noise_kernel
46+
kernel2, noise_kernel
4647
)
4748

4849
val model_flow = DataPipe(create_gp_model, scales_flow_stub)
@@ -52,15 +53,21 @@ val workflow = prepare_data > model_flow
5253
val (model, scales) = workflow("data/santafelaser.csv")
5354

5455
val num_hyp = model._hyper_parameters.length
55-
val proposal = MultGaussianRV(num_hyp)(DenseVector.zeros[Double](num_hyp), DenseMatrix.eye[Double](num_hyp))
56+
57+
val proposal = MultGaussianRV(
58+
num_hyp)(
59+
DenseVector.zeros[Double](num_hyp),
60+
DenseMatrix.eye[Double](num_hyp)*0.001)
5661

5762
val mcmc = HyperParameterMCMC[model.type, ContinuousDistr[Double]](
58-
model, model._hyper_parameters.map(h => (h, new Gamma(1.0, 1.0))).toMap,
63+
model, model._hyper_parameters.map(h => (h, new Gamma(1.0, 2.0))).toMap,
5964
proposal)
6065

61-
val samples = mcmc.iid(500).draw
66+
mcmc.burnIn = 50
67+
68+
val samples = mcmc.iid(1000).draw
6269

63-
val samples_se = samples.map(h => (h("bandwidth"), h("amplitude")))
70+
val samples_se = samples.map(h => (h("beta"), h("noiseLevel")))
6471

6572
scatter(samples_se)
6673
title("x,y ~ P(sigma, a | Data)")

0 commit comments

Comments
 (0)