Demand Forecasting

https://img.shields.io/badge/AIMMS_4.88-ZIP:_Demand_Forecasting-blue https://img.shields.io/badge/AIMMS_4.88-Github:_Demand_Forecasting-blue https://img.shields.io/badge/AIMMS_Community-Forum-yellow

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);
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
12    --color_border-divider_themed: var(--secondary);
13    --color_text_edit-select-link: var(--secondary);
14    --color_text_edit-select-link_hover: var(--primary);
15    --color_bg_edit-select-link_inverted: var(--secondary);
16    --color_bg_button_primary: var(--secondary);
17    --color_bg_button_primary_hover: var(--secondaryLight);
18    --color_text_button_secondary: var(--secondary);
19    --border_button_secondary: 1px solid var(--secondary);
20    --color_text_button_secondary_hover: var(--primary);
21    --border_button_secondary_hover: 1px solid var(--primary);
22    --color_bg_widget-header: var(--primaryLight);
23    --border_widget-header: 3px solid var(--primaryDark);
24}
 1/*Add logo on the background*/
 2.scroll-wrapper--pagev2 .page-container {
 3    content: " ";
 4    background: url(img/RightBackground.png) rgb(249, 249, 249) no-repeat left/contain;
 5}
 6
 7/*Changing tittle to be uppercase*/
 8.title-addon {
 9    text-transform: uppercase;
10    text-shadow: 1px 1px 2px var(--secondaryLightest);
11}
12
13/*Changing button font*/
14.ui-widget, .ui-widget button, .ui-widget input, .ui-widget select, .ui-widget textarea {
15    font-family: var(--font_headers),Montserrat,Roboto,Arial,Helvetica,sans-serif;
16}
1.aimms-widget .ui-button {
2    text-transform: uppercase;
3}
4
5/*Change checkbox color*/
6input.boolean-cell-editor-contents {
7    accent-color: var(--secondary);
8}
 1/*Change color of the active step*/
 2.workflow-panel .step-item.current,
 3.workflow-panel.collapse .step-item.current {
 4    box-shadow: inset 0.3125rem 0 0 var(--secondary);
 5}
 6
 7/*Change color of the titles*/
 8.workflow-panel .step-item.active.complete .title,
 9.workflow-panel .step-item.active.incomplete .title {
10    color: var(--secondary);
11}
12
13/*Change color of the icons*/
14.workflow-panel .step-item.active.complete .icon,
15.workflow-panel .step-item.active.incomplete .icon {
16    color: var(--secondary);
17    border: 2px solid var(--secondary);
18}
1/*Link color*/
2.ql-snow a {
3    color: var(--primaryDark);
4}
5
6/*Change checkbox color*/
7input.boolean-cell-editor-contents {
8    accent-color: var(--secondary);
9}

Minimal Requirements

AIMMS Community license is sufficient for working with this example.