Skip to content

Instantly share code, notes, and snippets.

View cscherrer's full-sized avatar

Chad Scherrer cscherrer

View GitHub Profile
@cscherrer
cscherrer / maskarray-playground.jl
Created April 8, 2021 13:07
trying out MaskArrays
using MeasureTheory
using MaskArrays
using Soss
using TransformVariables
a = rand(Cauchy() ^ 10)
b = rand(Cauchy() ^ 10)
x = a' .+ b .+ randn(10,10)
@cscherrer
cscherrer / sir.jl
Created April 5, 2021 00:12
SIR model in Soss using MeasureTheory.jl
using Soss
using MeasureTheory
minit = @model begin
s ~ Poisson(300_000_000)
i ~ Dirac(1)
r ~ Dirac(0)
d ~ Dirac(0)
end
@cscherrer
cscherrer / markovchains-dyniterate.jl
Created March 13, 2021 23:35
First crack at using DynamicIterators.jl to build Markov chains
using DynamicIterators
using MeasureTheory
using ConcreteStructs
abstract type Step end
struct Sample <: Step end
sample = Sample()
@cscherrer
cscherrer / partial.jl
Last active March 5, 2021 00:03
partial at one coordinate
julia> using StructArrays
julia> using ForwardDiff
julia> function partiali(n,i)
ith = zeros(n)
ith[i] += 1
function (f,x)
sa = StructArray{ForwardDiff.Dual{}}((x, ith))
return f(sa)
@cscherrer
cscherrer / showstack.jl
Last active February 12, 2021 22:40
Showing a callstack with IRTools
using IRTools: @dynamo, IR, xcall, arguments, insertafter!, recurse!, self
mutable struct CallStack
count::Int
end
inc!(d::CallStack) = d.count += 1
dec!(d::CallStack) = d.count -= 1
function hook0(callstack::CallStack, f, args...)
@cscherrer
cscherrer / Manifest.toml
Created January 15, 2021 15:52
Soss Manifest.toml
# This file is machine-generated - editing it directly is not advised
[[AbstractAlgebra]]
deps = ["InteractiveUtils", "LinearAlgebra", "Markdown", "Random", "RandomExtensions", "SparseArrays", "Test"]
git-tree-sha1 = "7df2949bfd757e426897a4b579fbd5dc776ff8c9"
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
version = "0.12.0"
[[AbstractLattices]]
git-tree-sha1 = "f35684b7349da49fcc8a9e520e30e45dbb077166"
@cscherrer
cscherrer / sir.jl
Last active July 2, 2021 20:58
Simple SIR model in Soss
using Soss
using Distributions
mstep = @model pars,state begin
# Parameters
α = pars.α # Daily transmission rate
βγ = pars.βγ # Daily recovery rate, case fatality rate
# Starting counts
s0 = state.s # Susceptible
@cscherrer
cscherrer / Julia____-packages.txt
Created February 7, 2020 16:09
A list of Julia packages that are "branded" in the sense of being hosted in a Julia____ organization on Github
JuliaActuary/MortalityTables.jl
JuliaActuary/DynamicPolynomials.jl
JuliaActuary/FixedPolynomials.jl
JuliaActuary/MultivariateBases.jl
JuliaActuary/MultivariateMoments.jl
JuliaActuary/MultivariatePolynomials.jl
JuliaActuary/SemialgebraicSets.jl
JuliaActuary/StaticPolynomials.jl
JuliaActuary/TypedPolynomials.jl
@cscherrer
cscherrer / logpdfs.jl
Created January 10, 2020 03:45
Log-densities with less code, using MacroTools and SymPy
import PyCall,SymPy
using MLStyle
stats = PyCall.pyimport_conda("sympy.stats", "sympy");
SymPy.import_from(stats)
sym(x) = SymPy.symbols(x);
macro ℓ(expr)
args = @match expr begin
using Transducers
T = Transducers
struct MeanVar <: Transducer
end
function T.start(rf::T.R_{MeanVar}, result)
private_state = (0, 0.0, 0.0)