Skip to content

Instantly share code, notes, and snippets.

View fonnesbeck's full-sized avatar

Chris Fonnesbeck fonnesbeck

  • Philadelphia Phillies
View GitHub Profile
@cs224
cs224 / pyjags_rain_sprinkler_grass_simple_bayesian_network.py
Last active October 27, 2022 17:57
Simple Bayesian Network via Monte Carlo Markov Chain in PyMC3
import math
import pyjags
import numpy as np
import pandas as pd
np.random.seed(0)
np.set_printoptions(precision=3)
def pyjags_trace():
@buo
buo / init_jupyter.sh
Created August 24, 2016 07:59
A script that automatically configures Jupyter on Cloud9
#!/bin/bash
sudo pip install jupyter
jupyter notebook --generate-config
sed -i "s/# c.NotebookApp.port = 8888/c.NotebookApp.port = $PORT/" ~/.jupyter/jupyter_notebook_config.py
sed -i "s/# c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '0.0.0.0'/" ~/.jupyter/jupyter_notebook_config.py
@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"""
@MatsuuraKentaro
MatsuuraKentaro / model.stan
Last active March 5, 2024 06:08
Tweedie distribution in Stan
data {
int N;
int M;
real<lower=0> Y[N];
}
parameters {
real<lower=0> mu;
real<lower=0> phi;
real<lower=1, upper=2> theta;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@f0k
f0k / batch_norm.py
Last active September 9, 2022 11:34
Batch Normalization for Lasagne
# -*- coding: utf-8 -*-
"""
Preliminary implementation of batch normalization for Lasagne.
Does not include a way to properly compute the normalization factors over the
full training set for testing, but can be used as a drop-in for training and
validation.
Author: Jan Schlüter
"""
@ramhiser
ramhiser / date-range.py
Last active July 5, 2022 10:55
Python generator to construct range of dates
from datetime import datetime, timedelta
def date_range(start, end, step=7, date_format="%m-%d-%Y"):
"""
Creates generator with a range of dates.
The dates occur every 7th day (default).
:param start: the start date of the date range
:param end: the end date of the date range
:param step: the step size of the dates
@jseabold
jseabold / tufte.py
Last active February 19, 2019 12:44
Recreation of Tufte graphic in Python based on an Rstats blog post and gist http://asbcllc.com/blog/2015/January/gotham_2014_weather/ https://gist.github.com/abresler/46c36c1a88c849b94b07
import os
import calendar
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FixedLocator, FixedFormatter
import pandas as pd
import seaborn as sns
to_colors = lambda x : x/255.
@minrk
minrk / foo.py
Created November 16, 2014 04:12
a=1
@takluyver
takluyver / README.md
Created September 6, 2014 21:44
Flatten notebooks for git diff

Copy nbflatten.py to somewhere on $PATH. Then, in the root of a git repository, run these commands:

echo "*.ipynb diff=ipynb" >> .gitattributes 
git config diff.ipynb.textconv nbflatten.py

When you change a notebook and run git diff, you'll see the diff of flattened, simplified notebooks, rather than the full JSON. This does lose some information (metadata, non-text output), but it makes it easier to see simple changes in the notebook.

This doesn't help with merging conflicting changes in notebooks. For that, see nbdiff.org.