Skip to content

Instantly share code, notes, and snippets.

View currymj's full-sized avatar

Michael J. Curry currymj

View GitHub Profile
@currymj
currymj / double_newton.py
Last active February 5, 2021 23:11
solving unconstrained Stackelberg problems using autograd to differentiate through a Newton solver
import jax.numpy as jnp
from jax import grad, hessian, jit
from jax.scipy.linalg import solve
import numpy as np
import matplotlib.pyplot as plt
# The goal here is to solve a Stackelberg game in a particularly grotesque way.
# To compute the follower best response, we take a few Newton steps using autograd to compute the Hessian and gradients.
# This is implemented in function `follower_bestresponse`.
@currymj
currymj / distributed.sh
Last active September 13, 2019 18:35
example code to reproduce problem
#!/bin/bash
#SBATCH --ntasks 2
#SBATCH -N 2
#SBATCH --job-name=distributed-pbg
#SBATCH -o log-gloo-test-%j.out
source /etc/profile
export HDF5_USE_FILE_LOCKING='FALSE'
export PARENT=`/bin/hostname -s`
@currymj
currymj / pytorch-build-errors.txt
Created September 11, 2019 16:54
saved output of build errors from pytorch code
In file included from ../caffe2/operators/batch_matmul_op.h:11:0,
from ../caffe2/operators/batch_matmul_op_test.cc:6:
../caffe2/core/operator.h: In member function 'std::vector<_RealType> caffe2::OperatorBase::GetVectorFromIValueList(const c10::IValue&) const':
../caffe2/core/operator.h:129:47: error: parse error in template argument list
return c10::impl::toVector(value.template to<List<T>>());
^
../caffe2/core/operator.h: In instantiation of 'std::vector<_RealType> caffe2::OperatorBase::GetVectorFromIValueList(const c10::IValue&) const [with T = long int]':
../caffe2/core/operator.h:818:52: required from here
../caffe2/core/operator.h:129:31: error: no matching function for call to 'c10::IValue::to() const'
return c10::impl::toVector(value.template to<List<T>>());
@currymj
currymj / branchprediction_problem.jl
Last active August 25, 2018 01:05
demonstrates that adding up certain values becomes much faster when an array is sorted, due to modern CPU branch prediction (see https://stackoverflow.com/questions/11227809/why-is-it-faster-to-process-a-sorted-array-than-an-unsorted-array)
function genlist()
arr = zeros(32768)
for i=1:length(arr)
arr[i] = rand(Int) % 256
end
arr
end
function processlist(arr)
sum = 0
@currymj
currymj / diffeqbayes_delay.jl
Created July 11, 2018 15:11
example of bc_model with lag parameter failing for turing inference
using DifferentialEquations
using DiffEqBayes
using Distributions
const p0 = 0.2; const q0 = 0.3; const v0 = 1; const d0 = 5
const p1 = 0.2; const q1 = 0.3; const v1 = 1; const d1 = 1
const d2 = 1; const beta0 = 1; const beta1 = 1; #const tau = 1
function bc_model(du,u,h,p,t)
du[1] = (v0/(1+beta0*(h(p, t-p[1])[3]^2))) * (p0 - q0)*u[1] - d0*u[1]
du[2] = (v0/(1+beta0*(h(p, t-p[1])[3]^2))) * (1 - p0 + q0)*u[1] +
@currymj
currymj / gp_opt_testfun.jl
Last active July 10, 2018 16:52
optimization test functions including from Kandasamy et al 2015, "High Dimensional Bayesian Optimization and Bandits"
using Distributions
using Plots
using StatsFuns
# function from Kandasamy et al
# each Fd is trimodal
struct Fd <: Function
d::Int64
v1::Vector{Float64}
@currymj
currymj / python-shell.nix
Created February 8, 2018 00:02
example python nix shell env
with import <nixpkgs> {};
let ps = pkgs.python3Packages;
in
(python3.buildEnv.override {
extraLibs = [
ps.numpy
ps.toolz
ps.notebook
ps.matplotlib
@currymj
currymj / stacktrace.txt
Created January 29, 2018 19:18
stack trace of error
(bayesopt) Michaels-MacBook-Pro-2:release_pre_alpha curry$ python run_stybtang_transform.py
[array([2, 4, 9]), array([8]), array([6, 7, 5]), array([1, 3, 0])]
Running Multi MCMC model selection BO on rotated Stybtang
12.3249773332
141.004751431
/Users/curry/src/GPy/GPy/kern/src/rbf.py:43: RuntimeWarning:overflow encountered in square
/Users/curry/src/GPy/GPy/kern/src/stationary.py:167: RuntimeWarning:overflow encountered in divide
/Users/curry/src/GPy/GPy/kern/src/rbf.py:46: RuntimeWarning:invalid value encountered in multiply
/Users/curry/anaconda3/envs/bayesopt/lib/python2.7/site-packages/paramz/transformations.py:108: RuntimeWarning:invalid value encountered in greater
/Users/curry/anaconda3/envs/bayesopt/lib/python2.7/site-packages/paramz/transformations.py:113: RuntimeWarning:invalid value encountered in greater

Keybase proof

I hereby claim:

  • I am currymj on github.
  • I am curry (https://keybase.io/curry) on keybase.
  • I have a public key ASAYThi4MBMaHHY_sPaY-F7foTp5G-eJVMhn38np7nAtYgo

To claim this, I am signing this object:

@currymj
currymj / forward_backward_tf.py
Created April 5, 2017 01:19
simple forward-backward implementation in tensorflow
import tensorflow as tf
import numpy as np
def backward_tf(transition, emission, initial_state, seq):
beta = tf.ones_like(transition[:,-1])
jrange = tf.reverse(tf.range(1,seq.get_shape()[0]),[0])
def scan_op(curr_beta, j):
return tf.reduce_sum( emission[:,seq[j]] * transition * curr_beta,1)
betas = tf.scan(scan_op, jrange, initializer=beta)
final_beta = initial_state * betas[-1,:] * emission[:,seq[0]]