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 | |
| csv_url = "https://raw.githubusercontent.com/gradlab/CtTrajectories/main/data/ct_dat_clean.csv" | |
| df = pd.read_csv(csv_url) | |
| person_ids = df["Person.ID"].unique() | |
| (min_x, max_x) = (df["Date.Index"].min(), df["Date.Index"].max()) |
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 seaborn as sns | |
| households = 10000 | |
| infected_households_prop = 0.01 | |
| persons_per_household = 100 | |
| sample_prop = 0.001 | |
| samples = int(sample_prop * households * persons_per_household) |
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
| # This bug was fixed in PyTorch 1.9. See: | |
| # https://github.com/pytorch/pytorch/commit/aec83ff45ebd2cb3d4890cc97bffb1f367386392. | |
| # See: https://pytorch.org/docs/stable/notes/faq.html#my-data-loader-workers-return-identical-random-numbers | |
| # and: https://pytorch.org/docs/stable/data.html#multi-process-data-loading | |
| # and: https://pytorch.org/docs/stable/data.html#randomness-in-multi-process-data-loading. | |
| import numpy as np | |
| import torch |
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 numpy as np | |
| A = np.array([[1, 1, 1], [2, 2, 2], [5, 5, 5]]) | |
| B = np.array([[0, 1, 0], [1, 1, 0], [1, 1, 1]]) | |
| (i_s, j_s, k_s) = (len(A), len(A[0]), len(B[0])) | |
| for do_sum in [True, False]: | |
| if do_sum: | |
| C = np.zeros((i_s, k_s)) | |
| print(np.einsum("ij,jk->ik", A, B)) |
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 networkx as nx | |
| import numpy as np | |
| import seaborn as sns | |
| def sim_outbreak(G, exps, inf_prob, init_infect, lock): | |
| pop_size = len(G) | |
| total_infected = [] | |
| for exp in range(exps): |
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
| # Create PDF montage from a directory of images. | |
| montage -tile 2x100 "test/*" final.png | |
| convert final.png final.pdf |
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 | |
| import matplotlib.cm as cm | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import pandas as pd | |
| import pgeocode | |
| import re | |
| import seaborn as sns | |
| from datetime import datetime |
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 numpy as np | |
| import matplotlib.pyplot as plt | |
| from scipy.optimize import linprog | |
| A_ub = np.eye(3) | |
| b_ub = np.ones(3) | |
| A_eq = np.array([[0.95, 0.9, 0.15]]) | |
| b_eq = np.ones(1) | |
| c = -np.array([0.9, 0.02, 0.08]) |
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
| # Derived from: https://github.com/pydicom/pydicom/blob/master/examples/input_output/plot_read_dicom_directory.py. | |
| import imageio | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import pydicom | |
| from os import mkdir | |
| from os.path import join | |
| from PIL import Image |
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 os | |
| from PIL import Image | |
| image_fs = os.listdir() | |
| image_fs.sort() | |
| image_fs = image_fs[:9] | |
| images = map(Image.open, image_fs) | |
| (widths, heights) = zip(*(i.size for i in images)) |