\section{Exercises}
\begin{footnotesize} 
\subsection*{Targeted exercises} 

\subsubsection*{Exercises for Section \ref{Comparing_smoothing_approaches_using_test_data}} 
\begin{enumerate}\setcounter{enumi}{-1}
	\item  Imagine you have data with uncertainties for the dependent variables.  You are considering smoothing using either binning or moving averages.  The bin width and the moving average window would be the same size. After smoothing, which approach results in the largest absolute uncertainty?  Which approach results in the largest relative uncertainties?  You can, of course, use code to answer this question, if you want.

	
\end{enumerate}
\subsubsection*{Exercises for Section \ref{Generating_noisy_test_data_using_random_numbers_from_numpy.random}} 
\begin{enumerate}\setcounter{enumi}{0}
    \item We are going to explore what `random' means in Python. Use the following code, which generates two arrays using a Numpy random number generator and then subtracts one from another:
\begin{lstlisting}
import numpy as np
rng1 = np.random.default_rng(42) # sets a 'seed' for random number generation
rand1 = rng1.random(10) # get 10 random numbers from the generator`
rng2 = np.random.default_rng(42) # set up random number generation with the same seed as above`
rand2 = rng2.random(10) # get another 10 random numbers, using the second generator` 
rand1 - rand2
\end{lstlisting}
    \begin{enumerate}
        \item What does it mean that \lstinline{rand1 - rand2} gave an array of all zeros?
        \item  Now, repeat the above, but change the value given to  \lstinline{default_rng()}, the \textit{second} time you use it (you can also supply no argumen to this function).
	\item  What does it mean that  \lstinline{rand1 - rand2} did not give an array of all zeros?
	\item  Repeat the calculation again, just as above. Do you get the same difference as before?
	\item  What does all of this tell you about random number generation in Numpy?
    \end{enumerate}
    
	\item  Perform a linear fit to a series of ten random normally-distributed $y$-values (a mean of 0 and a standard deviation of 1) over a range of $x$-values from 0 to 10.  Do ten trials and compute the standard error of the slopes, and compare that to the uncertainties of the slopes in each individual fit. The expected slope is 0.

	\item  Repeat Exercise 3 using 100, 1000, and 10000 points.

	\item  Repeat Exercise 3 using  standard deviations of 2, 3, and 4.

	\item  Reproduce Figure 10.2 using your own code.

	\item  There are some general guidelines for understanding how large to make bins. One common one is the Friedman-Diaconis rule, but there are others, such as Sturges's formula or the Rice rule.  Modify the final code from Exercise 3 to plot the results from each of these formulas.

	
\end{enumerate}
\subsubsection*{Exercises for Section \ref{Smoothing_by_moving_averages_using_scipy.signal.convolve}} 
\begin{enumerate}\setcounter{enumi}{6}
	\item  A common bandshape to encounter in vibrational spectroscopy of condensed phases is a Voight profile.  This profile is a convolution of a Gaussian and Lorentzian profiles, and can be generated using the \lstinline{scipy.signal.convolve()} function. However, many times people use pseudo-Voight profiles instead, which are the sum of Gaussian and Lorentzian profiles. The LMFIT module has some documentation of this, but it is also well described on Wikipedia. In this problem, generate a Voight and `equivalent' pseudo-Voight profile.  Plot them against one another. Describe the differences you notice.

	
\end{enumerate}
\subsubsection*{Exercises for Section \ref{Smoothing_using_local_regression_with_scipy.signal.savgol_filter}} 
\begin{enumerate}\setcounter{enumi}{7}
	\item  We explored several different smoothing approaches in this chapter, but did not directly compare them. Take the bin centers and counts from the data with the largest numbers in Exercise 3, apply the following methods, and then plot them all on one plot: 

	\begin{enumerate}
	\item binning
	\item moving averages
	\item Savizky-Golay.
	\end{enumerate}
    
\end{enumerate}
\subsection*{Comprehensive exercises} 
\begin{enumerate}\setcounter{enumi}{8}
	\item  The appearance of binned data can change drastically as the width of the bins change. Using the particle size measurement data from our website (sizes.csv), explore the effect of different bin sizes. You can vary the number of bins between the fourth-root of the number of measurements and 0.5 times the number of measurements. For each choice, fit the histogram to a log-normal distribution.  How much smoothing can you do before the best-fitting values change by more than their uncertainty compared using the Freedman-Diaconis rule, as introduced in Exercise 6?

	\item  Using the convolution function \lstinline{scipy.signal.convolve()}, write a wrapper function that performs weighted moving average smoothing of the X-ray powder diffraction data provided on the website for this book. This function should take as arguments: the data to be smoothed and an array that specifies the shape of the smoothing function. For the latter, use:

	\begin{enumerate}
	\item A square function.
	\item A parabolic function
	\item A triangular function
	\item A sine function
	\item A Gaussian function
	\item A Lorentzian function
    \end{enumerate}
    Compare the results using Plotly and comment on which methods appear to give the best noise reduction with the minimum peak broadening.

\item  Generate a Gaussian with $\sigma = 1$ and $x_0 = 0$ on an $x$-axis from -5 to 5 with 20 points. Then add noise by adding normally-distributed random numbers with a standard deviation of 0.1.  Fit the a Gaussian profile to this data using \lstinline{lmfit}, then smooth it using a simple 7-point moving average and fit it again.  Compare the fit of the original data versus the fit of the smoothed data: do the best fitting parameters agree within uncertainty? Has the uncertainty changed? What do you think about fitting smoothed data, rather than original noisy data?

\end{enumerate}
\end{footnotesize} 
