Skip to content

Instantly share code, notes, and snippets.

@jiahao
jiahao / setup_julia.sh
Last active January 20, 2022 03:43
Setting up Julia on an Amazon EC2 instance
#Set up data partition
sudo mkdir /data
sudo chmod 777 /data
sudo "echo /dev/xvdb /data ext4 rw,user,exec,comment=cloudconfig 0 2 >> /etc/fstab"
sudo mount /data
#Install build environment
sudo sed -i "s/enabled=0/enabled=1" /etc/yum.repos.d/epel.epo
sudo yum -y update
sudo yum -y upgrade
@jiahao
jiahao / parallel_cumsum.jl
Last active December 27, 2015 08:29
An implementation of parallel cumsum (cumulative sum) in Julia.
import Base.fetch; fetch(t::Vector) = [fetch(tt) for tt in t]
import Base.length; length(r1::RemoteRef)=length(fetch(r1))
addprocs(8-nprocs()) #Run on 8 processors
chunkrange(i, nc) = floor((i-1)*nc)+1:floor(i*nc)
function chunk(z, n)
nc = length(z)/n
y = Vector{typeof(z[1])}[]
for i=1:n #Number of chunks
push!(y, (typeof(z[1]))[])
Process: julia-readline [12132]
Path: /Users/USER/*/julia-readline
Identifier: julia-readline
Version: ???
Code Type: X86-64 (Native)
Parent Process: Vim [11995]
Responsible: MacVim [11340]
User ID: 502
Date/Time: 2013-10-28 23:52:40.788 -0400
@jiahao
jiahao / Hypergeometric.jl
Created October 18, 2013 21:13
Hypergeometric random variate generators implemented in Julia
# Hypergeometric random variate generators
#
# (c) 2013 Jiahao Chen <[email protected]>
#
# This file implements several random variate generators as described in the
# reference paper.
#
# Algorithm Function
# HBU randhg_hbu
# HIN randhg_hin
@jiahao
jiahao / BagOfLittleBootstraps.jl
Last active March 23, 2021 02:22
Julia implementation of the Bag of Little Bootstraps (BLB) method (documented as, e.g., Algorithm 1 in arXiv:1112.5016)
using Distributions
export Measure, DiscreteMeasure, Estimator, EstimatorQuality,
blb, randsubset
abstract Measure
type DiscreteMeasure{S<:Number,T<:Number} <: Measure
points :: Vector{S}
weights :: Vector{T}
@jiahao
jiahao / RTFM.md
Created May 9, 2013 19:13
How to add yourself to the free-food mailing list at MIT
@jiahao
jiahao / Optimizer.py
Created January 4, 2012 17:44
Pure Python implementation of some numerical optimizers
#!/usr/bin/env python
'''
Pure Python implementation of some numerical optimizers
Created on Jan 21, 2011
@author Jiahao Chen
'''