MATH 314 Quiz 19

Given on 2025-11-02

Please submit a Jupyter notebook to the Quiz 19 repository by the end of class today.

  1. Generate N = 10 random numbers from a Poisson distribution of your choice (you pick a value ) store the data into a variable named x.

  2. Write Python function with the following signature that calculates the negative log-likelihood for the Poisson distribution.

ll_poisson(theta, data):
...
  1. Use the numpy function linspace to generate a linearly spaced array of values for , named ls, that at least captures within its range the value you chose for above.

  2. Use ls, ll_poisson, and x (as your data) to make a plot of the function ll_poisson.

  3. Repeat 3. and 4. above for a linearly spaced array of values for of values and again for . What does the effect of this array have on the plot? Explain.

  4. Randomly initialize a starting value for within it's proper range.

  5. Use Scipy's funciton sp.optimize.minimize(...) to find the most likely value of given the data you generated (but without knowledge of the true value of ).

    Use the initial value generated in 6. and the data x from 1. Use the method "L-BFGS-B". Don't forget to adjust the bounds appropriately. You can set a bound as np.inf.

  6. Calculate the mean of x and compare it to your answer for 6. They all should match.

  7. Assuming you don't know the answer in advance, how many values would need to be in your grid from part 3. to find the exact answer found in 7.?

  8. Repeat 1. with N = 1000 and the same value of , 3. and 4. When doing 4 again, overlay both log-likelihood functions, one for N = 10 and one fore N = 1000. Given them distinct labels with plt.plot(..., label = "...") and call plt.legend() after your two plt.plot() calls. What is the effect of more data on the log-likelihood function?

  9. Repeat 7. and 8. with your N = 1000 data from 10.