- Thor::Util#snake_case: well-isolated test cases. Clear and thorough about expected behavior with potentially ambiguous input
- HTTParty.normalize_base_uri: describes behavior well for a method that might be confusing at first
- Virtus::Attribute#==: good use of intermediate variable for clarity. tests are collectively exhaustive within the scope of the method
- AASM::Core::Event#fire: good isolation of complex behavior; good use of mocks and doubles. when/then/expect division is clear (BDD). good use of context
- [Money.from_amount](https://gi
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 pymc3 as pm | |
def posterior_upvote_ratio(upvotes, downvotes, samples = 20000): | |
“”” | |
This function accepts the number of upvotes and downvotes a particular submission recieved, | |
and the number of posterior samples to return to the user. Assumes a uniform prior. | |
“”” | |
N = upvotes + downvotes | |
with pm.Model() as model: | |
upvote_ratio = pm.Uniform(“upvote_ratio”, 0, 1) # (1) |
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 torch | |
import pyro | |
import pyro.distributions as dist | |
from pyro.infer import SVI, Trace_ELBO | |
from pyro.optim import Adam |
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
from __future__ import print_function | |
import math | |
import os | |
import torch | |
import torch.distributions.constraints as constraints | |
import pyro | |
from pyro.optim import Adam | |
from pyro.infer import SVI, Trace_ELBO | |
import pyro.distributions as dist |
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
pyro.enable_validation(True) | |
pyro.clear_param_store() |
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
# Tiger Jason James | |
data = torch.cat((torch.zeros(9), torch.ones(7), torch.empty(4).fill_(2.))) |
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): | |
alpha = torch.tensor(6.0) | |
beta = torch.tensor(10.0) | |
pay_probs = pyro.sample('pay_probs', dist.Beta(alpha, beta).expand(3).independent(1)) | |
normalized_pay_probs = pay_probs / torch.sum(pay_probs) | |
with pyro.iarange('data_loop', len(data)): | |
pyro.sample('obs', dist.Categorical(probs=normalized_pay_probs), obs=data) |
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 guide(data): | |
alphas = pyro.param('alphas', torch.tensor(6.).expand(3), constraint=constraints.positive) | |
betas = pyro.param('betas', torch.tensor(10.).expand(3), constraint=constraints.positive) | |
pyro.sample('pay_probs', dist.Beta(alphas, betas).independent(1)) |
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 print_progress(): | |
alphas = pyro.param("alphas") | |
betas = pyro.param("betas") | |
if torch.cuda.is_available(): | |
alphas.cuda() | |
betas.cuda() | |
means = alphas / (alphas + betas) | |
normalized_means = means / torch.sum(means) |
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
adam_params = {"lr": 0.0005} | |
optimizer = Adam(adam_params) | |
svi = SVI(model, guide, optimizer, loss=Trace_ELBO()) | |
n_steps = 2501 | |
for step in range(n_steps): | |
svi.step(data) | |
if step % 100 == 0: | |
print_progress() |