Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I want to know how the Hessian of the function

$f(x) = \log\sum_{k=1}^n\exp(x_k)$

comes out to be

$\frac{1}{\textbf{1}^Tz}\mathrm{diag}(z)-\frac{1}{(\textbf{1}^Tz)^2}zz^T $

given $z_k=\exp(x_k)$

share|improve this question
    
It's a straightforward calculation. Why don't you try it for the case $n=2$? That will show you why the result is a difference of two terms and where all the pieces are coming from. –  whuber Jan 9 '13 at 23:56
add comment

migrated from stats.stackexchange.com Jan 10 '13 at 13:57

This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.

1 Answer

We have $$ f(x) = \log(\sum_k \exp(x_k))$$ Our first partial derivative is $$ \partial x_i f (x) = \frac{\exp(x_i)}{\sum_k\exp(x_k)}$$ But we need second derivatives, therefore \begin{align} \partial x_i \partial x_i f (x)& = \frac{\exp(x_i)\cdot(\sum_{k,k\not =i} \exp(x_i))}{(\sum_k\exp(x_k))^2} \\ &= \frac{\exp(x_i)}{\sum_k\exp(x_k)} -\frac{\exp(2x_i)}{(\sum_k\exp(x_k))^2} \end{align} and \begin{align} \partial x_j \partial x_i f (x) = -\frac{\exp(x_i)\cdot\exp(x_j)}{(\sum_k\exp(x_k))^2} \end{align} Therefore we can rewrite our Hessian as \begin{align} H_f = \frac{1}{\sum_k\exp(x_k)} \begin{pmatrix} \exp(x_1) & 0 & 0 & ...\\ 0 & \exp(x_2) & 0 & ...\\ ... & ... & ... & ...\\ 0 & ... & 0 &\exp(x_n)\\ \end{pmatrix} - \frac{1}{(\sum_k\exp(x_k))^2} \begin{pmatrix} \exp(2x_1) & \exp(x_1x_2) & \exp(x_1x_3) & ...\\ \exp(x_2x_1) & \exp(2x_2) & \exp(x_2x_3) & ...\\ ... & ... & ... & ...\\ ... & ... & ... &\exp(2x_n)\\ \end{pmatrix} \end{align} which is exactly what you should show if we define $z := (\exp(x_1),...,\exp(x_n))^T$. Your task is now to proof that I calculated the corred deriatives and that you can split the second derivative for $\partial x_i\partial x_i f$ in two terms as i claimed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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