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
plt.hist(baby_predictions, color='g', alpha=0.4, histtype='step', label='Babies', fill=True, linewidth=4, density=True) | |
plt.hist(spider_predictions, color='r', alpha=0.4, histtype='step', label='Spiders', fill=True, linewidth=4, density=True) | |
plt.xlabel('Predicted Height (pixels)') | |
plt.ylabel("Density") | |
plt.legend() |
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
baby_predictions = [model.predict(np.expand_dims(new_baby, [0]))[0,0] for i in range(1000)] | |
spider_predictions = [model.predict(np.expand_dims(spider, [0,-1]))[0,0] for i in range(1000)] |
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
batch_size = 5 | |
history = model.fit(x=images_, | |
y=np.array(labels), | |
epochs=250, | |
verbose=1, | |
batch_size=batch_size, | |
validation_split=0.1, | |
validation_freq=5) |
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() | |
kl_divergence_function = lambda q, p, _: dist.kl_divergence(q, p) / tf.cast(836, dtype=tf.float32) | |
model = tf.keras.Sequential([ | |
tf.keras.Input(shape=(126,126,1),name="basket"), | |
tfp.layers.Convolution2DFlipout(16, kernel_size=5, strides=(1,1), data_format="channels_last", | |
padding="same", activation=tf.nn.relu, name="conv_tfp_1a", | |
kernel_divergence_fn=kl_divergence_function), |
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
plt.hist(underdone['time'], color='r', alpha=0.6, histtype='step', label='underdone', fill=True, linewidth=2) | |
plt.hist(softboiled['time'], color='y', alpha=0.6, histtype='step', label='soft-boiled', fill=True, linewidth=2) | |
plt.hist(hardboiled['time'], color='g', alpha=0.6, histtype='step', label='hard-boiled', fill=True, linewidth=2) | |
plt.xlabel('time (g)') | |
plt.ylabel("number examples") | |
plt.legend() |
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 matplotlib.pyplot as plt | |
plt.scatter(hardboiled['weight'],hardboiled['time'],color='g',marker="^",label="hard-boiled") | |
plt.scatter(softboiled['weight'],softboiled['time'],color='y',marker="o",label="soft-boiled") | |
plt.scatter(underdone['weight'],underdone['time'],color='r', marker="+",label="underdone") | |
plt.xlabel('weight (g)') | |
plt.ylabel("time (mins)") | |
plt.legend() |
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() |
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
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
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 |
NewerOlder