Title: | Echo State Networks for Time Series Modeling and Forecasting |
---|---|
Description: | Provides a lightweight implementation of functions and methods for fast and fully automatic time series modeling and forecasting using Echo State Networks (ESNs). |
Authors: | Alexander Häußer [aut, cre, cph] |
Maintainer: | Alexander Häußer <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2025-03-04 15:25:19 UTC |
Source: | https://github.com/ahaeusser/echos |
This function trains an Echo State Network (ESN) to a univariate time series.
ESN(formula, ...)
ESN(formula, ...)
formula |
Model specification (currently not in use). |
... |
Further arguments passed to |
An object of class ESN
.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value))
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value))
Extract fitted values from a trained ESN.
## S3 method for class 'ESN' fitted(object, ...)
## S3 method for class 'ESN' fitted(object, ...)
object |
An object of class |
... |
Currently not in use. |
Fitted values extracted from the object.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% fitted()
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% fitted()
Forecast an Echo State Network from a trained model.
forecast_esn(object, n_ahead = 18)
forecast_esn(object, n_ahead = 18)
object |
An object of class |
n_ahead |
Integer value. The number of periods for forecasting (i.e. forecast horizon). |
A list
containing:
point
: Numeric vector containing the point forecasts.
actual
: Numeric vector containing the actual values.
fitted
: Numeric vector containing the fitted values.
n_ahead
: Integer value. The number of periods for forecasting (forecast horizon).
model_spec
: Character value. The model specification as string.
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) xfcst <- forecast_esn(xmodel, n_ahead = 12) plot(xfcst)
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) xfcst <- forecast_esn(xmodel, n_ahead = 12) plot(xfcst)
Forecast a trained ESN.
## S3 method for class 'ESN' forecast(object, new_data, specials = NULL, xreg = NULL, ...)
## S3 method for class 'ESN' forecast(object, new_data, specials = NULL, xreg = NULL, ...)
object |
An object of class |
new_data |
Forecast horizon (n-step ahead forecast) |
specials |
Currently not in use |
xreg |
A |
... |
Currently not in use. |
An object of class fable
.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% forecast(h = 18)
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% forecast(h = 18)
Return summary statistics from trained ESN models during random search as tibble.
model
: Model identifier.
loglik
: Log-likelihood.
nobs
: Number of observations.
df
: Effective degrees of freedom.
lambda
: Regularization parameter.
aic
: Akaike Information Criterion.
aicc
: Corrected Akaike Information Criterion.
bic
: Bayesian Information Criterion.
hqc
: Hannan-Quinn Information Criterion.
mse
: Mean Squared Error.
mae
: Mean Absolute Error.
## S3 method for class 'ESN' glance(x, ...)
## S3 method for class 'ESN' glance(x, ...)
x |
An object of class |
... |
Currently not in use. |
Summary statistics extracted from the object.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% glance()
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% glance()
Returns TRUE
if the object is of class "esn".
is.esn(object)
is.esn(object)
object |
object to be tested. |
Logical value. If TRUE
, the object is of class "esn".
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) is.esn(xmodel)
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) is.esn(xmodel)
Returns TRUE
if the object is of class "forecast_esn".
is.forecast_esn(object)
is.forecast_esn(object)
object |
object to be tested. |
Logical value. If TRUE
, the object is of class "forecast_esn".
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) xfcst <- forecast_esn(xmodel, n_ahead = 12) is.forecast_esn(xfcst)
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) xfcst <- forecast_esn(xmodel, n_ahead = 12) is.forecast_esn(xfcst)
Monthly tsibble with six exemplary time series from the M4 Forecasting Competition.
data(m4_data)
data(m4_data)
A time series object of class tsibble
with 1.152 rows and 4 columns:
series
: Unique identifier as character
(key variable).
category
: Category (e.g., Demographic, Macro) as factor
.
index
: Date as yearmonth
(index variable).
value
: Value as numeric
(measurement variable).
data(m4_data)
data(m4_data)
Provide a succinct summary of a trained ESN.
## S3 method for class 'ESN' model_sum(x)
## S3 method for class 'ESN' model_sum(x)
x |
An object of class |
Model summary extracted from the object.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value))
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value))
Plot point forecasts, actual and fitted values of a trained ESN model as line chart. Optionally, test data (out-of-sample) can be added to the plot.
## S3 method for class 'forecast_esn' plot(x, test = NULL, fitted = TRUE, ...)
## S3 method for class 'forecast_esn' plot(x, test = NULL, fitted = TRUE, ...)
x |
An object of class |
test |
Numeric vector. Test data, i.e., out-of-sample actual values. |
fitted |
Logical value. If |
... |
Currently not in use. |
Line chart of point forecast and actual values.
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) xfcst <- forecast_esn(xmodel, n_ahead = 12) plot(xfcst)
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) xfcst <- forecast_esn(xmodel, n_ahead = 12) plot(xfcst)
Print model specification of the trained ESN model.
## S3 method for class 'esn' print(x, ...)
## S3 method for class 'esn' print(x, ...)
x |
An object of class |
... |
Currently not in use. |
Print specification of the trained ESN model.
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) print(xmodel)
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) print(xmodel)
Provide a detailed summary of the trained ESN model.
## S3 method for class 'ESN' report(object, ...)
## S3 method for class 'ESN' report(object, ...)
object |
An object of class |
... |
Currently not in use. |
Print detailed model summary.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% report()
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% report()
Return the reservoir (internal states) from a
trained ESN as tibble. The function works only for models
of class ESN
.
reservoir(object)
reservoir(object)
object |
An object of class |
A tibble containing the reservoir (internal states).
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% reservoir()
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% reservoir()
Extract residuals from a trained ESN.
## S3 method for class 'ESN' residuals(object, ...)
## S3 method for class 'ESN' residuals(object, ...)
object |
An object of class |
... |
Currently not in use. |
Residuals extracted from the object.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% residuals()
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% residuals()
Run reservoir creates the internal states for the ESN.
input |
Numeric matrix containing the input features |
win |
Numeric matrix. The input weight matrix. |
wres |
Numeric matrix. The reservoir weight matrix. |
alpha |
Numeric value. The leakage rate (smoothing parameter). |
states train Numeric matrix with the internal states.
Provide a detailed summary of the trained ESN model.
## S3 method for class 'esn' summary(object, ...)
## S3 method for class 'esn' summary(object, ...)
object |
An object of class |
... |
Currently not in use. |
Print detailed model summary.
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) summary(xmodel)
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) summary(xmodel)
Return the estimated coefficients from a trained ESN as tibble.
## S3 method for class 'ESN' tidy(x, ...)
## S3 method for class 'ESN' tidy(x, ...)
x |
An object of class |
... |
Currently not in use. |
Coefficients extracted from the object.
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% tidy()
library(tsibble) library(fable) AirPassengers %>% as_tsibble() %>% model("ESN" = ESN(value)) %>% tidy()
This function trains an Echo State Network (ESN) to a univariate time series.
train_esn( y, lags = 1, inf_crit = "bic", n_diff = NULL, n_states = NULL, n_models = NULL, n_initial = NULL, n_seed = 42, alpha = 1, rho = 1, density = 0.5, lambda = c(1e-04, 2), scale_win = 0.5, scale_wres = 0.5, scale_inputs = c(-0.5, 0.5) )
train_esn( y, lags = 1, inf_crit = "bic", n_diff = NULL, n_states = NULL, n_models = NULL, n_initial = NULL, n_seed = 42, alpha = 1, rho = 1, density = 0.5, lambda = c(1e-04, 2), scale_win = 0.5, scale_wres = 0.5, scale_inputs = c(-0.5, 0.5) )
y |
Numeric vector containing the response variable. |
lags |
Integer vectors with the lags associated with the input variable. |
inf_crit |
Character value. The information criterion used for variable selection |
n_diff |
Integer vector. The nth-differences of the response variable. |
n_states |
Integer value. The number of internal states per reservoir. |
n_models |
Integer value. The maximum number of (random) models to train for model selection. |
n_initial |
Integer value. The number of observations of internal states for initial drop out (throw-off). |
n_seed |
Integer value. The seed for the random number generator (for reproducibility). |
alpha |
Numeric value. The leakage rate (smoothing parameter) applied to the reservoir. |
rho |
Numeric value. The spectral radius for scaling the reservoir weight matrix. |
density |
Numeric value. The connectivity of the reservoir weight matrix (dense or sparse). |
lambda |
Numeric vector. Lower and upper bound of lambda sequence for ridge regression. |
scale_win |
Numeric value. The lower and upper bound of the uniform distribution for scaling the input weight matrix. |
scale_wres |
Numeric value. The lower and upper bound of the uniform distribution for scaling the reservoir weight matrix. |
scale_inputs |
Numeric vector. The lower and upper bound for scaling the time series data. |
A list
containing:
actual
: Numeric vector containing the actual values.
fitted
: Numeric vector containing the fitted values.
resid
: Numeric vector containing the residuals.
states_train
: Numeric matrix containing the internal states.
method
: A list
containing several objects and meta information of the trained ESN (weight matrices, hyperparameters, model metrics, etc.).
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) summary(xmodel)
xdata <- as.numeric(AirPassengers) xmodel <- train_esn(y = xdata) summary(xmodel)