# Bayesian Network Demand-Forecasting Model Based on Modified Particle Swarm Optimization
## 2 Bayesian Network Model Construction  
### Problem Description and Assumptions  
This section aims at how a specific enterprise in the supply chain node predicts the demand for products in a future period of time based on the historical sales data of products. In reality, the actual demand of consumers is not available due to the occurrence of situations such as stock-outs, so this paper equates the sales volume of goods with the actual demand of customers. Specifically, in this section, the following problem is considered: given the historical sales data of commodities, suppose that the demand quantity of commodities in the past \(T\) consecutive time points is 1, 2, \(\ldots\), \(T\) is \(y_{1}\), \(y_{2}\), \(\ldots\), \(y_{T}\), make a relatively accurate prediction of the demand quantity of commodities in the future \(T+1\), \(T+2\), \(\ldots\), \(T+n\), and finally, minimize the prediction error. The multilayer Bayesian network demand-forecasting model constructed in this paper considers the continuity and volatility of commodity demand in time series, and the flow chart of the forecasting plan is shown in Figure 2.  
Assuming that the historical sales data of a certain product are known, the demand for a single product in the future period of time is forecasted, and the customer demand for the product at time t is recorded as \(y_{T}\). Then, \(y_{T}\) represents the time series data, and there are time series characteristics. In addition, a hyperparameter layer is introduced on the middle layer to smooth the data fitting effect. Aiming at the volatility of product demand, the volatility factor \(\gamma\) and the correction factor \(\beta\) are introduced to better fit the data. Specifically, it is assumed that each variable has the following relationship with each other, and the probability graphical model is shown in Figure 3.  
Assume that the variables in Figure 3 have the following relationships with each other:  
1. Assume that at any time \(t\), the customer's demand for goods satisfies the Gaussian distribution with mean value \(\gamma_{t}\eta_{t}+\beta\) and variance \(\sigma_{y}^{2}\). The large fluctuation of the actual commodity data, namely, the change of the data on the time nodes before and after, shows a strong randomness. Therefore, it is assumed that the observations at different times are independent of each other. For the observation data \(y_{t}\) at any time, there is: \[y_{t}\sim N(\gamma_{t}\eta_{t}+\beta,\sigma_{y}^{2})\] (7) where \(\eta_{t}\) represents the sequential characteristics of the customer demand for goods. \(\gamma_{t}\) represents the volatility factor, representing the volatility of customer demand for commodities, which often has a certain cyclical law. \(\beta\) is the correction factor. Figure 3: Probability graph model. Figure 2: Prediction plan flow chart. The hidden layer variable \(\eta_{t}\) at any time is only affected by the previous moment, \(\eta_{t-1}\), and only affects the next moment, \(\eta_{t+1}\). The hidden layer variable has the first-order Markov property on the time axis, which can be obtained:  
\[P(\eta_{t}|\eta_{1},\eta_{2},\eta_{3},\cdots,\eta_{t-1})=P(\eta_{t}|\eta_{t-1}) \tag{8}\]  
Furthermore, taking into account the timing characteristics of the number of customers' demand for goods, it is assumed that the hidden layer variables at each time point obey the following first-order autoregressive model:  
\[\eta_{t}=\left\{ \begin{array}{ll}\mu+\epsilon_{t}&t=1\\ \mu+\phi(\eta_{t-1}-\mu)&t>1\end{array} \right. \tag{9}\]  
where \(\mu\)\(\in\)\(R\) represents the long-term mean value of \(\eta_{t}\); \(-1\)\(<\)\(\phi\)\(<\)\(1\) represents the rate of autoregression; \(\epsilon_{t}\) represents the noise term of autoregression; and \(\epsilon_{t}\)\(\sim\)\(N(0,1)\). 3. It can be seen from the probability diagram model in Figure 3 that the fluctuation factor \(\gamma_{t}\) directly acts on the demand data \(y_{t}\).