Skip to content

Instantly share code, notes, and snippets.

View cpfiffer's full-sized avatar
🤙
LOVING IT

Cameron Pfiffer cpfiffer

🤙
LOVING IT
View GitHub Profile
@cpfiffer
cpfiffer / mdc.sh
Created June 17, 2024 20:41
Quick julia script to display markdown
#!/usr/bin/env bash
program="
import Markdown
map(ARGS) do f
c = if isfile(f)
read(f, String)
else
f
end
display(Markdown.parse(c))
@cpfiffer
cpfiffer / poly-test.jl
Created January 13, 2021 06:54
A super simple estimation of a function using its derivative.
# Set up environment
import Pkg; Pkg.activate(".")
# Imports
using Distributions
using Plots
using Polynomials
using Optim
using ForwardDiff
Formula:
returns ~ BITX + lag_returns + log_active + lag_active + log_avg_size + log_med_size + log_mode_size + native_transactions + :(fe(yearmonth))
Fixed Effect Model
=======================================================================================
Number of obs: 1066 Degrees of freedom: 44
R2: 0.157 R2 Adjusted: 0.122
F Statistic: 12.4004 p-value: 0.000
R2 within: 0.106 Iterations: 1
Converged: true
@cpfiffer
cpfiffer / streaming-turing.jl
Created March 3, 2020 14:19
Stream Turing samples onto disk as they come.
using Turing, MCMCChains
using AbstractMCMC
using JLD2, FileIO
import Random: GLOBAL_RNG
# Create a model.
@model model(y) = begin
μ ~ Normal(0, 1)
s ~ InverseGamma(2,3)
@cpfiffer
cpfiffer / garch.jl
Created November 26, 2019 14:32
GARCH in Turing.jl
using Turing
using CSVFiles
using DataFrames
using Dates
using StatsPlots
# The TV syntax allows sampling to be type-stable.
@model garch(r, ::Type{TV}=Vector{Float64}) where {TV} = begin
T = length(r)
@cpfiffer
cpfiffer / diag_test_3.jl
Created August 3, 2019 18:07
Test ESS cap
using MCMCChains
function sim(nsamples)
cnt = 0
for i in 1:1000
chn = Chains(randn(nsamples,1,1))
ess = describe(chn)[1].df[:ess][1]
ess > nsamples ? cnt+=1 : nothing
end
return cnt
@cpfiffer
cpfiffer / diag_test_2.jl
Created August 3, 2019 18:05
Test bias
using CmdStan, StatsPlots, Random, MCMCDiagnostics
Random.seed!(12395391)
ProjDir = @__DIR__
cd(ProjDir)
berstanmodel = "
data {
int<lower=0> N;
@cpfiffer
cpfiffer / diag_test.jl
Created August 3, 2019 17:27
Test ESS draws
using CmdStan, DynamicHMC
using StatsPlots, Random, MCMCDiagnostics
using Revise
using Turing, AdvancedHMC; const AHMC = AdvancedHMC
Random.seed!(1239911)
ProjDir = @__DIR__
cd(ProjDir)
Nsamples = 2000
@cpfiffer
cpfiffer / P21.hs
Created March 25, 2018 16:32
Solves problem 21 of Project Euler with list comprehensions.
module P21 (properDivisors, sumDivisors, sumAmicable, isAmicable, amicableList) where
properDivisors :: Int -> [Int]
properDivisors x = [xs | xs <- [1..x-1], x `mod` xs == 0]
sumDivisors :: Int -> Int
sumDivisors x = sum $ properDivisors x

Keybase proof

I hereby claim:

  • I am cpfiffer on github.
  • I am cpfiffer (https://keybase.io/cpfiffer) on keybase.
  • I have a public key ASBuOyV4zsOUIxWVtBtAh0aRwqkKu25BwWPjUIxgfL8R4go

To claim this, I am signing this object: