Skip to content

Instantly share code, notes, and snippets.

View sethaxen's full-sized avatar
🪓

Seth Axen sethaxen

🪓
View GitHub Profile
@sethaxen
sethaxen / ecdf_confidence_bands.ipynb
Last active February 7, 2024 15:16
Python implementation of ECDF confidence bands
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sethaxen
sethaxen / ldiv_pullback.md
Created January 30, 2024 22:18
Derivation of pullback of ldiv

Let $A$ be an $n \times m$ matrix, $Y$ be an $m \times k$ matrix, and $B$ be an $n \times k$ matrix such that $$Y = A \ B = A^+ \ B,$$ where $A^+$ is a Moore-Penrose pseudoinverse, given by $$ A^+ = \begin{cases} A^\top (AA^\top)^{-1} & n \le m\ (A^\top A)^{-1} A^\top & n \ge m\ \end{cases}. $$ Let $C = A^+$.

@sethaxen
sethaxen / juliaup_update_nightly.sh
Created January 20, 2024 09:14
Download and set nightly channel on juliaup
#!/bin/bash
# Adapted from https://github.com/JuliaLang/juliaup/issues/96#issuecomment-1480110471
# Set variables for directories and files
JULIA_DIR="$HOME/.julia/juliaup/julia-nightly"
TMP_FILE="/tmp/julia-nightly.tar.gz"
JULIA_NIGHTLY_URL="https://julialangnightlies-s3.julialang.org/bin/linux/x86_64/julia-latest-linux-x86_64.tar.gz"
# Download the nightly Julia build
@sethaxen
sethaxen / qr_reflector_bijector.jl
Last active November 8, 2023 14:31
Demo of a bijective transform to a QR factorization using elementary reflectors
using Bijectors, ChangesOfVariables, LinearAlgebra
"""
QRReflectorBijector(n, k; special::Bool=false, fullR::Bool=false)
A bijector that maps parameters of elementary LAPACK-style reflectors to a QR factorization
with size `(n, k)`.
The `R` factor of the element has a positive real diagonal.
If `fullR=false`, then the `R` factor is diagonal, which reduces the number of
@sethaxen
sethaxen / distribution_with_transform.jl
Created September 19, 2023 17:53
Custom bijectors in Turing
using Distributions, Bijectors, Random, FillArrays, LogExpFunctions
struct DistributionWithTransform{D<:ContinuousDistribution,B,V<:VariateForm} <: Distribution{V,Continuous}
dist::D
transform::B
function DistributionWithTransform(d::ContinuousDistribution, b)
F = Distributions.variate_form(typeof(d))
return new{typeof(d),typeof(b),F}(d, b)
end
end
@sethaxen
sethaxen / corrzeros.jl
Last active October 9, 2023 23:34
Bijector from Cholesky factor of correlation matrix with structural zeros
using Bijectors, ChangesOfVariables, LinearAlgebra
struct VecCholeskyCorrBijectorWithZeros{Z<:AbstractVector{Tuple{Int,Int}}} <: Bijectors.Bijector
zero_inds::Z
function VecCholeskyCorrBijectorWithZeros(zero_inds::Z) where Z<:AbstractVector{Tuple{Int,Int}}
new{Z}(unique!(sort(map(sort, zero_inds); by=reverse)))
end
end
function Bijectors.output_size(b::VecCholeskyCorrBijectorWithZeros, sz::Tuple{Int,Int})
@sethaxen
sethaxen / dirichlet_mvlogitnormal.jl
Last active September 9, 2023 19:28
Implementation of family containing Dirichlet and multivariate logit (logistic) normal as special cases, compatible with Turing
using Bijectors, Distributions, LinearAlgebra, PDMats
"""
DirichletMvLogitNormal(α::AbstractVector, J::AbstractMatrix; check=false)
A distribution that contains `MvLogitNormal` and `Dirichlet` as special cases.[^Aitchison1985]
Let ``x \\sim \\mathrm{DirichletMvLogitNormal}(α, J)`` be a length ``N`` probability vector,
where ``α`` is a length ``N`` vector, and ``J`` is a size ``(N-1,N-1)`` positive
semi-definite matrix. Given ``z_i = \\log(x_i)``, the density function of the
@sethaxen
sethaxen / dirichlet_unconstrained_N10.png
Last active June 15, 2023 09:04
Comparison plots for the IID marginals of the Dirichlet distribution after using stick-breaking and stick-breaking power transforms (see https://github.com/mjhajharia/transforms)
dirichlet_unconstrained_N10.png
@sethaxen
sethaxen / wrappednormal.jl
Created May 4, 2023 20:41
WrappedNormal for Distributions.jl
using Distributions
using IrrationalConstants
using LogExpFunctions
using Random
abstract type WrappedNormalDensityMethod end
struct WrappedMethod <: WrappedNormalDensityMethod end
struct JacobiMethod <: WrappedNormalDensityMethod end
"""
@sethaxen
sethaxen / eci.ipynb
Last active June 12, 2023 23:47
Expected Constrained Improvement with SMAC
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.