{'fraction_non_alphanumeric': 0.03030888030888031, 'fraction_numerical': 0.011341698841698842, 'mean_word_length': 4.372310085558724, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
First and second order semi-Markov chains for wind speed modeling

The increasing interest in renewable energy, particularly in wind, has given rise to the necessity of accurate models for the generation of good synthetic wind speed data. Markov chains are often used with this purpose but better models are needed to reproduce the statistical properties of wind speed data. We downloaded a database, freely available from the web, in which are included wind speed data taken from L.S.I. -Lastem station (Italy) and sampled every 10 minutes. With the aim of reproducing the statistical properties of this data we propose the use of three semi-Markov models. We generate synthetic time series for wind speed by means of Monte Carlo simulations. The time lagged autocorrelation is then used to compare statistical properties of the proposed models with those of real data and also with a synthetic time series generated though a simple Markov chain.


Introduction
The increasing interest in renewable energy leads scientific research to find a better way to recover most of the available energy. Particularly, the maximum energy recoverable from wind is equal to 59.3% of that available (Betz law) at a specific pitch angle and when the ratio between the wind speed in output and in input is equal to 1/3. The pitch angle is the angle formed between the airfoil of the blade of the wind turbine and the wind direction. Old turbine and a lot of that actually marketed, in fact, have always the same invariant geometry of the airfoil. This causes that wind turbines will work with an efficiency that is lower than 59.3%. New generation wind turbines, instead, have a system to variate the pitch angle by rotating the blades. This system allows the wind turbines to recover, at different wind speed, always the maximum energy, working in Betz limit at different speed ratios. A powerful system control of the pitch angle allows the wind turbine to recover better the energy in transient regime. A good stochastic model for wind speed is then needed to help both the optimization of turbine design and to assist the system control to predict the value of the wind speed to positioning the blades quickly and correctly. The possibility to have synthetic data of wind speed is a powerful instrument to assist designer to verify the structures of the wind turbines or to estimate the energy recoverable from a specific site. To generate synthetic data, Markov chains of first or higher order were often used [1,2,3,4]. In particular in [1] is presented a comparison between a first-order Markov chain and a second-order Markov chain. A similar work, but only for the first-order Markov chain, is conduced by [2], presenting the probability transition matrix and comparing the energy spectral density and autocorrelation of real and synthetic wind speed data. A tentative to modeling and to join speed and direction of wind is presented in [3], by using two models, first-order Markov chain with different number of states, and Weibull distribution. The Markov assumption is widely used in other closely related topics, see for example [5,6].
All these models use Markov chains to generate synthetic wind speed time series but the search for a better model is still open. Approaching this issue, we applied new models which are generalization of Markov models. More precisely we applied semi-Markov models to generate synthetic wind speed time series.
Semi-Markov processes (SMP) are a wide class of stochastic processes which generalize at the same time both Markov chains and renewal processes [7,8]. They have been widely used in the literature to model natural phenomena (see for example [9,10,11,12,13,14,15]). Their main advantage is that of using whatever type of waiting time distribution for modeling the time to have a transition from one state to another one. This major flexibil-ity has a price to pay: availability of data to estimate the parameters of the model which are more numerous. Data availability is not an issue in wind speed studies, therefore, semi-Markov models can be used in a statistical efficient way.
In this work we present three different semi-Markov chain models: the first one is a first-order SMP where the transition probabilities from two speed states (at time T n and T n−1 ) depend on the initial state (the state at T n−1 ), final state (the state at T n ) and on the waiting time (given by t = T n − T n−1 ). The second model is a second order SMP where we consider the transition probabilities as depending also on the state the wind speed was before the initial state (which is the state at T n−2 ) and the last one is still a second order SMP where the transition probabilities depends on the three states at T n−2 , T n−1 and T n and on the waiting times t 1 = T n−1 − T n−2 and t 2 = T n − T n−1 . The three models will be extensively explained in the next sections. The three models are used to generate synthetic time series for wind speed by means of Monte Carlo simulations and the time lagged autocorrelation function is used to compare statistical properties of the proposed models with those of real data and also with a time series generated though a simple Markov chain. The probability density function of real and simulated data are also compared for the model which is recognized to be the best among the proposed ones.
In this paper, for the first time, different second order discrete time semi-Markov chains are defined and general formulae of transition probabilities with initial and final backward are presented.
The paper is organized as follows: in Section 2 we describe the stochastic models and we derive relevant results. Section 3 demonstrates the models applied to a real dataset by testing the semi-Markov hypothesis and by computing the autocorrelation functions and the probability density functions of the wind speed. Finally Section 4 presents some concluding remarks.

Wind speed modeling with semi-Markov chains
Semi-Markov chains are a generalization of Markov chains allowing the times between transitions to occur at random times according to any kind of distribution functions which may depend on the current and the next visited state. As it is well known, Markov chains have sojourn times between transitions geometrically distributed, for this reason the memoryless property is preserved and no duration effect is observed. The more general semi-Markov environment allows the possibility to use also no memoryless distributions and then can reproduce a duration effect. The duration effect affirms that the time the system is in a state influences its transition probabilities. The states of the process in our data are represented by different wind speed values, then in this paper we detect the presence of a duration effect in wind speed modeling and forecasting. Given that the data on wind speed are recorded naturally in discrete time and in discrete values we develop also the theoretical model in discrete time and discrete values.
Here below we propose a semi-Markov model of order two in state and duration and we compare its performance with the Markov chain models often used to describe wind speed, see [1,2,3] and with some particular cases of our semi-Markov chain model. Let us consider a finite set of states E = {1, 2, ..., S} in which the system can be into and a complete probability space (Ω, F, P ) on which we define the following random variables: They denote the state occupied at the n-th transition and the time of the n-th transition, respectively. To be more concrete, by J n we denote the wind speed at the nth transition and by T n the time of the nth transition of the wind speed process. We do the following conditional independence assumption: (2) Relation (2) asserts that, the knowledge of the values J n , J n−1 , T n − T n−1 is sufficient to give the conditional distribution of the couple J n+1 , T n+1 − T n whatever the values of the past variables might be. Therefore to make probabilistic forecasting we need the knowledge of the last two visited state and the duration time of the transition between them. For this reason we called this model a second order semi-Markov chains in state and duration.
The conditional probabilities are stored in a matrix of functions q = ( x q i.k,j (t)) called the second order kernel in state and duration. The element x q i.k,j (t) represents the probability that next wind speed will be in speed j at time t given that the current wind speed is k and the previous wind speed state was i and the duration in wind speed i before of reaching the wind speed k was equal to x units of time.
We can define the cumulated second order kernel: (3) The process {J n } is a second order Markov chain with state space E and transition probability matrix x P = x Q(∞). We shall refer to it as the embedded Markov chain.
Let us consider the unconditional waiting time distribution function in states i and k with duration x as (4) The conditional cumulative distribution functions of the waiting time in each state, given the state subsequently occupied is defined as where, in general, 1 {a=b} is 1 if a = b and zero otherwise. Now let N (t) = sup{n : T n ≤ t} ∀t ∈ N be the number of transitions up to time t, then the second order (in state and duration) semi-Markov chain can be defined as For all i, k, j ∈ E, and t ∈ N, we define the semi-Markov transition probabilities: then the following system of equations is verified: The proof of equation (7) is not given here because it is a particular case of the equation established and proved later.
To detect the duration effects let us introduce the backward recurrence time process defined for each time t ∈ N by: If the semi-Markov process Z(t) indicates the wind speed at time t, the backward process B(t) indicates the time since the last transition, that is from how long time the wind speed is at the value Z(t).
In Figure 1 a trajectory of a semi-Markov process with initial and final backward times is reported. In this figure we have that N (s) = n and N (s + t) = h − 1, the backward process at time s is B(s) = s − T n = v and the backward process at time t + s is To quantify the duration effect in our second order semi-Markov model, let us define the following probabilities: (9) Expression (9) gives the probability that the wind speed will enter in the state j at time t − v coming from state h and will remains inside the state j without any other transition up to the time t given that at the present the wind speed is k and it entered into this state with the last transition v periods before coming from a wind speed equal to i with a duration in i of x periods. Proposition 1. The relation (10) represents the evolution equation of (9): Proof: For simplicity of notation, suppose the counting process N (0) = 0, and denote by Observe that If This gives: The second addend on the right hand side of (11) can be represented as follows: A substitution of (13) and (14) in (11) concludes the proof.

Obviously we have that
(15) Expression (15) represents the probability that the wind speed will be in the state j at time t coming from a wind speed equal to h given that at present the wind speed is k and it entered into this state with the last transition v periods before coming from a wind speed equal to i with a duration in i of x periods.
Notice that, if v = 0 we obtain the equation (7). It should be noted that our semi-Markov model of order two in state and duration contains several interesting special cases we will apply in the next section. The paper [16] proposed a n-order semi-Markov process (in state) in continuous time. The discrete time counterpart of order two (in state) is obtained through the following assumption: Relation (16) asserts that, the knowledge of the values J n , J n−1 is sufficient to give the conditional distribution of the couple J n+1 , T n+1 − T n whatever the values of the past variables might be. Therefore to make probabilistic forecasting we need the knowledge of the last two visited state. In the application we will refer to this model as the model named semi-Markov II.
If we assume that then we recover the classical semi-Markov chain model. Finally remark that a Markov chain with transition probability matrix (t ij ) ij∈E is obtained when the semi-Markov kernel (17) is given by q ij (s) = t ij (t ii ) s−1 1 {i =j} , s ∈ N − {0}.

Application to real data
To check the validity of our model we perform a comparison of the behavior of real data and wind speeds generated through Monte Carlo simulations based on the models described above. In this section we describe the database of real data used for the analysis, the method used to simulate synthetic wind speed time series and, at the end, we compare results from real and simulated data.
The data used in this analysis are freely available from http : //www.lsi− lastem.it/meteo/page/dwnldata.aspx. The station of L.S.I. -Lastem is situated in Italy at N 45 28' 14,9" − E 9 22 ' 19,9" and at 107 m of altitude. The station uses a combined speed-direction anemometer at 22 m above the ground. It has a measurement range that goes from 0 to 60 m/s, a threshold of 0,38 m/s and a resolution of 0,05 m/s. The station processes the speed every 10 minutes in a time interval ranging from 25/10/2006 to 28/06/2011. During the 10 minutes are performed 31 sampling which are then averaged in the time interval. In this work, we use the sampled data that represents the average of the modulus of the wind speed (m/s) without a specific direction. The database is then composed of about 230thousands wind speed measures ranging from 0 to 16 m/s. The time series, together with its empirical probability density distribution are represented in Figure 2.
To be able to model the wind speed as a semi-Markov process the state space of wind speed has been discretized. In the example shown in this work we discretized wind speed into 7 states chosen to cover all the wind speed distribution. From the discretized wind speeds we estimated the probabilities P and G to generate synthetic trajectories by means of Monte Carlo simulations [17] for three semi-Markov models: a simple semi-Markov model of the first order named semi-Markov I, semi-Markov II a second order semi-Markov model in state (as described in section 2) and the second order semi-Markov model in state and duration is named semi-Markov III. For comparison reason, we also generated a synthetic trajectory which follows a simple Markov model with transition probability matrix estimated from the real data. We then ended up with five trajectories: one representing real data, three representing the three trajectories according to the three semi-Markov models and the last one a Markov chain. The time series are used in the following to compare results on the time lagged autocorrelation function. Real data are, in fact, strongly autocorrelated and the autocorrelation function decreases rapidly with time. We then tested our models to check whether they are able to reproduce such behavior. Before doing so we tested the semi-Markov hypothesis using an hypothesis test which we are going to describe in the next subsection.

Test
The semi-Markov hypothesis is tested applying a test of hypothesis proposed by [18] and shortly described here below. As already stated, the model can be considered semi-Markovian if the sojourn times are not geometrically distributed. The probability distribution function of the sojourn time in state i before making a transition in state j has been denoted by G ij (·). Define the corresponding probability mass function by Under the geometrical hypothesis the equality g ij (1)(1 − g ij (1)) − g ij (2) = 0 must hold, then a sufficiently strong deviation from this equality has to be interpreted as an evidence in favor of the semi-Markov model. The teststatistic is the following: (1)) . (19) where N (i, j) denotes the number of transitions from state i to state j observed in the sample andĝ ij (x) is the empirical estimator of the probability g ij (x) which is given by the ratio between the number of transition from i to j occurring exactly after x unit of time and N (i, j). This statistic, under the geometrical hypothesis H 0 (or markovian hypothesis), has approximately the standard normal distribution, see [18]. We applied this procedure to our data to execute tests at a significance level of 95%. Because we have 7 states we estimated the 7 × (7 − 1) waiting time distribution functions and for each of them we computed the value of the test-statistic (19). The geometric hypothesis is rejected for 28 of the 42 distributions. Due to lack of space, we do not report all the values of the test-statistic, but they are available upon request. In Table 1 we show the state state score decision i = 1 j = 2 12.14 H 0 rejected i = 1 j = 3 3.33 H 0 rejected i = 2 j = 1 5.64 H 0 rejected i = 2 j = 3 9.35 H 0 rejected The large values of the test statistic suggest the rejection of the Markovian hypothesis in favor of the more general semi-Markov one.

Autocorrelation function
If Z indicates wind speed, the time lagged (τ ) autocorrelation of wind speed is defined as The time lag τ was made to run from 1 minute up to 1000 minutes. Note that to be able to compare results for Σ(τ ) each simulated time series was generated with the same length as real data. Results shown in Figure 3 indicate that semi-Markov models reproduce better the autocorrelation present in real data especially if a second order semi-Markov chain is used to generate synthetic data. We can also notice that the second order semi-Markov model in state and duration (Model III) has to be preferred to the second order semi-Markov model in state (Model II) because it exhibits a slightly higher autocorrelation uniformly in time and also because, asymptotically, its autocorrelation has the same slope of that observed in real data whereas in the Model II, the autocorrelation drops to zero.

Probability density function and trajectories
From the study of the autocorrelation function we found out that Model III should be chosen to generate synthetic trajectories of wind speed data. In this subsection we are going to compare the probability density function (pdf) of real data and synthetic data. As an example we will show also the two trajectories for a sample period. First of all let us remind that to use the semi-Markov approach we discretized the wind speed in a finite number of states. We choose 7 so that we can cover all the wind speeds in our dataset and, at the same time, each state as a sufficient number of occupation. To obtain synthetic wind speeds data comparable with real ones a transformation back to continuous speed as to be made. We used the following formula w c (t) = w d (t) + ∆.
where w c indicates the continuous wind speed at time t, w d (t) the discretized wind speed at the same time, is a uniformly distributed random number in the interval [0, 1] and ∆ is the wind speed interval used for discretization. We show in Figure 4 an example of real and simulated trajectories while in Figure 5 we compare the pdf for both trajectories. From Figure 5 it is possible to notice that the pdf for real and synthetic data are almost identical supporting even more our model. We only compare here the pdf of real data and of the synthetic data from Model III because the fitting is already very good and there is very little space for improvement.

Conclusions
Wind speed is a stochastic process for which a completely satisfactory model is still lacking. Many authors have used Markov chain to model the process but this approach does not give the same persistence present in real data. We presented in this work three semi-Markov models with the aim of generate synthetic wind speed data. We have shown that all our models perform better than a simple Markov chain in reproducing the statistical properties of wind speed data. In particular, the model that we recognized as being the more suitable is a second order semi-Markov process in state and duration. Although the evidence shows the semi-Markovian nature of the studied phenomenon, probably a third/fourth order semi-Markov chain would be needed to decrease the difference between autocorrelation of real and simulated data. In our view this approach would be too much computationally and data consuming and further research on a simplified, but still with longer memory, model is needed. In this view, models from the econophysics literature (see for example [13,15,19,20,21,22]) could be tested for possible application in wind speed modeling.
We conclude that semi-Markov models should be used when dealing with wind speed data.