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
violin_parts = plt.violinplot(underdone['time'], positions=[0], showmeans=True) | |
# over-ride default blue color, you can't use 'color' parameter as can on histograms etc | |
for pc in violin_parts['bodies']: # used to | |
pc.set_facecolor('red') | |
violin_parts['cbars'].set_edgecolor('red') | |
violin_parts['cmaxes'].set_edgecolor('red') | |
violin_parts['cmins'].set_edgecolor('red') | |
violin_parts['cmeans'].set_edgecolor('red') | |
plt.violinplot(softboiled['time'], positions=[0.5], showmeans=True) | |
plt.violinplot(hardboiled['time'], positions=[1], showmeans=True) |
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
tf.keras.backend.clear_session() | |
model = tf.keras.Sequential([ | |
tf.keras.Input(shape=(2,),name="basket"), | |
tf.keras.layers.Dense(16, activation="relu", name="dense_1"), | |
tf.keras.layers.Dense(6, activation="relu", name="dense_2"), | |
tf.keras.layers.Dense(3, activation="softmax", name="out_pred"), | |
]) | |
learning_rate = 1.0e-4 |
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
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir="./logs/egg_times", histogram_freq=1) | |
history = model.fit(train_, | |
target_, | |
epochs=800, | |
verbose=0, | |
use_multiprocessing=True, | |
callbacks=[tensorboard_callback], | |
validation_split=0.1, | |
validation_freq=20) |
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
class DenseModel(nn.Module): | |
def __init__(self, num_in): | |
super(DenseModel, self).__init__() | |
self.fc1 = nn.Linear(num_in, 16) | |
self.fc2 = nn.Linear(16, 6) | |
self.fc3 = nn.Linear(6, 3) | |
def forward(self, x): |
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
for epoch in range(800): | |
running_loss = [] | |
for i, batch in enumerate(trainloader): | |
inputs = batch["features"] | |
labels = batch["outcomes"] | |
optimizer.zero_grad() |
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 model(data): | |
fc1w_prior = dist.Normal(loc=torch.zeros_like(dense.fc1.weight), scale=torch.ones_like(dense.fc1.weight)) | |
fc1b_prior = dist.Normal(loc=torch.zeros_like(dense.fc1.bias), scale=torch.ones_like(dense.fc1.bias)) | |
fc2w_prior = dist.Normal(loc=torch.zeros_like(dense.fc2.weight), scale=torch.ones_like(dense.fc2.weight)) | |
fc2b_prior = dist.Normal(loc=torch.zeros_like(dense.fc2.bias), scale=torch.ones_like(dense.fc2.bias)) | |
fc3w_prior = dist.Normal(loc=torch.zeros_like(dense.fc3.weight), scale=torch.ones_like(dense.fc3.weight)) | |
fc3b_prior = dist.Normal(loc=torch.zeros_like(dense.fc3.bias), scale=torch.ones_like(dense.fc3.bias)) | |
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
optim = pyro.optim.Adam({"lr": 0.001}) | |
svi = SVI(model, guide, optim, loss=Trace_ELBO()) | |
num_iterations = 50 | |
loss = 0 | |
for j in range(num_iterations): | |
loss = 0 | |
for batch_id, data in enumerate(trainloader): | |
# calculate the loss and take a gradient step |
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
ax1 = plt.subplot(1,3,1) | |
ax1.hist(predicted[:,1].reshape(-1,1),bins=[0,1,2,3],density=False, hatch="/", color='r', edgecolor='black') | |
ax = plt.subplot(1,3,2, sharey=ax1) | |
ax.hist(predicted[:,49].reshape(-1,1),bins=[0,1,2,3],density=False, color='g', edgecolor='black') | |
ax = plt.subplot(1,3,3,sharey=ax1) | |
ax.hist(predicted[:,13].reshape(-1,1),bins=[0,1,2,3],density=False, hatch=".", edgecolor='black') |
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
num_samples = 5000 | |
predicted = [] | |
for i in range(num_samples): | |
features = test_dataset.df.sample(n=3).drop('outcome',axis=1) | |
batch_predictions = predict(torch.tensor(features.values)) | |
predicted.append(batch_predictions) |
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 pandas as pd | |
egg_timing_df = pd.read_csv("egg_times.csv",index_col=0) | |
egg_timing_df.head() |
OlderNewer