Skip to content

Instantly share code, notes, and snippets.

View sethaxen's full-sized avatar
🪓

Seth Axen sethaxen

🪓
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sethaxen
sethaxen / varnames_to_ranges.jl
Last active February 16, 2022 22:42
Getting parameter ranges from Turing
using DynamicPPL
# utilities for working with Turing model parameter names using only the DynamicPPL API
"""
flattened_varnames_list(model::DynamicPPL.Model) -> Vector{Symbol}
Get a vector of varnames as `Symbol`s with one-to-one correspondence to the
flattened parameter vector.
@sethaxen
sethaxen / wasserstein.jl
Last active October 28, 2021 23:03
empirical p-wasserstein distance for multivariate samples
using Distances, Distributions, OptimalTransport, LinearAlgebra, Random
struct PowEuclidean{T} <: Distances.PreMetric
p::T
end
(m::PowEuclidean)(a, b) = Distances.Euclidean()(a, b)^m.p
# for measures μ and ν with support ℝᵈ, approximate empirical p-wasserstein distance
# between matrices x and y of random points whose columns are respectively drawn from
@sethaxen
sethaxen / geodesic_flow_gl.jl
Last active March 14, 2021 04:52
Geodesic flow on the general linear group
# Using Manifolds.jl, follow-up to https://github.com/JuliaManifolds/Manifolds.jl/pull/249
using LinearAlgebra
using Manifolds
using Test
# parallel transport of a point (p,X) ∈ T GL(n) along the
# geodesic curve γ on GL(n) with the left-GL(n)-invariant metric
# from section A.2 of https://arxiv.org/abs/1603.05868v1
function geodesic_flow!(M::GeneralLinear, q, Y, p, X, t::Real = 1)
@sethaxen
sethaxen / expv_chainrules.jl
Last active December 26, 2020 20:59
Chain rules for the action of the matrix exponential
# rrule for expv(t, A, v) = exp(t * A) * v
# Use OrdinaryDiffEq to solve adjoint system for pullback
# Since OrdinaryDiffEq depends on ExponentialUtilities, it doesn't make sense
# to include this code there
using Pkg
Pkg.add(["ChainRulesCore", "ChainRulesTestUtils", "ExponentialUtilities", "FiniteDifferences", "OrdinaryDiffEq", "Test", "LinearAlgebra"])
using ChainRulesCore, ChainRulesTestUtils, FiniteDifferences, OrdinaryDiffEq, Test, LinearAlgebra, Random
using FiniteDifferences: rand_tangent
@sethaxen
sethaxen / zygote_power_series_tests.jl
Created April 29, 2020 22:32
Zygote power series tests
using FiniteDifferences, LinearAlgebra, Zygote, Random, Test
# adapted from ChainRulesTestUtils.rrule_test
function pullback_test(
f,
ȳ,
xx̄s::Tuple{Any,Any}...;
rtol = 1e-9,
atol = 1e-9,
fkwargs = NamedTuple(),
@sethaxen
sethaxen / harmonic_distance_restraints.ipynb
Last active January 14, 2020 00:52
Harmonic distance restraints are not Gaussian
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.