pytorch贝叶斯网络
贝叶斯神经网络 (Bayesian Neural Net)
This chapter continues the series on Bayesian deep learning. In the chapter we’ll explore alternative solutions to conventional dense neural networks. These alternatives will invoke probability distributions over each weight in the neural network resulting in a single model that effectively contains an infinite ensemble of neural networks trained on the same data. We’ll use this knowledge to solve an important problem of our age: how long to boil an egg.
本章继续介绍贝叶斯深度学习系列。 在本章中,我们将探讨传统密集神经网络的替代解决方案。 这些替代方法将调用神经网络中每个权重的概率分布,从而产生一个有效包含对相同数据训练的神经网络的无限集合的单个模型。 我们将利用这些知识来解决我们这个时代的一个重要问题:煮鸡蛋要多长时间。
本章目标: (Chapter Objectives:)
- Become familiar with variational inference with dense Bayesian models 熟悉密集贝叶斯模型的变分推理
- Learn how to convert a normal fully connected (dense) neural network to a Bayesian neural network 了解如何将正常的完全连接(密集)神经网络转换为贝叶斯神经网络
- Appreciate the advantages and shortcomings of the current implementation 赞赏当前实施的优点和缺点
The data is from an experiment in egg boiling. The boil durations are provided along with the egg’s weight in grams and the finding on cutting it open. Findings are categorised into one of three classes: under cooked, soft-boiled and hard-boiled. We want the egg’s outcome from its weight and boiling time. The problem is insanely simple, so much so that the data is near being linearly separable¹. But not quite, as the egg’s pre-boil life (fridge temperature or cupboard storage at room temperature) aren’t provided and as you’ll see this swings cooking times. Without the missing data we can’t be certain what we’ll find when opening an egg up. Knowing how certain we are we can influence the outcome here as we can with most problems. In this case if relatively confident an egg’s undercooked we’ll cook it more before cracking it open.
数据来自煮鸡蛋的实验。 提供煮沸的时间以及鸡蛋的重量(克)和切开鸡蛋的发现。 调查结果分为以下三类之一:未煮熟,软煮和硬煮。 我们想要鸡蛋的重量和煮沸时间来获得结果。 这个问题非常简单,以至于数据几乎可以线性分离。 但事实并非如此,因为没有提供鸡蛋的预煮寿命(冰箱温度或橱柜在室温下存储),并且您会看到这会改变烹饪时间。 没有缺少的数据,我们将无法确定打开鸡蛋时会发现什么。 知道自己的确定性,我们可以像对待大多数问题一样在这里影响结果。 在这种情况下,如果对鸡蛋未完全煮熟有相对的把握,我们会在将其打开之前将其煮熟。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/afd92443f7ad8b50a22d12eae1eb964e.png)
Let’s have a look at the data first to see what we’re dealing with. If you want to feel the difference for yourself you can get the data at github.com/DoctorLoop/BayesianDeepLearning/blob/master/egg_times.csv. You’ll need Pandas and Matplotlib for exploring the data. (pip install — upgrade pandas matplotlib) Download the dataset to the same directory you’re working from. From a Jupyter notebook type pwd on its own in a cell to find out where that directory is if unsure.
首先让我们看一下数据,看看我们正在处理什么。 如果您想自己感觉与众不同,可以在github.com/DoctorLoop/BayesianDeepLearning/blob/master/egg_times.csv上获取数据。 您将需要Pandas和Matplotlib来浏览数据。 (pip安装-升级pandas matplotlib)将数据集下载到您正在使用的目录中。 在Jupyter笔记本中,在一个单元格中单独键入pwd,以查明该目录在哪里(如果不确定)。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/eb465538e74a0bd5256a6ab72f361876.png)
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/3154d8c75e48bee1f7c18f4d35dbb0c4.png)
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/3c3b485628b6c1dff372b5b784d2dfed.png)
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/67d7e2c3afddab9123c0dfc7c9197912.png)
And let’s see it now as a histogram.
现在让我们将其视为直方图。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/6957e5ff1669254fd6fe82748c91fb45.png)