Exemple #1
0
def guide(x, y):
    # parameters of (w : weight)
    w_loc_1 = pyro.param('w_loc_1', torch.tensor(0.))
    w_scale_1 = pyro.param('w_scale_1',
                           torch.tensor(1.),
                           constraint=constraints.positive)
    # parameters of (b : bias)
    b_loc_1 = pyro.param('b_loc_1', torch.tensor(0.))
    b_scale_1 = pyro.param('b_scale_1',
                           torch.tensor(1.),
                           constraint=constraints.positive)

    w_loc_2 = pyro.param('w_loc_2', torch.tensor(0.))
    w_scale_2 = pyro.param('w_scale_2',
                           torch.tensor(1.),
                           constraint=constraints.positive)
    b_loc_2 = pyro.param('b_loc_2', torch.tensor(0.))
    b_scale_2 = pyro.param('b_scale_2',
                           torch.tensor(1.),
                           constraint=constraints.positive)

    w1 = pyro.sample('w1', pdist.Normal(w_loc_1, w_scale_1))
    b1 = pyro.sample('b1', pdist.Normal(b_loc_1, b_scale_1))
    w2 = pyro.sample('w2', pdist.Normal(w_loc_2, w_scale_2))
    b2 = pyro.sample('b2', pdist.Normal(b_loc_2, b_scale_2))
Exemple #2
0
def model(x, y):
    w = pyro.sample('w', pdist.Normal(0., 1.))
    b = pyro.sample('b', pdist.Normal(0.5, 1.))
    # define model
    mean = w * x + b
    # variance of distribution centered around y
    # sigma = pyro.sample('sigma', pdist.Normal(0., 0.01))
    pyro.sample('obs', pdist.Normal(mean, 0.01), obs=y)
    return mean
Exemple #3
0
 def guide(data):
     # define parameters
     #  loc and scale for latent variable `z_loc`
     guide_loc = pyro.param('guide_loc', torch.tensor(0.))
     guide_scale = pyro.param('guide_scale',
                              torch.tensor(1.),
                              constraint=constraints.positive)
     # we would like to learn the distribution `loc`
     pyro.sample('z_loc', pdist.Normal(guide_loc, guide_scale))
Exemple #4
0
def guide(data):
    """ Guide is a variational distribution """

    # define parameters
    #  loc and scale for latent variable `z_loc`
    guide_loc = pyro.param('guide_loc', torch.tensor(0.))
    guide_scale = pyro.param('guide_scale', torch.tensor(0.)).exp()

    # we would like to learn the distribution `loc`
    pyro.sample('z_loc', pdist.Normal(guide_loc, guide_scale))
def model(x, y):
    w = pyro.sample('w', pdist.Normal(torch.zeros(4), torch.ones(4)))
    b = pyro.sample('b', pdist.Normal(0., 1.))

    # define logistic regression model
    y_hat = torch.sigmoid((w * x).sum(dim=1) + b)

    # variance of distribution centered around y
    # sigma = pyro.sample('sigma', pdist.Normal(0., 0.01))

    pyro.sample('obs', pdist.Bernoulli(y_hat), obs=y)
Exemple #6
0
def model(data):
    """ Model : z_loc -> x

  Args
    data : list of scalars

  """
    z_loc = pyro.sample('z_loc', pdist.Normal(0., 1.))
    with pyro.plate('data', size=len(data), dim=-1):
        # normally distributed observations
        pyro.sample('obs', pdist.Normal(z_loc, 1.), obs=data)
def guide(x, y):
    # parameters of (w : weight)
    w_loc = pyro.param('w_loc', torch.zeros(4))
    w_scale = pyro.param('w_scale',
                         torch.ones(4),
                         constraint=constraints.positive)
    # parameters of (b : bias)
    b_loc = pyro.param('b_loc', torch.tensor(0.))
    b_scale = pyro.param('b_scale',
                         torch.tensor(1.),
                         constraint=constraints.positive)

    w = pyro.sample('w', pdist.Normal(w_loc, w_scale))
    b = pyro.sample('b', pdist.Normal(b_loc, b_scale))
Exemple #8
0
def guide(x, y):
    # parameters of (w : weight)
    w_loc = pyro.param('w_loc', torch.tensor(1.))
    w_scale = pyro.param('w_scale',
                         torch.tensor(1.),
                         constraint=constraints.positive)
    # parameters of (b : bias)
    b_loc = pyro.param('b_loc', torch.tensor(0.))
    b_scale = pyro.param('b_scale',
                         torch.tensor(1.),
                         constraint=constraints.positive)
    # parameters of (sigma)
    # sigma_loc = pyro.param('sigma_loc', torch.tensor(0.), constraint=constraints.positive)  # .exp()

    # sample (w, b, sigma)
    w = pyro.sample('w', pdist.Normal(w_loc, w_scale))
    b = pyro.sample('b', pdist.Normal(b_loc, b_scale))
def model(x, y):
    w1 = pyro.sample('w1', pdist.Normal(0., 1.))
    b1 = pyro.sample('b1', pdist.Normal(3., 1.))
    w2 = pyro.sample('w2', pdist.Normal(0., 1.))
    b2 = pyro.sample('b2', pdist.Normal(3., 1.))
    w3 = pyro.sample('w3', pdist.Normal(0., 1.))
    b3 = pyro.sample('b3', pdist.Normal(3., 1.))
    # define model
    mean = w3 * torch.tanh(w2 * torch.tanh(w1 * x + b1) + b2) + b3
    pyro.sample('obs', pdist.Normal(mean, 0.01), obs=y)
    return mean
Exemple #10
0
 def model(data):
     z_loc = pyro.sample('z_loc', pdist.Normal(0., 1.))
     # normally distributed observations
     # for datapoint in data:
     pyro.sample('obs', pdist.Normal(z_loc, 1.), obs=data)