Skip to content

Instantly share code, notes, and snippets.

@jtobin
jtobin / gist:4028961
Created November 7, 2012 01:24
Stochastic partial differential equation
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 November 7, 2012 01:35
SPDE parallel run
./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 November 7, 2012 01:37
SPDE sequential run
./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 November 12, 2012 01:55
SPDE gradient via ad
import Numeric.AD
gTarget :: [Double] -> [Double]
gTarget = grad target
@jtobin
jtobin / gist:4130676
Created November 22, 2012 11:26
praxis list union/intersection
{-# 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 November 22, 2012 11:33
praxis list union/intersection main
=== 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 / fix.hs
Created December 9, 2015 18:50
A program defined using 'Fix'
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
data Program f = Running (f (Program f))
deriving instance (Show (f (Program f))) => Show (Program f)
data Instruction r =
@jtobin
jtobin / free.hs
Created December 9, 2015 18:51
A program defined using 'Free'
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
data Program f a =
Running (f (Program f a))
| Terminated a
deriving instance (Show a, Show (f (Program f a))) => Show (Program f a)
@jtobin
jtobin / cofree.hs
Created December 9, 2015 18:51
A program defined using 'Cofree'
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
data Program f a = Program {
annotation :: a
, running :: f (Program f a)
}
@jtobin
jtobin / gist:5651280
Last active December 17, 2015 18:09
Portfolio grabbin'
{-# OPTIONS_GHC -Wall #-}
import Data.Function
import Data.List
main :: IO ()
main = print $ minimumBy (compare `on` sumDiffs) portfolios
-- Data ------------------------------------------------------------------------