Let $M \in \mathscr{M}_{N,d}(\mathbb{R})$ defined by $M_{i,j} = g_{j}(i)$. For all $\theta \in \mathbb{R}^{d}$, let $f(\theta) = M\theta \in \mathbb{R}^{N}$, $Z(\theta) = \sum_{i=1}^{N} e^{f_{i}(\theta)}$ and $$p(\theta) = \left(\frac{e^{f_{1}(\theta)}}{Z(\theta)}, \ldots, \frac{e^{f_{N}(\theta)}}{Z(\theta)}\right) \in \Sigma_{N}$$ where $f(\theta) = (f_{1}(\theta), \ldots, f_{N}(\theta))$. The function $L : \mathbb{R}^{d} \rightarrow \mathbb{R}$ is defined by $$L(\theta) = \ln(Z(\theta)) - q^{T} M\theta.$$ Show that $L$ is of class $\mathscr{C}^{1}$ and calculate its gradient.
Let $M \in \mathscr{M}_{N,d}(\mathbb{R})$ defined by $M_{i,j} = g_{j}(i)$. For all $\theta \in \mathbb{R}^{d}$, let $f(\theta) = M\theta \in \mathbb{R}^{N}$, $Z(\theta) = \sum_{i=1}^{N} e^{f_{i}(\theta)}$ and
$$p(\theta) = \left(\frac{e^{f_{1}(\theta)}}{Z(\theta)}, \ldots, \frac{e^{f_{N}(\theta)}}{Z(\theta)}\right) \in \Sigma_{N}$$
where $f(\theta) = (f_{1}(\theta), \ldots, f_{N}(\theta))$. The function $L : \mathbb{R}^{d} \rightarrow \mathbb{R}$ is defined by
$$L(\theta) = \ln(Z(\theta)) - q^{T} M\theta.$$
Show that $L$ is of class $\mathscr{C}^{1}$ and calculate its gradient.