Conversion from sum of product to product of sum

4.9k Views Asked by At

I do not understand how did he convert from this to this.

enter image description here

Source :http://cs229.stanford.edu/notes/cs229-notes1.pdf Page 18

2

There are 2 best solutions below

0
On BEST ANSWER

It uses the below logarithmic properties:

$(1) ~~~~~\log(a \cdot b) = \log a + \log b$

$(2) ~~~~~\log a^b = b \cdot \log a$

At first, you have $$ \log L(\theta) = \log \left( \prod_{i=1}^m \left(h_\theta(x^{(i)})\right)^{y^{(i)}}\left(1 - h_\theta(x^{(i)})\right)^{1-y^{(i)}}\right) $$ By the first equation, the product in the argument of $\log$ becomes a sum of $\log$s. $$ \log L(\theta) = \sum_{i=1}^m \left( \log \left( h_\theta(x^{(i)})\right)^{y^{(i)}}\left(1 - h_\theta(x^{(i)}) \right)^{1-y^{(i)}}\right) $$

But, again because of the first equation, you have that

$\log \left( h_\theta(x^{(i)})\right)^{y^{(i)}}\left(1 - h_\theta(x^{(i)}) \right) = \log\left( h_\theta(x^{(i)})\right)^{y^{(i)}} + \log \left( 1- h_\theta(x^{(i)})\right)^{1-y^{(i)}}$

And then, because of equation (2), you have

$\log\left( h_\theta(x^{(i)})\right)^{y^{(i)}} + \log \left( 1-h_\theta(x^{(i)})\right)^{1-y^{(i)}} = y^{(i)} \log (h_\theta(x^{(i)})) + (1-y^{(i)})\log\left( 1-h_\theta(x^{(i)})\right)$

In the end, you get $$ \log L(\theta) = \sum_{i=1}^m \left( y^{(i)} \log (h_\theta(x^{(i)})) + (1-y^{(i)})\log\left( 1-h_\theta(x^{(i)})\right)\right) $$

3
On

This comes from basic properties of logarithms:

$$ \log(ab) = \log(a)+\log(b) $$

and

$$ \log(a^b) = b\log(a) $$