This file contains 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
# Load trajectory data | |
traj_X = np.genfromtxt('./Dataset/traj_X.csv', delimiter=',') | |
traj_Y = np.genfromtxt('./Dataset/traj_Y.csv', delimiter=',') | |
# Display a single trajectory | |
fig, ax = plt.subplots(figsize=(8,3)) | |
pick_traj = 5 | |
ax.plot(traj_X[pick_traj,:],traj_Y[pick_traj,:], | |
color='b', lw=2, linestyle='--') |
This file contains 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 matplotlib import animation | |
from IPython.display import HTML | |
from celluloid import Camera | |
%matplotlib inline | |
# Animate a single trajectory | |
pick_traj = 5 # Select a trajectory to simulate |
This file contains 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 individual frames | |
for i in range(0,30): | |
for j in range(1,traj_X.shape[1]+1): | |
# Projectile's trajectory | |
x = traj_X[i][0:j] | |
y = traj_Y[i][0:j] | |
# Show Projectile's location | |
ax.plot(x[-1], y[-1], marker='o', markersize=12, |
This file contains 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
# Extract range data | |
Range = traj_X[:,-1] | |
# Extract bins | |
n, bins, patches = plt.hist(Range, bins=10, edgecolor='black') | |
plt.close() |
This file contains 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
# Set up the histogram axis | |
ax_hist = ax.twinx() # Make an identical copy | |
ax_hist.set_ylim(0, 10.2) | |
ax_hist.set_yticks(list(range(0,10,2))) | |
ax_hist.set_ylabel('Count', fontsize=15) | |
# Initiate camera | |
camera = Camera(fig) | |
# A list of range values |
This file contains 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
# Data analysis | |
import pandas as pd | |
import numpy as np | |
# Simulate SIR model | |
from scipy.integrate import odeint | |
# Sampling | |
from pyDOE import lhs | |
from scipy.stats.distributions import norm |
This file contains 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
def SIR_model(beta, gamma, t, N, I0, R0): | |
"""The function solves the SIR model to simulate | |
the disease spreading""" | |
S0 = N - I0 - R0 | |
def deriv(y, t, N, beta, gamma): | |
S, I, R = y | |
dSdt = -beta * S * I / N | |
dIdt = beta * S * I / N - gamma * I |
This file contains 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
# Assign infection and recovery rate parameters | |
beta, gamma = 0.22, 0.1 | |
# Grid of time points (in days) | |
t = np.arange(0, 101, 2) | |
# Run SIR model to predict epidemic evolution | |
S, I, R = SIR_model(beta, gamma, t, I0=8, N=1000, R0=0) | |
# Extract output of interest |
This file contains 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
# Specify random sample number | |
sample_num = 1000 | |
# Using Latin Hypercube method to generate uniform distribution | |
uni_samples = lhs(n=2, samples=sample_num, criterion='maximin') |
This file contains 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
# Transforming to standard normal distribution | |
std_norm_samples = np.zeros_like(uni_samples) | |
for i in range(2): | |
std_norm_samples[:,i] = norm(loc=0, scale=1).ppf(uni_samples[:,i]) |
OlderNewer