Skip to content

Instantly share code, notes, and snippets.

View phipsgabler's full-sized avatar

Philipp Gabler phipsgabler

View GitHub Profile
@phipsgabler
phipsgabler / benchmark_history_extended.svg
Last active February 9, 2023 12:08
Redrawing & extension of the figure from Ajot & Fiscus (2009)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Background:
# - Release in ≈ 2012
# - Intended for scientific programming, but solving 2-language-problem
# - Replace Matlab/Fortran/C++ with free, dynamic language (inspired by
# Matlab, Python, Ruby, LISP, Perl,...)
# - Has become really good alternative to Matlab & Python
# - GC, dynamic, but strong nominal parametric type system with
# multiple dispatch
# - Extensive standard library (numerics, glue code), loads of packages
# - JIT-compiled
@phipsgabler
phipsgabler / simulation.jl
Created September 16, 2021 14:26
Rough sketch of a mixed-effects beta regression allowing to use MixedModels.jl formula syntax
using CategoricalArrays
using DataFrames
using Distributions
using DynamicPPL
using MixedModels
using Plots
using StatsFuns
using StatsModels
using StatsPlots
using Turing
@phipsgabler
phipsgabler / hasfields_trait.jl
Created August 25, 2021 14:38
Type stable trait for checking field types
julia> HasFields(::Type{T}) where {T} = Val{true}()
HasFields (generic function with 1 method)
julia> HasFields(::Type{T}, ::Type{U}, name) where {T, U} = Val{fieldtype(T, name) <: U}()
HasFields (generic function with 2 methods)
julia> HasFields(Some, Any, :value)
Val{true}()
julia> HasFields(::Type{T}, ::Type{U}, name, names...) where {T, U} = Val{fieldtype(T, name) <: U && HasFields(T, U, names...) isa Val{true}}()
# trying to refactor https://codereview.stackexchange.com/q/259818/180160
# not tested for correctness
const EPSILON = 1e-6
log_ϕ(x, μ, σ) = -(((x - μ) / σ)^2 - log(2π)) / 2 - log(σ)
ϕ(x, μ, σ) = exp(log_ϕ(x, μ, σ))
log_likelihood(x, θ) = sum(log(θ.p' * ϕ.(xₜ, θ.μ, θ.σ)) for xₜ in x)
function normalize!(θ; eps=EPSILON)
julia> macro unpacker(expr)
           (expr.head != :(=) || length(expr.args) != 2) && error("Expression needs to be of form `name = value`")
           name, value = expr.args
           @gensym(props, x)
           return esc(quote
               $props = propertynames($value)
               macro $name($x)
                   return Expr(:(=), Expr(:tuple, $props...), $x)
 end
IRTools.@dynamo function sloppyifs(f, args...)
ir = IRTools.IR(f, args...)
ir === nothing && return
IRTools.recurse!(ir)
for block in IRTools.blocks(ir)
bblock = IRTools.BasicBlock(block)
for b in eachindex(IRTools.branches(bblock))
branch = bblock.branches[b]
if IRTools.isconditional(branch)
using IRTools
abstract type AbstractNode end
struct Node <: AbstractNode
ir::IRTools.IR
children::Vector{<:AbstractNode}
end
Node(ir) = Node(ir, Vector{AbstractNode}())
{-# LANGUAGE DataKinds,
TypeFamilies,
PolyKinds,
GADTs,
ConstraintKinds #-}
module MonadicFlow (
Sec,
Less,
open,
using BenchmarkTools
using Einsum
using TensorOperations
const N = 9851
const K = 35
const D = 16
const x = rand(N, D)
const μ = rand(D, K)