Skip to content

Instantly share code, notes, and snippets.

View luiarthur's full-sized avatar

Arthur Lui luiarthur

View GitHub Profile
@luiarthur
luiarthur / pbar.R
Last active September 26, 2022 17:54
Basic Progress Bar for R
ProgressBar = function(num_steps, freq=0.2) {
tic = Sys.time()
init = Sys.time()
current_step = 0
update = function() {
current_step <<- current_step + 1
toc = Sys.time()
if ((toc - tic > freq) || (current_step == num_steps)) {
.speed = current_step / as.numeric(toc - init)
@luiarthur
luiarthur / ess.R
Last active February 16, 2023 02:57
Elliptical slice sampling in R
ProgressBar = function(niters, freq=0.2) {
tic = Sys.time()
init = Sys.time()
advance = function(i) {
toc = Sys.time()
if ((toc - tic > freq) || (i == niters)) {
.speed = i / as.numeric(toc - init)
speed = round(ifelse(.speed > 1, .speed, 1 / .speed))
speed_units = ifelse(.speed > 1, "it/s", "s/it")
@luiarthur
luiarthur / keybindings.json
Last active April 10, 2024 16:40
VSCode map `ctrl-j` to send line down
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+shift+h",
"command": "workbench.action.navigateLeft"
},
{
"key": "ctrl+shift+l",
"command": "workbench.action.navigateRight"
},
@luiarthur
luiarthur / gibbs.jl
Last active February 16, 2023 02:59
Gibbs sampling with ESS and analytic full conditional in Turing (julia)
# Julia: v1.7
"""
Demo of using `Gibbs` sampling with `ESS` update for one set of parameters and
`GibbsConditional` for another. Demo model is a standard multiple linear
regression model with Gaussian priors for the coefficients and Inverse Gamma
prior for the variance of the error terms. Weakly / non-informative priors are
used. Results are benchmarked against the inference from a model sampled
entirely using NUTS.
"""
@luiarthur
luiarthur / elliptical_slice_sampler.py
Created September 19, 2022 22:55
Elliptical Slice Sampler
def ess_step(state, loglike_fn, prior_sampler, prev_loglike=None):
"""
state: current state
loglike_fn: loglikelihood function which accepts one argument: a
parameter vector.
prior_sampler: function (with no arguments) to sample from the prior,
which must be a multivariate normal. i.e. the function returns a
sample from a multivariate normal.
prev_loglike (float): the result of `loglike_fn(state)`, which should be computed previously.
"""
@luiarthur
luiarthur / init.vim
Created September 15, 2022 04:25
Single script init.vim for native windows
""" This file belongs in ~/AppData/Local/nvim/init.vim. Create if necessary.
""" Made for Windows OS.
""" Make sure that ~/AppData/Local/nvim/autoload/plug.vim contains a copy of plug.vim.
""" 1. Plugins
" NOTE: This script requires vim-plug.
" See: https://github.com/junegunn/vim-plug
" Install vimplug if needed.
@luiarthur
luiarthur / shortcuts.jupyterlab-settings
Last active September 13, 2022 22:08
Keyboard shortcut settings for Jupyterlab
{
"shortcuts": [
{
"command": "notebook:run-all-below",
"keys": [
"Ctrl Shift Enter"
],
"selector": ".jp-Notebook:focus"
},
{
@luiarthur
luiarthur / vimrc
Last active February 16, 2023 03:01
simple vimrc (for vim 7+)
" Plugins.
call plug#begin()
Plug 'luiarthur/tmux.vim'
Plug 'luiarthur/red.vim'
call plug#end()
" Color scheme.
silent! colorscheme noir " depends on `luiarthur/red.vim`
" Tab / buffer navigation.
@luiarthur
luiarthur / screenrc
Created June 1, 2022 22:16
A very basic `~/.screenrc`
# Always show status bar at the bottom of screen.
hardstatus alwayslastline
# Disable screen locking.
bind ^x
bind x
@luiarthur
luiarthur / SIR-alternative.ipynb
Created March 30, 2022 18:59
SIR model using transition matrices
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.