concept number in category Keras

appears as: numbers, number, numbers, The number, number
Probabilistic Deep Learning: With Python, Keras and TensorFlow Probability

This is an excerpt from Manning's book Probabilistic Deep Learning: With Python, Keras and TensorFlow Probability.

Note that the number of parameters can be vastly different, ranging from 2 in the 1D linear regression case to 500 million for advanced DL models. The whole procedure is the same as in linear regression. You will learn in chapter 3 how to fit the parameter of a non-probabilistic linear regression model.

The dice throwing experiment, where we count the successful throws with upcoming $, is an example of a general class of experiments that are called binomial experiments. In a binomial experiment you count the number of successes (here seeing a $) in n trials (here throwing a die) where all trials are independent from each other and the probability for success is the same in each trial. The number of successes in a binomial experiment with n trials is not fixed but can usually take any values between 0 and n (if p is not exactly 0 or 1). For this reason the number of success, k, is called a random variable. To emphasis that k is a random variable coming from a binomial distribution, one writes

The ~ symbol reads “stems from” or “is distributed like” a binomial with n the number of tries and p the number of successes. In the context of the book it is not so important how to derive the probability of a certain k. But there is a scipy function to calculate it, called binom.pmf with the argument k=`number of successes`, n=`number of tries` and p=`probability for success`. Using this function, we can plot the probability that 0 to 10 dollar signs occur in 10 throws. See listing 4.1 for the code and figure 4.3 for the result.

Listing 4.1 The probability for 0 to 10 red throws using the binom function
from scipy.stats import binom
ndollar = np.asarray(np.linspace(0,10,11), dtype='int') #A
pdollar_sign = binom.pmf(k=ndollar, n=10, p=1/6)  #B    
plt.stem(ndollar, pdollar_sign)
plt.xlabel('Number of dollar signs')
plt.ylabel('Probability')
Figure 4.3 Probability distribution for the number of observed dollar signs in 10 dice throws. The probability of a dollar sign in an individual throw is p=⅙. The figure is created with listing 4.1. The probability for one and two dollar signs (0.323 and 0.2907) is the same as calculated by hand.

So far so good, you might remember this from your probability class. Now we turn the tables. Consider the following situation: You are in a casino and play a game in which you win, if the dollar sign appears. You know that there are a certain number of faces (0 to 6) with the dollar sign, but you don’t know how many. You observe 10 throws of the dice and 2 dollar signs came up in those throws. What do you guess for the number of dollar signs on the dice? Surely it cannot be zero since you observed a dollar sign on the other hand it cannot be 6 either, you observed dots. But what would be a good guess? Looking at the Listing 4.1 again, you suddenly have a genius idea. Simply calculate the probabilities to observe two dollar signs in ten throws again, but this time assume that your die has not only on one face with a dollar sign but on two faces. Then assume your die has on three faces a dollar sign and again determine the probability to see two dollar signs in ten throws, and so on. So, your observed data is fixed (two dollar signs in ten throws) but your assumed model of how the data is generated changes from a dice with zero dollar faces to a dice with 1, 2, 3, 4, 5, or 6 dollar faces. The probability to observe of a dollar sign in one throw can be seen as a parameter in your model of the die and this parameter value takes the values for your different die models. For each of these dice models you can determine the probability to observe two dollar signs in ten throws and plot it in a chart (see figure 4.4).