Skip to content

Instantly share code, notes, and snippets.

View roualdes's full-sized avatar

Edward A. Roualdes roualdes

View GitHub Profile
@roualdes
roualdes / bootdplyr.R
Last active November 8, 2018 18:21
Bootstrap Confidence Interval with dplyr
library(boot)
library(dplyr)
## assumed symmetric bootstrapped confidence interval
# function: bootstrap estimated standard error
boot_sd <- function(x, fun=mean, R=1001) {
fun <- match.fun(fun)
bfoo <- function(data, idx) {
fun(data[idx])
}
@roualdes
roualdes / onlinewindowedapproximateautocovariance.jl
Last active July 15, 2022 12:48
An online windowed approximation for auto covariance in Julia
# to run
# install Julia: https://julialang.org/
# create gist.jl in dir
# $ cd dir
# $ julia gist.jl
# tested on macOS 12.2 and Julia 1.7.2
struct OnlineCov{T <: AbstractFloat}
mx::Vector{T}
my::Vector{T}
@roualdes
roualdes / rosenbrock.py
Created November 7, 2022 21:25
BridgeStan: Rosenbrock
import bridgestan as bs
import optax
import numpy as np
import jax.numpy as jnp
import matplotlib.pyplot as plt
from matplotlib import cm
sm = bs.StanModel("rosenbrock_model.so")
q = np.asarray([0.0, 2.5])
@roualdes
roualdes / mvt.R
Last active November 11, 2022 00:31
BridgeStan: Multivariate Student-t
library(cmdstanr)
library(bridgestan)
library(mvtnorm)
project_xy <- function(z, sigma = diag(dim(z)[2])) {
theta <- atan2(z[,2], z[,1]) # atan(z[,2] / z[,1]) + (z[,1] < 0) * pi
r <- apply(z, 1, function(x) sqrt(t(x) %*% solve(sigma, x)))
list(x = r * cos(theta), y = r * sin(theta))
}
@roualdes
roualdes / StanESS.stan
Created March 21, 2023 20:10
Stan to autodiff effective sample size
functions {
int fft_nextgoodsize(int N) {
if (N <= 2) {
return 2;
}
int m = N;
int n = N;
while (1) {
while (m % 2 == 0) {