piEsposito / blitz-bayesian-deep-learning

A simple and extensible library to create Bayesian Neural Network layers on PyTorch.
GNU General Public License v3.0
918 stars 107 forks source link

Providing a minimal working example #81

Closed j0rd1smit closed 3 years ago

j0rd1smit commented 3 years ago

I really like the idea of this library. However, it is really hard to get started with it. For example, the minimal working example in the read me doesn't work. No matter what I try, I cannot get it to improve the accuracy. The loss decrease towards zero, but the accuracy doesn't change. The problem is that it is totally unclear why this is the case is it because:

Any help would be appreciated.

piEsposito commented 3 years ago

Hello @j0rd1smit, and thank you so much for using BLiTZ.

I will give it a look on the weekend and come back to you. If your problem is related to a specific modelling task, you can reach me on the email on my profile, so I can try to help you.

Anyway, sorry it did not yet work for you, but I'm here and will help you in any way I can.

j0rd1smit commented 3 years ago

I really appreciate the help. It would already be a great help if the readme example worked such that I can base my implementation on it.

If you are interested, I can tell you a bit more about what I want to do using this library. In my current project, I'm trying to visualize different uncertainty measure in DL. So, I'm trying to create plots like this for each method: example This plot is from an ensemble method. However, I also want a plot like this for a BNN.

If you want to try it out the dataset is generated using:

def make_x_train(n_samples=1000, seed=2):
    np.random.seed(seed)
    return 5 * np.sign(np.random.randn(n_samples)) + np.random.randn(n_samples).clip(-2, 2)

def make_y_data(x, noise=0.05, seed=2):
    n_samples = len(x)

    # make some random sines & cosines
    np.random.seed(seed)
    W = np.random.randn(30, 1)
    b = np.random.rand(30, 1) * 2 * np.pi

    y = np.cos(W * x + b).sum(0) + noise * np.random.randn(n_samples)
    return y

seed = 2
n_samples = 500

x = make_x_train(n_samples=n_samples, seed=seed)
y = make_y_data(x, seed=seed)
x_line = np.linspace(min(x)-5, max(x) + 5, 500)
y_line = make_y_data(x_line, seed=seed)
j0rd1smit commented 3 years ago

@piEsposito, did you have a chance to look at it?

victor-yon commented 3 years ago

I tested the example from the Readme file, the training is slow but it seems to work.

I got this after 47000 training iterations :

CI acc: 0.99, CI upper acc: 0.99, CI lower acc: 1.00 Loss: 69.8541

piEsposito commented 3 years ago

@victor-yon thank you for answering that. I'll close it.