Skip to content

Instantly share code, notes, and snippets.

View airalcorn2's full-sized avatar

Michael A. Alcorn airalcorn2

View GitHub Profile
@airalcorn2
airalcorn2 / gdp.csv
Created November 2, 2016 17:29
Comparing fiscal policies and GDP to poverty rates in different countries.
Rank Country GDP (millions of Int$)
World 119,097,427
1 China 21,269,017
European Union[n 1] 19,973,035
2 United States 18,561,934
3 India 8,720,514
4 Japan 4,931,877
5 Germany 3,979,083
6 Russia 3,745,084
7 Brazil 3,134,892
@airalcorn2
airalcorn2 / d_stat_experiment.py
Last active December 22, 2016 00:05
Kolmogorov–Smirnov statistic experiment.
# Michael A. Alcorn ([email protected])
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import numpy as np
import statsmodels.api as sm # recommended import according to the docs
import matplotlib.pyplot as plt
# Michael A. Alcorn ([email protected])
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import random
fixed_rates = {"p_1": 0.3, "p_2": 0.5}
find_rates = {"biased": {"fixed": 0.7, "non_fixed": 0.9},
kernels = model.layers[0].get_weights()[0].T
(rows, cols) = (8, 4)
plt.figure(figsize = (16, 24))
gs = gridspec.GridSpec(rows, cols, wspace = 0.1, hspace = 0.1)
for i in range(kernels.shape[0]):
row = i // cols
col = i % cols
ax = plt.subplot(gs[row, col])
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
from keras import backend
from keras.layers import Input, Dense
from keras.models import Model
# Autoencoder.
@airalcorn2
airalcorn2 / species_plots.py
Last active April 13, 2018 17:40
Python code to generate the plots used to make this GIF --> http://imgur.com/BjgN6UA.
# Michael A. Alcorn
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import multiprocessing
import numpy as np
import pandas as pd
import seaborn as sns
import time
@airalcorn2
airalcorn2 / clade_counts.py
Created April 13, 2018 18:54
A script for counting the total species in each clade in a Newick formatted file.
# Michael A. Alcorn
from Bio import Phylo
tree = Phylo.read("species_newick.txt", "newick")
clade_counts = {}
for clade in tree.find_clades():
if not clade.is_terminal():
clade_counts[str(clade)] = clade.count_terminals()
# Michael A. Alcorn
library(ggplot2)
library(plyr)
data <- read.csv("species.csv")
data$Date <- as.Date(data$Date, "%Y-%m-%d")
ggplot(data, aes(Date, Total)) + geom_line() + scale_x_date(date_breaks = "1 month")
@airalcorn2
airalcorn2 / attention_grok.py
Last active March 21, 2020 14:10
A barebones PyTorch implementation of a seq2seq model with attention.
# Michael A. Alcorn
import torch
import torch.autograd as autograd
import torch.nn as nn
def create_lstm(params):
"""Create a LSTM from a dictionary of parameters.
@airalcorn2
airalcorn2 / rtw_fatalities.py
Created July 3, 2018 16:36
Plotting fatality rates for states that had a change in right-to-work laws from this paper --> https://oem.bmj.com/content/early/2018/06/13/oemed-2017-104747.
# Michael A. Alcorn
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("repdata.tab", sep = "\t", index_col = False)
no_law = set(df[df["RTW"] == 0]["state"])
yes_law = set(df[df["RTW"] == 1]["state"])
states_that_changed = list(no_law & yes_law)
states_that_changed.sort()