Skip to content

Instantly share code, notes, and snippets.

View brandonwillard's full-sized avatar

Brandon T. Willard brandonwillard

View GitHub Profile
# -*- coding: utf-8 -*-
"""
example use of pandas with oracle mysql postgresql sqlite
lightly tested.
to do:
save/restore index (how to check table existence? just do select count(*)?),
finish odbc,
add booleans?,
sql_server?
@brandonwillard
brandonwillard / sparse-matrix-fix.R
Last active March 12, 2018 14:58
Slow fix for creating large sparse matrices with interactions
library(Rcpp)
#library(RcppProgress)
#library(RcppParallel)
{
code = '
// [[Rcpp::depends(RcppProgress, RcppArmadillo, RcppParallel)]]
#define ARMA_64BIT_WORD
#include <RcppArmadillo.h>
#include <RcppParallel.h>
@brandonwillard
brandonwillard / gist:dab0b21099ea88ad3545
Created May 18, 2015 20:14
glmnet work-around for a single column design matrix
local({
myglmnet = function(x, y, family = c("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"), weights, offset = NULL, alpha = 1, nlambda = 100, lambda.min.ratio = ifelse(nobs < nvars, 0.01, 1e-04), lambda = NULL, standardize = TRUE, intercept = TRUE, thresh = 1e-07, dfmax = nvars + 1, pmax = min(dfmax * 2 + 20, nvars), exclude, penalty.factor = rep(1, nvars), lower.limits = -Inf, upper.limits = Inf, maxit = 1e+05, type.gaussian = ifelse(nvars < 500, "covariance", "naive"), type.logistic = c("Newton", "modified.Newton"), standardize.response = FALSE, type.multinomial = c("ungrouped", "grouped")) {
family = match.arg(family)
if (alpha > 1) {
warning("alpha >1; set to 1")
alpha = 1
}
if (alpha < 0) {
warning("alpha<0; set to 0")
@brandonwillard
brandonwillard / cm-functions-plot.ipynb
Created November 15, 2015 17:00
Investigate CM Functions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brandonwillard
brandonwillard / config.py
Last active June 27, 2016 03:23
qtile config
# -*- coding: utf-8 -*-
#
# Check out org.mate.panel in dconf. It has a `.toplevels`
# section with `bottom` and `top` entries that provide the
# mate-panel dimensions and screen id.
# Seems like those could be read and used by qtile.
#
#
@brandonwillard
brandonwillard / mvnormal-extension.py
Created May 18, 2016 20:36
Somewhat fixed MvNormal implementation
from scipy import stats
from theano.tensor.nlinalg import det, matrix_inverse, trace, eigh
from pymc3 import transforms
from pymc3.distributions.distribution import Continuous, Discrete, draw_values, generate_samples
from pymc3.distributions.special import gammaln, multigammaln
from pymc3.distributions.dist_math import bound, logpow, factln
class MvNormal(Continuous):
r"""
@brandonwillard
brandonwillard / Sympy Mixture Model Test.ipynb
Created June 17, 2016 21:18
Sympy Mixture Model Moments Test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brandonwillard
brandonwillard / curious_incident_stan.R
Last active July 31, 2016 00:55
Inverse Mean Reparameterization Simulation
#
# Simple inspection of an inverse mean reparameterization for observations
# x ~ N(theta, 1)
# and theta = 1/u.
# Original discussion: https://xianblog.wordpress.com/2016/07/15/the-curious-incident-of-the-inverse-of-the-mean/
#
# Authors: Jyotishka Datta and Brandon T. Willard
#
library(rstan)
rstan_options(auto_write = TRUE)
@brandonwillard
brandonwillard / SURE_plot.py
Created August 23, 2016 19:39
Plot SURE estimates
import numpy as np
from hsplus.special_funcs import sure_hib
alpha_d_range = np.linspace(-100, 100, 200)
sigma = 1.
tau = 1.
from timeit import default_timer as timer
start = timer()
sure_range = sure_hib(alpha_d_range, sigma, tau)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.