Skip to content

Instantly share code, notes, and snippets.

View hrlai's full-sized avatar
🛰️
Open the portbay door, please

Lai Hao Ran hrlai

🛰️
Open the portbay door, please
View GitHub Profile
@hrlai
hrlai / rsync_tunnelling.sh
Created August 9, 2022 02:46
Using rsync with ssh tunnelling
# Suppose we want to sync files through host A -> host B -> local C
# replace <port number>, <username>, <hostnameB>, <hostnameA>
rsync -av -e 'ssh -o "ProxyCommand ssh -p <port number> -A <username>@<hostnameB> -W %h:%p"' <username>@<hostnameA>:path/to/folder local/path
@hrlai
hrlai / .sge_custom.tmpl
Created January 12, 2023 01:49
SGE bash script for future.batchtools::batchtools_sge
#!/bin/bash
#$ -cwd
#$ -j y
#$ -o <%= log.file %>
#$ -V
#$ -N <%= job.name %>
#$ -pe smp <%= resources[["slots"]] %>
Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
exit 0
##!/bin/bash
PATH=/share/apps/R/R-3.6.2/bin/:/share/apps/gcc-8.3/bin:$PATH
LD_LIBRARY_PATH=/share/apps/gcc-8.3/lib64:/home/hrl23/lib:$LD_LIBRARY_PATH
###############################
# SGE settings Here
# Basically, if a line starts with "#$", then you can enter any
# qsub command line flags . See the qsub(1) man page.
@hrlai
hrlai / greta_clique.R
Created November 30, 2023 02:28
greta_clique
# I am translating the code from https://github.com/mrcbarbier/diffuseclique/blob/master/codes/Clique%20Coexistence%20Matrix%20Generation.R to greta
# using the original function
MatrixGen=function(etai, beta.m, beta.sd)
{
S=length(etai)
mat=diag(S)
for(sp in 1:S)
{
Nmi=etai[-sp]
@hrlai
hrlai / loo_greta.R
Last active July 17, 2024 00:10
Obtain LOOIC or WAIC from greta
#' Obtain LOO-IC or WAIC from \code{greta} Output
#'
#' @param observed Vector of the observed response variable
#' @param posterior MCMC posterior from a \code{greta} model
#' @param mean Name of the mean/location parameter, defaults to \code{mu}
#' @param scale Name of the scale/variance parameter, defaults to \code{sd}
#' @param family Distribution of the observational model. Currently, only
#' \code{normal}, \code{lognormal}, and \code{student} are implemented
#' @param method
#' \code{"loo"} to calculate the Leave-One-Out Information Criteria or