Skip to content

Instantly share code, notes, and snippets.

@jiahao
jiahao / savitzkygolay.jl
Last active April 26, 2024 12:03
An implementation of the Savitzky-Golay filter using generated functions. Accompanies https://medium.com/@acidflask/smoothing-data-with-julia-s-generated-functions-c80e240e05f3
"""
Savitzky-Golay filter of window half-width M and degree N
M is the number of points before and after to interpolate, i.e. the full width
of the window is 2M+1
"""
immutable SavitzkyGolayFilter{M,N} end
@generated function Base.call{M,N,T}(::Type{SavitzkyGolayFilter{M,N}},
data::AbstractVector{T})
@jiahao
jiahao / llama2.jl
Last active August 2, 2023 08:35
NOTE 2023-07-30: This gist is deprecated in favor of https://github.com/rai-llc/LanguageModels.jl . llama2.jl is a port of @karpathy's llama2.c to Julia.
# A port of https://github.com/karpathy/llama2.c/blob/master/run.c
# to Julia.
# Jiahao Chen <jiahao@csail.mit.edu> 2023-07-29
#
# MIT License: see full text at https://opensource.org/license/mit/
#
using LinearAlgebra
using LogExpFunctions
@jiahao
jiahao / doubledescent.jl
Last active July 12, 2023 18:29
A small example of double descent in Julia
using Plots
using StatsPlots
using LinearAlgebra
using ClassicalOrthogonalPolynomials
using ProgressMeter
using Statistics
k = 15 # Size of training data
l = 15 # Size of test data
@jiahao
jiahao / nf4.jl
Last active July 10, 2023 14:55
Minimal Julia implementation of NF4 floating point for QLoRA
using Statistics
using BFloat16s
using StaticArrays
import Base: getindex, setindex!, length, iterate
###########################################
# Implementation of the NormedFloat4 type
# and its container type, QLoRAArray
#
@jiahao
jiahao / nrules.svg
Last active May 17, 2022 08:30
What do .gitignore files tell us about the inherent complexity of programming languages? This gist can be run on data from GitHub's own collection of gitignore templates, whose repository is at https://github.com/github/gitignore, and counts how many rules are present in the template for each programming language.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / listpdfs.py
Created August 31, 2021 15:37
Scrape my arXiv profile to list one PDF per line. Useful for updating conference submission profiles
from bs4 import BeautifulSoup
import urllib.request
url = "https://arxiv.org/a/chen_j_2.html"
with urllib.request.urlopen(url) as response:
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
for link in soup.find_all('a'):
@jiahao
jiahao / tsqr.jl
Created August 4, 2015 05:50
Tall and skinny QR in Julia
#################################################################
# A simple implementation of TSQR (Tall and Skinny QR) in Julia #
# Jiahao Chen <jiahao@mit.edu>, 2015-08-03 #
#################################################################
#
# TSQR is a communication-avoiding QR algorithm designed for
# distributed computation on tall, skinny matrices, which are
# typical of data matrices in Big Data applications.
#
# The primary reference is
@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}