This section begins with an energy scheduling problem and its stochastic optimization model. Subsequently, we present the real-world data used in the numerical experiments and preprocess the data. Finally, we train four ML models and calculate the decision losses for w-SAA and contextual distribution estimation methods.
3.1. Energy Scheduling Problem and Its Mathematical Model
This section presents an energy production scheduling problem, where the future 24-hour energy prices are uncertain, requiring the company to plan corresponding energy production schedules and maximize the profit obtained from energy sales on the future day. The definitions of parameters and variables are shown in
Table 1.
The settings of the parameters in
Table 1 are designed based on the real situation of an energy company. For example, for energy-consuming enterprises, the larger the production quantity, the higher the unit production cost; therefore, we design a piecewise cost function with the gradually increasing unit production cost. This experimental setup can reflect the essence of a class of decision-making problems that enterprises face in reality. As the energy price per hour is an uncertain parameter, this study establishes the following stochastic optimization model:
Objective function (6) minimizes the expected total negative profits from energy sales on a future day. Constraint (7) represents the production capacity constraint per unit time. Constraints (8)–(11) denote the cost calculation formulas per unit time. Constraint (12) is the formula for total cost calculation. Constraint (13) specifies the variable domain constraints.
Assume that we have estimated scenarios for energy prices, represented by , each with a likelihood of . Therefore, the approximation of Model A is shown as follows:
Model B:
subject to Constraints (7)–(13).
3.2. Introduction of Datasets
The energy price dataset used in this study consists of 14,592 records [
16]. We divide it into a training dataset
and a test dataset
. Each record contains historical values of a random variable
and feature variables
. Specifically, the feature vector
and the random variable
, along with their practical meanings and ranges, are detailed in
Table 2.
Specifically, indicates January of the current year, indicates the first week of the current year, indicates Monday, indicates the first hour of the day, and so on. indicates that the day is a holiday.
Histograms and density curves of the frequency distribution of the random variable
based on
are plotted, as shown in
Figure 1. From the graph, it can be observed that, without considering some extreme values, the distribution of the random variable
approximates a normal distribution. Therefore, in the contextual distribution estimation method, this study chooses a normal distribution to fit the random variable
.
Since the mathematical model in this study is aimed at scheduling energy production within a 24-hour period in the future, during testing on the test dataset , each of the 24 data samples form an input of a decision problem. Therefore, we construct a set of decision problems , where and .
For problem
, its input data is defined as:
where
In the w-SAA method, for , the weight can be obtained through an ML model, where . Therefore, there are potential combinations of energy prices in one day. The weight for each parameter combination is , where . This study randomly selects scenarios along with their weights to be inputted into the objective function of the mathematical model for solving, and obtains the decision . In the contextual distribution estimation method, for , the estimated distribution can be obtained. Based on , we obtain estimates of , denoted as . Therefore, there are potential combinations of energy prices in one day, with equal weight for each parameter combination. This study also randomly selects scenarios to be inputted into the objective function of the mathematical model for solving, and obtains the decision .
The optimal objective function value of problem
under complete information is
; hence, the decision loss is:
Based on the training dataset , this study adopts four ML models, i.e., kNN, CART, RF, and KR, to compare the effectiveness of the w-SAA and contextual distribution estimation methods.
The
kNN and KR models involve calculating distances between data samples, thus requiring data standardization before training the models, while the CART and RF models can be trained directly using the original dataset. The standardization method is used as follows: features
to
represent periodic features related to time; therefore, we employ Sine-Cosine encoding, where
, with
as the original value,
as the standardized value, and
as the total periods of
. For example, the standardized data of the feature
representing months is
, where:
For features
to
, we apply the Z-score standardization method. For instance, for the feature
, the mean is calculated as
, and the standard deviation as
, resulting in the standardized data
, where:
The data after Z-score standardization have a mean of 0 and a standard deviation of 1.
3.3. Model Training
During the model training process, this study randomly splits the training dataset into and in a 4:1 ratio, with containing 9312 data samples and containing 2328 data samples.
In the w-SAA method, the study trains ML models based on
and tunes hyperparameters based on
, with decision loss as the training metric. In the process of validation and testing, this study randomly selects
scenarios of energy prices to be inputted into the model for solving, yielding approximate solutions
and calculating the corresponding decision losses
. The hyperparameter settings and tuning results for the four models are shown in
Table 3.
The line charts of decision loss during the hyperparameter tuning process of the four models for w-SAA are depicted in
Figure 2.
In the contextual distribution estimation method, this study trains ML models based on
and tunes hyperparameters based on
, with decision loss as the training metric. In the process of validation and testing, this study generates
estimates of energy price based on the estimated distribution
and randomly selects
scenarios of energy prices to be inputted into the model for solving, yielding approximate solutions
and calculating the corresponding decision losses
. The hyperparameter settings and tuning results for the four models are shown in
Table 4.
The line charts of decision loss during the hyperparameter tuning process of the four models for contextual distribution estimation are depicted in
Figure 3.
3.4. Discussion
The experiments are conducted on a computer with AMD Ryzen 5 4600U and 16 GB (3200 MHz) RAM under the Windows 10 operating system. The mathematical model in
Section 3.1 is implemented in Python programming language using Gurobi 9.5.2 as the solver. This study trains four ML models, i.e.,
kNN, CART, RF, and KR, based on the dataset
to implement two methods, w-SAA and contextual distribution estimation. The models are tested on the test dataset
, and the corresponding decision losses
are calculated and summarized in
Table 5.
Figure 4 illustrates the results.
From
Table 5 and
Figure 4, we can see that compared to the traditional w-SAA method, the proposed contextual distribution estimation method has similar decision loss under the
kNN, CART, and RF models, and exhibits certain advantages under the KR models. Specifically, under the
kNN model, the decision loss obtained by w-SAA is 1.78% lower than that of our proposed method; under the CART model, the decision loss obtained by w-SAA is 0.63% lower than that of our proposed method; under the RF model, the decision loss obtained by w-SAA is 3.33% lower than that of our proposed method; however, under the KR model, the decision loss obtained by our proposed method is 30.36% lower than that of w-SAA.
The results of the numerical experiments demonstrate that our proposed method, i.e., contextual distribution estimation, exhibits certain advantages under some particular scenarios, leading to a significant reduction in decision loss.