Diagrams and Pseudocode

In this section we present the conceptual diagrams of the proposed methodology, besides the pseudocode in R, which shows its high level functional behavior.

 

General scheme:General scheme for this methodology

Figure 1.- Forecasting Methodology - General Scheme

 

General scheme pseudocode

Input:

w_data: Workload data

Output:

models: Prediction models obtained with the methodology applied.

results: Scores of RelMAE, sMAPE, C_up and C_op measures

# Creating subsets of data for appropriate processing

[train,test]=createDataPartition(w_data)

 

# Time series analysis (Analytical process)

# Definition of posible lags and invervals

intervals=c(5,60) #Typical ranges study this type of problem

lags=which(max(pacf(train)[-1]))

[lags,intervals]=define(lags, intervals)

 

# Create corresponding data structures (lags and prediction intervals)

for lag in lags

  for inter in intervals

    ts_datasets_cases=importATSListIntoDataRepository(train, lag, inter)

 

for ts_data in ts_datasets_cases

  # Non-seasonal study

  if(struct(ts_data)==Non-seasonal struct){

    [results_ns, models_ns]=non_seasonal_study(ts_data)

    export([results_ns, models_ns])

  }

  # Seasonal study

  else{

    [results_s, models_s]= seasonal_study(ts_data)

    export([results_s, models_s])

  }


Analytical Process:

Analytical Process of the time series.

Figure 2.- Forecasting Methodology - Analytical Process

 

Analytical Process scheme pseudocode

Input:

train: train dataset

Output:

params: lags and seasonality

#Time series analysis

plot.ts(train)

acf(train)

pacf(train)

 

# Study lags and seasonality

params=[lags, seasonality]

 

# Is stationary time series studied?

for i in length(lags){

  box_test=Box.test(ts, lag = lags[i], type = c("Ljung-Box"), fitdf = p+q)           #Arima.model(p,d,q)

  if(box_test$p.value>0.05){ #It can not reject the null hypothesis.  

    apply_non_seasonal_study(train)

  }else{ #The null hypothesis is rejected,

    #The differentiation of the time series studied could obtain stationarity.

    train=diff(train)

    params=ts_analysis(train)

  }

}


Non-seasonal Study:

Non-seasonal Study scheme

 Figure 3.- Forecasting Methodology - Non-seasonal Study

 

 

Non-seasonal Study scheme pseudocode

Input:

train: train dataset

test: test dataset

params: lags and prediction intervals

Output:

models: Prediction models obtained with the methodology applied.

results: Scores of RelMAE, sMAPE, C_up and C_op measures

# Create corresponding data structures (lags and prediction intervals)

train= importATSListIntoDataRepository(train,params)

 

# Linear series test

linear=terasvirta.test(train)

if(linear$p.value>0.05){ #We can not reject the presence of linearity in the data.

  #Apply non-seasonal arima and ets models

  mod_arima=auto.arima(train, seasonal=FALSE)

  mod_ets=ets(train) # ETS not study seasonal behavior

  res_arima=pred(test, mod_arima)

  res_ets=pred(test, mod_ets)

  models=c(mod_arima,mod_ets)

  results=c(res_arima, res_ets)

 

  # Apply evaluation criteria

  for i in length(results){

    aux[i]=c(RelMAE(results[i]),sMAPE(results[i])) # sMAPE in percent (if greater than 10%'ll take that as a negative result)

    box_results[i]=Box.test(residuals(models[i]))

    if(box_result[i]$p.value < 0.05){ #Not independent residuals

      seasonal[i]=TRUE

      break

    }

    if(aux[i][1]>=1 || aux[i][2]>=10){ # Get bad results in the evaluation criteria used (RelME, SMAPE, C_up and C_op)

      break

    }else{

      seasonal[i]=TRUE

      break

    }

  }

}

if(seasonal[1]==TRUE){ # Seasonal study on Arima models (ETS not have seasonal study)

  [models_s_arima, results_s_arima]=apply_seasonal_study_arima(train)

  export=[models_s_arima, results_s_arima]

}

#Apply generic models 

[models, results]=apply_generic_models(train)

 

#Obtain models and results for generic models

[models_ns, results_ns]=apply_evalution_criteria([models, results])

export([models_ns, results_ns])

 

#Apply seasonal study for generic models

[models_s, results_s]=apply_seasonal_study(train)

export=([models_s, results_s])