Skip to content

Instantly share code, notes, and snippets.

View AnthonyEbert's full-sized avatar

Anthony Ebert "Ace" AnthonyEbert

View GitHub Profile
@AnthonyEbert
AnthonyEbert / set_lib_paths.R
Created April 27, 2020 06:36
set lib paths
# Courtesy of Miles McBain https://milesmcbain.xyz/hacking-r-library-paths
set_lib_paths <- function(lib_vec) {
lib_vec <- normalizePath(lib_vec, mustWork = TRUE)
shim_fun <- .libPaths
shim_env <- new.env(parent = environment(shim_fun))
shim_env$.Library <- character()
shim_env$.Library.site <- character()
@AnthonyEbert
AnthonyEbert / coin-flips.R
Created September 30, 2019 09:46
Metropolis hastings sampler for coin flips
prob <- 0.1
len_z <- 1000
z <- rbinom(n = len_z, 1, prob)
n <- 1000
z_mat <- matrix(nrow = n, ncol = len_z)
for(i in 1:n){
for(s in 1:len_z){
oldz <- z[s]
@AnthonyEbert
AnthonyEbert / R2PBS.md
Created January 2, 2019 00:52 — forked from brfitzpatrick/R2PBS.md
How to submit R code to a Portable Batch System (PBS) managed HPC resource (e.g. QUT's High Performance Computing Facility `Lyra').

How to submit R code to a Portable Batch System (PBS) managed High Performance Computing (HPC) Facility (e.g. QUT's HPC Facility 'Lyra').

You will need:

  1. An account with the relevant HPC facility (QUT staff and HDR students can request access to the QUT facility here),
  2. the R Script (.R file) you want to run,
  3. a Job Script (.sub file) that tells Lyra how to run your R script and,
  4. a file containing any data your R Script needs to run.

Note: These instructions work on a system running Debian (GNU + Linux) with the Gnome Desktop Environment.

# R hacks that are cool ------
## Function to create list with default elements
list_defaults <- function(
a = 1,
b = 3,
c = "lsa"){
@AnthonyEbert
AnthonyEbert / latexdiff_procedure.md
Last active February 4, 2022 15:45
Do a latexdiff

Get old commit ready

Create folder in another repo directory e.g. repo-tester . Checkout the commit version that you want.

Put tex into single file

latexpand main.tex > output.tex

Do this for Git and repo-tester folders.

@AnthonyEbert
AnthonyEbert / subsampling-problem-or-not.md
Created November 10, 2017 06:47
Subsampling: problem or not?

Is subsampling y a problem?

The real data is y, the realisations (forward-simulations) are x. The distance d could refer to the MMD or the Wasserstein estimator.

Sampling strategies

  1. Compute full d with y and x,
  2. Draw a subsample from y and x and compute d,
@AnthonyEbert
AnthonyEbert / multi_smooth_ggpairs.R
Last active October 18, 2017 09:17 — forked from padamson/multi_smooth_ggpairs.R
Add true value annotation to empirical posterior plots
# For empirical posterior plots. Put the true values, repeated at the bottom two rows of the data.
require(datasets)
data("swiss")
require(GGally)
require(ggplot2)
input_swiss <- rbind(swiss[,1:4], c(75, 60, 10, 15), c(75, 60, 10, 15))
my_low <- function(data, mapping, ...){
@AnthonyEbert
AnthonyEbert / reneg.R
Last active October 9, 2017 11:31
queuecomputer Reneg
library(queuecomputer)
arrivals <- cumsum(rexp(1e4))
service <- rexp(1e4, 0.6)
max_wait <- rexp(1e4, 0.01)
reneg <- TRUE
angry_output <- c()
@AnthonyEbert
AnthonyEbert / R_and_python3.py
Last active May 15, 2017 10:33
Working with R and python3 with rpy2
import rpy2
import rpy2.robjects as robjects
import numpy
# python3 to R ----------------------------
py_base_list_x = [1,6]
py_base_array_x = (1,6)
R_base_numeric_x = rpy2.robjects.vectors.FloatVector(py_base_list_x)