This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import torch | |
| import torch.utils.data | |
| import torch.nn as nn | |
| device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") | |
| class Net(nn.Module): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # See: https://www.tensorflow.org/api_docs/python/tf/scatter_nd. | |
| # TensorFlow | |
| import tensorflow as tf | |
| sess = tf.InteractiveSession() | |
| indices = tf.constant([[0, 1], [2, 3]]) | |
| updates = tf.constant([[5, 5, 5, 5], | |
| [6, 6, 6, 6]]) | |
| shape = tf.constant([4, 4, 4]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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}, |