Skip to content

Instantly share code, notes, and snippets.

View brendancooley's full-sized avatar

Brendan Cooley brendancooley

View GitHub Profile
@omarfsosa
omarfsosa / neg_binomial_2_rng.py
Created January 27, 2021 16:06
Sample from a negative binomial in terms of mean and precision parameters
import numpy as np
def neg_binomial_2_rng(mu, phi, size=None):
"""
RNG for the negative binomial parametrised in terms
of the mean and the precision.
mean = mu
variance = mu + (mu**2)/phi
"""
tau = np.random.gamma(phi, mu/phi, size=size)
@arthurattwell
arthurattwell / split.sh
Last active November 24, 2021 11:52
Split a markdown file into separate files on YAML frontmatter
#!/bin/bash
# That tells Linux to use a Bourne shell interpreter.
# Run this script from the current directory. (Required on OSX.)
cd -- "$(dirname "$0")"
# Don't echo these commands.
set +v
# Get the filename from the user.
@mikelove
mikelove / rmosek
Created December 29, 2017 00:44
How to install Rmosek
1) Download mosek from here:
https://www.mosek.com/downloads/
(I downloaded this to my ~/bin)
cd ~/bin
tar -xvf mosektoolslinux64x86.tar.bz2
2) Add this to your ~/.bashrc
export PATH=$PATH:/home/username/bin/mosek/8/tools/platform/linux64x86/bin
@bmmalone
bmmalone / Makefile
Created March 9, 2017 09:06
Makefile to use pandoc to convert all markdown files to html and pdf
# Makefile
#
# Converts Markdown to other formats (HTML, PDF) using Pandoc
# <http://johnmacfarlane.net/pandoc/>
#
# Run "make" (or "make all") to convert to all other formats
#
# Run "make clean" to delete converted files
#
# Adapted from: https://gist.github.com/kristopherjohnson/7466917
@ctufts
ctufts / group_by_and_ggplot.R
Created July 11, 2016 19:56
dplyr group_by and ggplot example
plot_df <-df %>% group_by(feature) %>%
do(
plots = ggplot(data = .) + aes(x = xcol, y = ycol) +
geom_point() + ggtitle(.$feature)
)
# show plots
plot_df$plots
@mblondel
mblondel / projection_simplex.py
Last active May 16, 2024 16:53
Projection onto the simplex
"""
License: BSD
Author: Mathieu Blondel
Implements three algorithms for projecting a vector onto the simplex: sort, pivot and bisection.
For details and references, see the following paper:
Large-scale Multiclass Support Vector Machine Training via Euclidean Projection onto the Simplex
Mathieu Blondel, Akinori Fujino, and Naonori Ueda.
@rochacbruno
rochacbruno / haversine.py
Created June 6, 2012 17:43
Calculate distance between latitude longitude pairs with Python
#!/usr/bin/env python
# Haversine formula example in Python
# Author: Wayne Dyck
import math
def distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination