Skip to content

Instantly share code, notes, and snippets.

@aotimme
aotimme / pharmacokinetics.R
Last active August 29, 2015 14:20
Pharmacokinetics Estimation Example
x <- c(0.27, 0.58, 1.02, 2.02, 3.62, 5.08, 7.07, 9.00, 12.15, 24.17)
y <- c(4.40, 6.90, 8.20, 7.80, 7.50, 6.20, 5.30, 4.90, 3.70, 1.05)
# function
f <- function(beta, x) {
D <- 4.53
V <- beta[1]
k.a <- beta[2]
k.e <- beta[3]
D * k.a / (V * (k.a - k.e)) * (exp(-k.e * x) - exp(-k.a * x))
@aotimme
aotimme / lasso_admm.py
Last active August 22, 2018 16:23
ADMM for LASSO
import numpy as np
l2 = lambda x: np.sqrt(np.sum(np.square(x)))
def lasso_admm(X, y, lambduh, rho=1.0, tol=1e-10, maxiter=1000):
i = 0
n, p = X.shape
inv = np.linalg.inv(X.T.dot(X) + rho * np.eye(p))
xy = X.T.dot(y)
@aotimme
aotimme / rbm.go
Created March 5, 2015 03:14
Restricted Boltzmann Machine in Golang
package rbm
import (
"fmt"
"math"
"math/rand"
)
func uniform(r *rand.Rand) float64 {
if r == nil {
@aotimme
aotimme / bblinreg.py
Last active August 29, 2015 14:16
Black Box Variational Inference: Bayesian Linear Regression
import os
import numpy as np
def generate_data(n, p, seed):
np.random.seed(seed)
beta = np.random.normal(size=p, scale=2.0)
X = np.random.normal(size=(n,p))
y = np.dot(X, beta)
@aotimme
aotimme / pushstate.nginxconf
Last active June 3, 2022 19:37
Nginx config file to support pushState.
# pushState friendly!
# The setup:
# * website name is `site.com`
# * the API for your running on localhost:3000
# * the root for API calls is at `/api`, and you have authentication routes with root `/auth` (both go to localhost:3000)
# * javascript app is located at `/path/to/javascript/app`
# Assuming you have your server for API calls at localhost port 3000
upstream api_sitecom {
server localhost:3000;
@aotimme
aotimme / test_array_hash.js
Created December 5, 2012 18:09
Quick example test of how object is implemented in node and chrome. (Hint: it's a hash table)
var i;
var MAX = 100000;
/* === Versions ===
* NODE: v0.6.12
* CHROME: 23.0.1271.64
*/
/* === Hash ===
* NODE: 12ms
* CHROME: 187.885ms