Skip to content

Instantly share code, notes, and snippets.

@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
'''
@jiahao
jiahao / RTFM.md
Created May 9, 2013 19:13
How to add yourself to the free-food mailing list at MIT
@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 / 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
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 / 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]))[])
@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 / bicgstabell.jl
Last active October 12, 2017 19:51
A transcription of the BiCGSTAB(ell) algorithm (Sleijpen and Fokkema, 1993, http://igitur-archive.library.uu.nl/math/2006-1214-210728/sleijpen_93_bicgstab.pdf)
function bicgstabell(K::KrylovSubspace; tol::Real, l::Int=1)
k=-l
initrand!(K)
#XXX Choose r̃[0]
r[0]=b-nextvec(K)
u[-1]=0
x[0]=K.v0
ρ₀=1
α=0
ω=1
@jiahao
jiahao / custom.css
Created December 1, 2013 08:28
Experimental typographically tinkered IJulia stylesheet To use, place in ~/.ipython/profile_julia/static/custom/custom.css and refresh IJulia
/* Experimental typographically tinkered IJulia stylesheet
* Copyright © 2013 Jiahao Chen <[email protected]>
* MIT License
*
* To use, place in ~/.ipython/profile_julia/static/custom/custom.css
* and refresh IJulia
*
* Based on suggestions from practicaltypography.com
*/
using Images
using JSON
auth_token=#Put your auth_token here
download("https://api.github.com/repos/JuliaLang/julia/contributors?access_token=$(auth_token)", "julia_contribs.json")
authors=JSON.parse(open("julia_contribs.json"))
for (idx, author) in enumerate(authors)
authorname=author["login"]
gravatar_filename = string("avatar_", authorname, ".png")
download(author["avatar_url"], gravatar_filename)
theimage = Images.imread(gravatar_filename)