How is this expectation calculated This is from an old practice midterm from my statistics class. Suppose $$X = \begin{cases} 2 & \text{w.p. $\theta$} \\ 4 & \text{w.p. $\theta^2$} \\ 6 & \text{w.p. $1-\theta-\theta^2$} \end{cases}$$
The goal is to calculate $$i(\theta) = E\left[\left(\frac{\partial}{\partial\theta}\log f_\theta (x)\right)^2 \right]$$
From the solution key, it claims $$i(\theta) = \theta\left(\frac{1}{\theta}\right)^2 + \theta^2\left(\frac{2\theta}{\theta^2}\right)^2 + (1-\theta-\theta^2)\left(\frac{-1-2\theta}{1-\theta-\theta^2}\right)^2$$ 
which we can simplify. However, I'm not understanding where this expression is coming from. I think I see where the part in parenthesis comes from (e.g. $\frac{\partial}{\partial\theta}\log(\theta^2) = \frac{2\theta}{\theta^2}$), and the whole expression resembles $$E[X] = \sum_{x \in X} xp(x)$$ 
but the $x$ in that expression is appearing as the probabilities themselves so I'm a bit confused over how this expression is derived (it's probably simple and I'm just missing it).
 A: Hint: $\frac{\partial logf_{\theta}\left ( x\right ) }{\partial \theta} = \frac{1}{f_{\theta}\left ( x \right )}\frac{\partial f_{\theta}\left ( x\right )}{\partial \theta}$.  
Use this to compute the derivative, square it, and plug it in the expectation which is really a sum.
A: First note that
$$E[g(X)]=\sum\limits_{x_k\in X}p(x_k)g(x_k)$$
Where $g$ is a function of a random variable and $p$ is a probability density function. So now
$$X = 
\begin{cases} 
x_1=2 & \text{w.p.}\quad f_\theta(2)=\theta \\ 
x_2=4 & \text{w.p.}\quad f_\theta(4)=\theta^2 \\ 
x_3=6 & \text{w.p.}\quad f_\theta(6)=1-\theta-\theta^2
\end{cases}$$
Therefore
$$i(\theta) = E\left[\left(\frac{\partial}{\partial\theta} \log f_\theta (X)\right)^2 \right]$$
$$= E\left[\left(\frac{1}{f_\theta(X)}\frac{\partial}{\partial\theta} f_\theta (X)\right)^2 \right]$$
$$=\sum\limits_{x_k\in X} \left[f_\theta(x_k)\left(\frac{1}{f_\theta(x_k)}\frac{\partial}{\partial\theta} f_\theta (x_k)\right)^2\right] $$
$$=f_\theta(2)\left(\frac{1}{f_\theta(2)}\frac{\partial}{\partial\theta} f_\theta (2)\right)^2+f_\theta(4)\left(\frac{1}{f_\theta(4)}\frac{\partial}{\partial\theta} f_\theta (4)\right)^2 +f_\theta(6)\left(\frac{1}{f_\theta(6)}\frac{\partial}{\partial\theta} f_\theta (6)\right)^2$$
$$=\theta\left(\frac{1}{\theta}\frac{\partial}{\partial\theta} \theta\right)^2+\theta^2\left(\frac{1}{\theta^2}\frac{\partial}{\partial\theta} \theta^2\right)^2 +(1-\theta-\theta^2)\left(\frac{1}{(1-\theta-\theta^2)}\frac{\partial}{\partial\theta}(1-\theta-\theta^2)\right)^2$$
$$=\theta\left(\frac{1}{\theta}\right)^2 + \theta^2\left(\frac{2\theta}{\theta^2}\right)^2 + \left(1-\theta-\theta^2\right)\left(\frac{-1-2\theta}{1-\theta-\theta^2}\right)^2$$
