Instantly share code, notes, and snippets.

# jonnylaw

• Sort options
Last active Oct 9, 2017
What if the harrier league started from scratch
View harrier_league_actual.md

Harrier League Cross Country From Scratch The Harrier League is a cross country running league with seven fixtures across the North East of England in the 2017/18 season across the winter months from September ’17 until March ‘18.

The harrier league is unique to other cross country fixtures because the senior runners are divided up into slow, medium and fast packs. In the senior men’s race, the slow runners start first followed 2 minutes 30 seconds later by the medium pack runners, then a further 2 minutes 30

Created Jun 23, 2017
View RegressionDLM.R
 ##################################### # Simulate Data From Regression DLM # ##################################### regression_dlm = function(n = 6 * 24, psi, X) { theta = matrix(NA_real_, ncol = ncol(X), nrow = n) y = numeric(n) V = psi[1] W = diag(psi[2:3]) theta[1,] = rnorm(2)
Created Jun 23, 2017
View DescriptiveStats.scala
 import akka.stream.scaladsl._ import akka.actor.ActorSystem import akka.NotUsed import akka.stream._ import akka.util.ByteString import java.nio.file.Paths import scala.concurrent.Future object DescriptiveStats extends App {
Created Apr 24, 2017
View BreezeMCMC.scala
 package model import breeze.stats.distributions._ import breeze.linalg._ import breeze.numerics.exp import java.io.{File, PrintWriter} object GaussianModel { case class Parameters(mu: DenseVector[Double], sigma: Double) { override def toString = s"\${mu.data.mkString(", ")}, \$sigma"
Created Jan 5, 2017
View ErrorHandling.scala
 import cats.implicits._ import cats.data.OptionT object ErrorHandling { // Calculate the square root of a positive number or return an exception (which isn't obvious from the return type) def unsafe_sqrt(a: Double): Double = { if (a > 0) math.sqrt(a) else throw new Exception("Can't calculate square root of negative number") }
Last active Jul 18, 2016
View likelihood.scala
 type Likelihood = Double case class Observation(y: Int, x: DenseVector[Double]) def likelihood(data: Vector[Observation]): Parameters => Likelihood = p => { val ll = data. map{ y => Poisson(exp(p.dot(y.x))).logProbabilityOf(y.y) }. sum exp(ll) }
Last active Jul 18, 2016
View proposal.scala
 type Parameters = DenseVector[Double] def proposal(delta: Double): Parameters => Rand[Parameters] = p => { for { d <- Gaussian(0, delta) params = p mapValues (d + _) } yield params }
Created Jun 1, 2016
View MetropolisHastings.scala
 import breeze.stats.distributions.Gaussian import Stream._ import java.io.{PrintWriter, File} object MetropolisHastings { case class Parameter(mu: Double, sigma: Double) { override def toString = s"\$mu, \$sigma" } def sims(n: Int, params: Parameter): List[Double] = {
You can’t perform that action at this time.