You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/mle.md
+33-15Lines changed: 33 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,6 @@ kernelspec:
11
11
name: python3
12
12
---
13
13
14
-
15
14
# Maximum Likelihood Estimation
16
15
17
16
```{contents} Contents
@@ -47,15 +46,13 @@ Let's check the GPU we are running
47
46
!nvidia-smi
48
47
```
49
48
50
-
51
49
We will use 64 bit floats with JAX in order to increase the precision.
52
50
53
51
```{code-cell} ipython3
54
52
jax.config.update("jax_enable_x64", True)
55
53
```
56
54
57
-
58
-
## MLE with Numerical Methods (JAX)
55
+
## MLE with numerical methods (JAX)
59
56
60
57
Many distributions do not have nice, analytical solutions and therefore require
61
58
numerical methods to solve for parameter estimates.
@@ -81,7 +78,6 @@ def logL(β):
81
78
return -(β - 10) ** 2 - 10
82
79
```
83
80
84
-
85
81
To find the value of $\frac{d \log \mathcal{L(\boldsymbol{\beta})}}{d \boldsymbol{\beta}}$, we can use [jax.grad](https://jax.readthedocs.io/en/latest/_autosummary/jax.grad.html) which auto-differentiates the given function.
86
82
87
83
We further use [jax.vmap](https://jax.readthedocs.io/en/latest/_autosummary/jax.vmap.html) which vectorizes the given function i.e. the function acting upon scalar inputs can now be used with vector inputs.
@@ -113,7 +109,6 @@ plt.axhline(c='black')
113
109
plt.show()
114
110
```
115
111
116
-
117
112
The plot shows that the maximum likelihood value (the top plot) occurs
118
113
when $\frac{d \log \mathcal{L(\boldsymbol{\beta})}}{d \boldsymbol{\beta}} = 0$ (the bottom
119
114
plot).
@@ -129,14 +124,29 @@ The Newton-Raphson algorithm finds a point where the first derivative is
129
124
130
125
To use the algorithm, we take an initial guess at the maximum value,
131
126
$\beta_0$ (the OLS parameter estimates might be a reasonable
132
-
guess), then
127
+
guess).
133
128
129
+
Then we use the updating rule involving gradient information to iterate the algorithm until the error is sufficiently small or the algorithm reaches the maximum number of iterations.
134
130
135
131
Please refer to [this section](https://python.quantecon.org/mle.html#mle-with-numerical-methods) for the detailed algorithm.
136
132
137
-
Let's have a go at implementing the Newton-Raphson algorithm.
133
+
Let's have a go at implementing the Newton-Raphson algorithm to calculate the maximum likelihood estimations of a Poisson regression.
0 commit comments