Demand Forecasting
Story
Imagine you have a small cookie factory. And for a few months, you stored the demand data you had each day and now, you want to use this data in a way to forecast your possible future demand. This analysis will create understanding in how your demand will behaviour and decrease waste.
However, since you are not really sure which algorithm to use, your goal is to create a dashboard with all algorithm available to choose the best fit for your factory.
Language
In this example, we are using the library called Forecasting.
Library which have native a few forecast algorithms ready to use. Here, we are exemplifying 6 functions.
It can be installed by selecting the library Forecasting
from the AIMMS Library Repository.
- Procedure pr_exampleExponentialSmoothing
This procedure is an example on how to set up a forecast using exponential smoothing.
1 empty p_estimateExponentialSmoothingTrendSeasonality;
2
3 if p_bin_useAutomaticTrendExponentialSmoothing then
4
5 forecasting::ExponentialSmoothingTune(
6 dataValues : p_historicData,
7 noObservations : count(i_day | p_historicData(i_day)),
8 alpha : p_alphaExponentialSmoothing);
9
10 elseif not p_alphaExponentialSmoothing then
11
12 webui::RequestPerformWebUIDialog(
13 title : "Settings",
14 message : "One or more settings are empty, set a value or activate the automatic tune.",
15 actions : s_OK,
16 onDone : 'webui::NoOp1');
17 return;
18 endif;
19
20 forecasting::ExponentialSmoothing(
21 dataValues : p_historicData,
22 estimates : p_estimateExponentialSmoothing,
23 noObservations : count(i_day | p_historicData(i_day)),
24 alpha : p_alphaExponentialSmoothing);
See also
To more detail, check out forecasting::ExponentialSmoothing and forecasting::ExponentialSmoothingTune documentations.
- Procedure pr_exampleExponentialSmoothingTrend
This procedure is an example on how to set up a forecast using exponential smoothing trend.
1 empty p_estimateExponentialSmoothingTrend;
2
3 if p_bin_useAutomaticTrendExponentialSmoothingTrend then
4
5 forecasting::ExponentialSmoothingTrendTune(
6 dataValues : p_historicData,
7 noObservations : count(i_day | p_historicData(i_day)),
8 alpha : p_alphaExponentialSmoothingTrend,
9 beta : p_betaExponentialSmoothingTrend);
10
11 elseif not p_alphaExponentialSmoothingTrend
12 or not p_betaExponentialSmoothingTrend then
13
14 webui::RequestPerformWebUIDialog(
15 title : "Settings",
16 message : "One or more settings are empty, set a value or activate the automatic tune.",
17 actions : s_OK,
18 onDone : 'webui::NoOp1');
19 return;
20 endif;
21
22 forecasting::ExponentialSmoothingTrend(
23 dataValues : p_historicData,
24 estimates : p_estimateExponentialSmoothingTrend,
25 noObservations : count(i_day | p_historicData(i_day)),
26 alpha : p_alphaExponentialSmoothingTrend,
27 beta : p_betaExponentialSmoothingTrend);
See also
To more detail, check out forecasting::ExponentialSmoothingTrend and forecasting::ExponentialSmoothingTrendTune documentations.
- Procedure pr_exampleExponentialSmoothingTrendSeasonality
This procedure is an example on how to set up a forecast using exponential smoothing trend seasonality.
1 empty p_estimateExponentialSmoothingTrendSeasonality;
2
3 if p_bin_useAutomaticTrendExponentialSmoothingTrendSeasonality then
4
5 forecasting::ExponentialSmoothingTrendSeasonalityTune(
6 dataValues : p_historicData,
7 noObservations : count(i_day | p_historicData(i_day)),
8 alpha : p_alphaExponentialSmoothingTrendSeasonality,
9 beta : p_betaExponentialSmoothingTrendSeasonality,
10 gamma : p_gammaExponentialSmoothingTrendSeasonality,
11 periodLength : 12);
12
13 elseif not p_alphaExponentialSmoothingTrendSeasonality
14 or not p_betaExponentialSmoothingTrendSeasonality
15 or not p_gammaExponentialSmoothingTrendSeasonality then
16
17 webui::RequestPerformWebUIDialog(
18 title : "Settings",
19 message : "One or more settings are empty, set a value or activate the automatic tune.",
20 actions : s_OK,
21 onDone : 'webui::NoOp1');
22
23 return;
24 endif;
25
26 forecasting::ExponentialSmoothingTrendSeasonality(
27 dataValues : p_historicData,
28 estimates : p_estimateExponentialSmoothingTrendSeasonality(i_day),
29 noObservations : count(i_day | p_historicData(i_day)),
30 alpha : p_alphaExponentialSmoothingTrendSeasonality,
31 beta : p_betaExponentialSmoothingTrendSeasonality,
32 gamma : p_gammaExponentialSmoothingTrendSeasonality,
33 periodLength : 12);
See also
To more detail, check out forecasting::ExponentialSmoothingTrendSeasonality and forecasting::ExponentialSmoothingTrendSeasonalityTune documentations.
- Procedure pr_exampleMovingAverage
This procedure is an example on how to set up a forecast using moving average.
1 empty p_estimateMovingAverage;
2
3 forecasting::MovingAverage(
4 dataValues : p_historicData(i_day),
5 estimates : p_estimateMovingAverage(i_day),
6 noObservations : count(i_day | p_historicData(i_day)),
7 noAveragingPeriods : 12);
See also
To more detail, check out forecasting::MovingAverage documentation.
- Procedure pr_exampleWeightedMovingAverage
This procedure is an example on how to set up a forecast using weighted moving average.
1 empty p_estimateWeightedMovingAverage;
2
3 forecasting::WeightedMovingAverage(
4 dataValues : p_historicData,
5 estimates : p_estimateWeightedMovingAverage(i_day),
6 noObservations : count(i_day | p_historicData(i_day)),
7 weights : p_weights,
8 noAveragingPeriods : p_numberOfWeights);
See also
To more detail, check out forecasting::WeightedMovingAverage documentation.
- Procedure pr_exampleSimpleLinearRegressionVCR
This procedure is an example on how to set up a forecast using linear regression.
1 empty p_costError, p_costEstimate;
2
3 forecasting::SimpleLinearRegressionVCR(
4 xIndepVarValue : p_def_machineProduction,
5 yDepVarValue : p_def_costOfProduction,
6 LRcoeff : p_coeff,
7 VariationComp : p_variationMeasure,
8 yEstimates : p_costEstimate,
9 eResiduals : p_costError);
See also
To more detail, check out forecasting::SimpleLinearRegressionVCR documentation. And the notational convention here.
WebUI Features
The following WebUI features are used:
UI Styling
Below described all UI modifications done on this example trough css
files which can be found beneath MainProject/WebUI/resourses/stylesheets
.
1:root {
2 --secondaryLightest: #ECECFD;
3 --secondaryLight: #7883b4;
4 --secondary: #4E598C;
5 --primaryDark: #FF8C42;
6 --primary: #FCAF58;
7 --primaryLight: #F9C784;
8
9 --bg_app-logo: 15px 50% / 50px 50px no-repeat url(/app-resources/resources/images/forecast.png);
10 --spacing_app-logo_width: 60px;
11 --color_bg_app-canvas: url(/app-resources/resources/images/RightBackground.png) rgb(249, 249, 249) no-repeat left/contain; /*background color*/
12 --color_border_app-header-divider: var(--primaryDark); /*line color after header*/
13
14 --color_border-divider_themed: var(--secondary);
15 --color_text_edit-select-link: var(--secondary);
16 --color_text_edit-select-link_hover: var(--primary);
17 --color_bg_edit-select-link_inverted: var(--secondary);
18 --color_bg_button_primary: var(--secondary);
19 --color_bg_button_primary_hover: var(--secondaryLight);
20 --color_text_button_secondary: var(--secondary);
21 --border_button_secondary: 1px solid var(--secondary);
22 --color_text_button_secondary_hover: var(--primary);
23 --border_button_secondary_hover: 1px solid var(--primary);
24 --color_bg_widget-header: var(--primaryLight);
25 --border_widget-header: 3px solid var(--primaryDark);
26
27 --color_bg_workflow_current: var(--primaryDark); /*bg color when step is selected*/
28 --color_workflow_active: var(--secondary); /*font and icon color when step is active*/
29 --color_workflow-icon-border: var(--secondary);
30}
1a.page-link[href$="Story"]:before {
2 content: "";
3 display: block;
4 background: url("img/idea.png") no-repeat;
5 width: 20px;
6 height: 20px;
7 float: left;
8 margin: 0 6px 0 0;
9}
10
11a.page-link[href$="Dashboard"]:before {
12 content: "";
13 display: block;
14 background: url("img/dash.png") no-repeat;
15 width: 20px;
16 height: 20px;
17 float: left;
18 margin: 0 6px 0 0;
19}
20
21a.page-link[href$="home"]:before {
22 content: "";
23 display: block;
24 background: url("img/home.png") no-repeat;
25 width: 20px;
26 height: 20px;
27 float: left;
28 margin: 0 6px 0 0;
29}
30
31a.page-link[href$="Examples"]:before {
32 content: "";
33 display: block;
34 background: url("img/example.png") no-repeat;
35 width: 20px;
36 height: 20px;
37 float: left;
38 margin: 0 6px 0 0;
39}
Minimal Requirements
AIMMS Community license is sufficient for working with this example.
Release Notes
- v1.0 (20/09/2024)
First version.