# %% Avoid issuing memory warning due to number of plots

plt.rcParams.update({'figure.max_open_warning': 0})

# %% Load Iris data

iris = XYDataset.from_eeyore('iris',
                             yndmin=1,
                             dtype=torch.float32,
                             yonehot=True)
dataloader = DataLoader(iris, batch_size=len(iris), shuffle=True)

# %% Setup MLP model

hparams = mlp.Hyperparameters(dims=[4, 3, 3],
                              activations=[torch.sigmoid, None])
model = mlp.MLP(loss=loss_functions['multiclass_classification'],
                hparams=hparams,
                dtype=torch.float32)
model.prior = Normal(
    torch.zeros(model.num_params(), dtype=model.dtype),
    (3 * torch.ones(model.num_params(), dtype=model.dtype)).sqrt())

# %% Setup MALA sampler

sampler = MALA(model,
               theta0=model.prior.sample(),
               dataloader=dataloader,
               step=0.003)

# %% Run MALA sampler
Beispiel #2
0
# %% Import packages

import numpy as np
import torch

from torch.distributions import Normal

from eeyore.constants import loss_functions
from eeyore.models import mlp

from bnn_mcmc_examples.examples.mlp.pima.setting2.constants import dtype, mlp_dims, mlp_bias, mlp_activations

# %% Setup MLP model

hparams = mlp.Hyperparameters(dims=mlp_dims,
                              bias=mlp_bias,
                              activations=mlp_activations)

model = mlp.MLP(loss=loss_functions['binary_classification'],
                hparams=hparams,
                dtype=dtype)

prior_scale = np.sqrt(10.)

model.prior = Normal(
    torch.zeros(model.num_params(), dtype=model.dtype),
    torch.full([model.num_params()], prior_scale, dtype=model.dtype))
Beispiel #3
0
# %% Import packages

import numpy as np
import torch

from torch.distributions import Normal

from eeyore.constants import loss_functions
from eeyore.models import mlp

from bnn_mcmc_examples.examples.mlp.exact_xor.constants import dtype, mlp_dims

# %% Setup MLP model

hparams = mlp.Hyperparameters(dims=mlp_dims)

model = mlp.MLP(loss=loss_functions['binary_classification'],
                hparams=hparams,
                dtype=dtype)

prior_scale = np.sqrt(10.)

model.prior = Normal(
    torch.zeros(model.num_params(), dtype=model.dtype),
    torch.full([model.num_params()], prior_scale, dtype=model.dtype))