Created
August 4, 2020 10:51
-
-
Save DoctorLoop/5a3837c384181b391df5927bdd5e2ab5 to your computer and use it in GitHub Desktop.
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 | |
loss += svi.step(data) | |
normalizer_train = len(trainloader.dataset) | |
total_epoch_loss_train = loss / normalizer_train | |
correct = 0 | |
total = 0 | |
for j, data in enumerate(testloader): | |
features = data["features"] | |
labels = data["outcomes"] | |
predicted = predict(features) | |
total += labels.size(0) | |
correct += (np.array(predicted) == np.array(labels)).sum().item() | |
print("accuracy: {:.3f}".format(100 * correct / total)) | |
print("Epoch ", j, " Loss ", total_epoch_loss_train) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment