Datenanalyse und Stochastische Modellierung - Dr. Philipp Meyer
Exercise 8

### Wind Speed

In this exercise we want to predict daily mean wind speeds in Potsdam. Our model is a simple AR(1) model $x_t = a x_{t-1} + v\xi_t,$ where the Gaussian noise xi has unit variance and zero mean. So the parameters to be optimized are 'a' and 'v'.

The data can be found at https://www.ecad.eu/dailydata/customquery.php. Select 'blended', 'Germany', 'Potsdam', and 'wind speed' and download the txt-file. Import the time series in python and plot it. The complete time series has a lot of missing data. We can restrict ourselves to a time window of 10000 points, by selecting data=data[20000:30000]. Then we can look for the best parameter 'a'.

• Fitting the TAMSD: calculate the time averaged mean squared displacement (TAMSD) of the data. The AR(1) model can be fitted using the following functions

from scipy.optimize import minimize

def tamsdAR1( DELTA , K , a ):
return 2*K * ( 1 - a**DELTA )

def AR1fit( DELTA, TAMSD ):
def fct( x ):
if(abs(x[1])>0.999):
return 1e45*x[1]**2
return np.mean( np.log(TAMSD / tamsdAR1( DELTA , x[0] , x[1] ))**2 )
x0 = [np.median(TAMSD)/2,0.8]
K,a = minimize( fct , x0 , method='Nelder-Mead' ).x
return K , a

Fit the TAMSD for DELTA smaller than 50, by calling the function as K,a=AR1fit(DELTA[:50],TAMSD[:50]). Plot the TAMSD and the fit. What is the correlation time of your fitted model?
• Minimizing the negative log-likelihood: The negative log-(conditional) likelihood of an autoregressive model is given as $\frac{1}{2}\log(v) + \frac{\frac{1}{T-1}\sum_{t=0}^{T-1} (z_{t+1}-az_{t})^2}{2v},$ were z is the measured time series, the parameters are v (related to K via v=K(1-a^2)) and a, and T is the length ofthe series. Fit the parameters via the above likelihood function, using the scipy.minimize function. What is the correlation time of your fitted model?
• Use the parameters from both, the TAMSD fit and the log-likelihood fit to generate an AR(1) process of length 200 and plot the outputs. Do they look similar?
• Plot the TAMSD of the log-likelihood-fit along with the empirical TAMSD of the data. Which part of the functions coincides
• Plot the autocorrelation function (up to lag 20) of the data, the TAMSD-fit and the log-likelihood-fit together in one figure