11
$\begingroup$

Background: I'm studying chapter 6 of Deep Learning by Ian Goodfellow and Yoshua Bengio and Aaron Courville. In section 6.2.2.2 (pages 182 of 183 which can be viewed here) the use of sigmoid to output $P(y=1|x)$ is motivated.

To summarize some of the material they let $$z = w^Th+b$$ be an output neuron before an activation is applied where $h$ is the output of the previous hidden layer, $w$ is a vector of weights and $b$ is a scalar bias. The input vector is denoted $x$ (which $h$ is a function of) and the output value is denoted $y=\phi(z)$ where $\phi$ is the sigmoid function. The book wishes to define a probability distribution over $y$ using the value $z$. From the second paragraph of page 183:

We omit the dependence on $x$ for the moment to discuss how to define a probability distribution over $y$ using the value $z$. The sigmoid can be motivated by constructing an unnormalized probability distribution $\tilde P(y)$, which does not sum to 1. We can then divide by an appropriate constant to obtain a valid probability distribution. If we begin with the assumption that the unnormalized log probabilities are linear in $y$ and $z$, we can exponentiate to obtain the unnormalized probabilities. We then normalize to see that this yields a Bernoulli distribution controlled by a sigmoidal transformation of z: \begin{align} \log\tilde P(y) &= yz \\ \tilde P(y) &= \exp(yz) \\ P(y) &= \frac{\exp(yz)}{\sum_{y'=0}^1 \exp(y'z) } \\ P(y) &= \phi((2y-1)z) \end{align}

Questions: I'm confused about two things, particularly the first:

  1. Where is the initial assumption coming from? Why is the unnormalized log probability linear in $y$ and $z$? Can someone give me some inituition on how the authors started with $\log\tilde P(y) = yz$?
  2. How does the last line follow?
$\endgroup$
7
$\begingroup$

There are two possible outcomes for $y \in \{0, 1\}$. It's very important, because this property changes meaning of the multiplication. There are two possible cases:

\begin{align} \log\tilde P(y=1) &= z \\ \log\tilde P(y=0) &= 0 \\ \end{align}

In addition important to notice that unnormalized logarithmic probability for $y=0$ is constant. This property derives from the main assumption. Applying any deterministic function to the constant value will produce constant output. This property will simplify final formula when we will do normalization over all possible probabilities, because we just need to know only unnormalized probability for $y=1$ and for $y=0$ it's always constant. And since output from the network in unnormalized logarithmic probability we will require only one output, because another one assumed to be constant.

Next, we are applying exponentiation to the unnormalized logarithm probability in order to obtain unnormalized probability.

\begin{align} \tilde P(y=1) &= e ^ z \\ \tilde P(y=0) &= e ^ 0 = 1 \end{align}

Next we just normalize probabilities dividing each unnormalized probability by the sum of all possible unnormalized probabilities.

\begin{align} P(y=1) = \frac{e ^ z}{1 + e ^ z} \\ P(y=0) = \frac{1}{1 + e ^ z} \end{align}

We are interested only in $P(y=1)$, because that's what probability from the sigmoid function means. The obtained function doesn't look like sigmoid on the first look, but they are equal and it's easy to show.

\begin{align} P(y=1) = \frac{e ^ x}{1 + e ^ x} = \frac{1}{\frac{e ^ x + 1}{e ^ x}} = \frac{1}{1 + \frac{1}{e ^ x}} = \frac{1}{1 + e ^ {-x}} \end{align}

The last statement can be confusing at first, but it just a way to show that that final probability function is a sigmoid. The $(2y−1)$ value converts $0$ to $-1$ and $1$ to $1$ (or we can say that it would be without change).

$$ P(y) = \sigma((2y - 1)z) = \begin{cases} \sigma(z) = \frac{1}{1 + e ^ {-z}} = \frac{e ^ z}{1 + e ^ z} & \text{when } y = 1 \\ \sigma(-z) = \frac{1}{1 + e ^ {-(-z)}} = \frac{1}{1 + e ^ z} & \text{when } y = 0 \\ \end{cases} $$

As we can see, it just the way to show the relation between $\sigma$ and $P(y)$

$\endgroup$
  • $\begingroup$ "In addition important to notice that unnormalized logarithmic probability for $y=0$ is constant. This property derives from the main assumption." The assumption being that we've already decided that $y=1$? $\endgroup$ – HBeel Mar 25 '17 at 13:27
  • $\begingroup$ I think my confusion came from the fact that the sigmoid gives the model's probability of $y=1$ regardless of the actual label. Thanks! $\endgroup$ – HBeel Mar 25 '17 at 13:33
  • $\begingroup$ Don't mean to be thick here but how is $y\times z$ linear in $y$ and $z$. I would expect something of the form $ay + bz + c$. I realize that $\log$ on the product $yz$ would yield a sum which would take me closer to linearity but that does not seem to be direct from what the author stated. $\endgroup$ – zebullon Dec 18 '17 at 4:46
  • $\begingroup$ I see, that's actually interesting question. I didn't pay attention to this statement when I read question for the first time. Now it looks odd to me as well. One problem is that y binary variable and I'm not sure how to check properties of the linear function under these circumstances. I guess it will make sense if you ask separate questions, maybe somebody can explain you why it has been written in this way. $\endgroup$ – itdxer Dec 18 '17 at 10:04
1
$\begingroup$

I also find this fragment of the book challenging to follow, and the above answer by itdxer deserves quite some time to understand as well for someone who's not properly fluent with probabilities and maths thinking. I made it however by reading the answer backwards, so start with the sigmoid of z

\begin{align} P(y=1) = \frac{e ^ z}{1 + e ^ z} = \frac{1}{1 + e ^ {-z}} \end{align}

and try to follow back to.

\begin{align} \log\tilde P(y) &= yz \end{align}

Then it makes sense why they started the explanation with yz - it's by design, same as the final

\begin{align} \sigma((2y-1)z) \end{align}

by construction allows to get -1 for y=0 and 1 for y=1, which are the only possible values of y under the Bernoulli.

$\endgroup$
0
$\begingroup$

Here's a more formal phrasing that will appeal to those with a measure-theoretic background.

Let $Y$ be a Bernoulli r.v. and let $P_Y$ denote the pushforward measure, i.e for $y\in \{0,1\}$, $P_Y(y)=P(Y=y)$ and let $\tilde P_Y$ denote its unnormalized counterpart.

We have the following chain of implications:

$$\begin{aligned} \log \tilde P_Y(y)=yz &\implies \tilde P_Y(y) = \exp(yz)\\ &\implies P_Y(y) = \frac{e^{yz}}{e^{0\cdot z}+e^{1\cdot z}}=\frac{e^{yz}}{1+e^{ z}}\\ &\implies P_Y(y) =y\frac{e^{z}}{1+e^{ z}} + (1-y)\frac{1}{1+e^{ z}}\\ &\implies P_Y(y) =y\sigma(z) + (1-y)\sigma(-z)\\ &\implies P_Y(y) = \sigma((2y-1)z) \end{aligned}$$

The last equality is a smart way of mapping $\{0,1\}$ to $\{-1,1\}$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.