Skip to content

Instantly share code, notes, and snippets.

@jtobin
jtobin / gist:3865601
Created Oct 10, 2012
Incorporating parallelism
View gist:3865601
import Control.Monad.Par
-- Using the Par monad
logRosenbrockDensity :: [Double] -> Double
logRosenbrockDensity [x0, x1] = runPar $ do
[a, b] <- sequence [new, new]
fork $ put a (-100*(x1 - (x0^2))^2 / 20)
fork $ put b (-0.05*(1-x0)^2)
[a', b'] <- sequence [get a, get b]
return $ a' + b'
@jtobin
jtobin / gist:3865828
Created Oct 10, 2012
Single-threaded Rosenbrock
View gist:3865828
logRosenbrockDensity :: [Double] -> Double
logRosenbrockDensity [x0, x1] = (-1)*(100*(x1 - (x0^2))^2 + (1 - x0)^2) / 20
@jtobin
jtobin / gist:3865854
Created Oct 10, 2012
Simple benchmark
View gist:3865854
$ time ./Rosenbrock 500 > trace.dat # using an ensemble containing 200 particles
(flat-mcmc) Rosenbrock density
20259 / 100000 (0.20259) proposals accepted
real 0m0.428s
user 0m0.367s
sys 0m0.016s
@jtobin
jtobin / gist:4028961
Created Nov 7, 2012
Stochastic partial differential equation
View gist:4028961
target :: [Double] -> Double
target xs = go 0 0 xs
where go t0 t1 [] = -0.5 * t0 / h - 0.5 * h * t1
go t0 t1 (u:us:uss) = go (t0 + (us - u)^2) (t1 + v (us + u)) uss
h = 1 / fromIntegral (length xs)
v x = (1 - x^2)^2
@jtobin
jtobin / gist:4029005
Created Nov 7, 2012
SPDE parallel run
View gist:4029005
./SPDE 1000000 1000 +RTS -N4 -qg > trace.dat
MUT time 4723.78s (1620.24s elapsed)
GC time 623.24s (596.64s elapsed)
Total time 5347.02s (2216.89s elapsed)
@jtobin
jtobin / gist:4029008
Created Nov 7, 2012
SPDE sequential run
View gist:4029008
./SPDE 1000000 1000 > trace.dat
MUT time 2769.65s (2770.68s elapsed)
GC time 600.57s (599.46s elapsed)
Total time 3370.22s (3370.13s elapsed)
@jtobin
jtobin / gist:4057105
Created Nov 12, 2012
SPDE gradient via ad
View gist:4057105
import Numeric.AD
gTarget :: [Double] -> [Double]
gTarget = grad target
@jtobin
jtobin / gist:4130676
Created Nov 22, 2012
praxis list union/intersection
View gist:4130676
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
import Data.List
import Data.Hashable (Hashable)
import Data.HashMap.Strict hiding (filter)
import Control.Monad
import Test.QuickCheck
import Test.QuickCheck.All
import Criterion.Main
@jtobin
jtobin / gist:4130700
Created Nov 22, 2012
praxis list union/intersection main
View gist:4130700
=== prop_i0ResultElementsAreInBoth from ui.hs:64 ===
+++ OK, passed 1000 tests.
=== prop_i1ResultElementsAreInBoth from ui.hs:68 ===
+++ OK, passed 1000 tests.
=== prop_i2ResultElementsAreInBoth from ui.hs:72 ===
+++ OK, passed 1000 tests.
=== prop_u0ResultElementsInAtLeastOne from ui.hs:77 ===
@jtobin
jtobin / gist:5651280
Last active Dec 17, 2015
Portfolio grabbin'
View gist:5651280
{-# OPTIONS_GHC -Wall #-}
import Data.Function
import Data.List
main :: IO ()
main = print $ minimumBy (compare `on` sumDiffs) portfolios
-- Data ------------------------------------------------------------------------
You can’t perform that action at this time.