*3.2. Short-Term In-Vehicle Occupation Predictions Based on Markov Chains Model*

The problem of in-vehicle occupancy forecasting in public transport may be closely related to previously defined comfort levels. The specificity of the inflow of passengers to the given bus line stops in the following hours is stochastic. Therefore, it seems appropriate to use discrete Markov processes to determine the expected occupancy level of the vehicle at subsequent departures from a given stop on the line. Markov's process is a sequence of random variables, in which the probability of what will happen depends only on the present state. In the considered issue, only Markov processes defined on a discrete space of states will be used (Markov chains).

Let us denote by *X* = (*<sup>X</sup>*0, *X*1, ...) a sequence of discrete random variables. The value of the variable *Xt* will be called the state of the chain at the moment *t*. It is assumed that the set of states *S* is calculable. The finite set of states can be defined as the state space *S* as follows:

$$s \in S\_{\prime}. S = \left\langle s\_1, \ s\_2, \dots, s\_{k-1}, s\_k \right\rangle\_{\prime}, k < \infty \tag{3}$$

The discrete timestamps used in the considered problem can be defined as follows:

$$t \in \mathcal{T}, \ T = \{1, \ 2, \ldots, t\_{\max}\}, \ t\_{\max} \le \infty \tag{4}$$

**Definition 1.** *A sequence of random variables X is a Markov chain if the Markov condition is fulfilled:*

$$\mathbb{P}(X\_{l} = \mathbf{s} | X\_{0} = \mathbf{x}\_{0}, \dots, X\_{l-1} = \mathbf{x}\_{l-1}) = \mathbb{P}(X\_{l} = \mathbf{s} | X\_{l-1} = \mathbf{x}\_{l-1}) \land \mathbb{H}T \land \mathbf{x}\_{0}, \mathbf{x}\_{1}, \dots, \mathbf{x}\_{l-1} \in \mathbb{S} \tag{5}$$

*Thus, for the Markov chain, the distribution of the conditional probability of the position in the time step t depends only on the conditional probability of the position in the previous step and not on the previous trajectory points (history).*

**Definition 2.** *Let* P *be a matrix of dimensions (k* × *k) and elements pij* : *i*, *j* = 1, ... *k*. *A sequence of random variables* (*<sup>X</sup>*0, *X*1, ...) *with values from a finite set of states S* = *s*1, *s*2, ... ,*sk*−1, *Sk is called the Markov process, with the transition matrix* P*, if for each t, any i*, *j* ∈ {1, ... *k*} *and all i*0, ... *it*−<sup>1</sup> ∈ {1, ... *k*},

$$\mathbb{P}\{X\_{t+1} = s\_j | X\_0 = s\_{i0}, \ X\_1 = s\_{i\_1}, \dots, X\_{t-1} = s\_{i\_{t+1}}, \ X\_t = s\_i\} = \mathbb{P}\{X\_{t+1} = s\_j | X\_t = s\_i\} = p\_{ij}$$

*The elements of the transition matrix pij* fulfill the following conditions:

$$\wedge \text{t} \epsilon T \, p\_{ij} = \mathbb{P} \{ \mathbf{X}\_{t+1} = s\_j | \mathbf{X}\_t = s\_i \}$$

$$p\_{ij} \ge 0 \land i, j \in \{ 1, \dots, k \}$$

$$\bigwedge\_i \sum\_j p\_{ij} = 1$$

**Definition 3.** *The Markov chain is homogenous when for each time stamp it is described by the same transition matrix* P*. The transition matrix is fixed and does not depend on time.*

In the use of Markov chains, the initial state plays a crucial role. Formally, the initial state is a random variable *X*0. Therefore, the Markov chain often starts with a certain probability distribution across the state space.

**Definition 4.** *The initial distribution is a vector defined as follows:*

$$D^{(0)} = \left[ d\_1^{(0)}, d\_2^{(0)}, \dots, d\_k^{(0)} \right] = \left[ \mathbb{P}(\mathbf{X}\_0 = \mathbf{s}\_1), \mathbb{P}(\mathbf{X}\_0 = \mathbf{s}\_2), \dots, \mathbb{P}(\mathbf{X}\_0 = \mathbf{s}\_k) \right]$$

*To determine the distribution of the forecasted state of the modelled object for the n-th time step ahead, the following equation can be used:*

$$D^{(\mathfrak{t}+\mathfrak{n})} = D^{(\mathfrak{t})} \mathcal{P}^{\mathfrak{n}}$$

*where n* is the parameter defining the forecasting horizon.
