Forecasts

To make working with forecasts easy and user-friendy, PostForecasts.jl introduces the Forecasts supertype that spans PointForecasts and QuantForecast types.

PointForecasts

PointForecasts is a type designed for storing the series of point predictions (single predictions or prediction pools), along with the observations and identifiers (timestamps). The package provides functions for building PointForecasts objects from delimited files, averaging point forecasts and calculating error measures.

PostForecasts.PointForecastsType
PointForecasts(pred::AbstractVecOrMat{F}, obs::AbstractVector{F}[, id::AbstractVector{I}]) where {F<:AbstractFloat, I<:Integer}

Create PointForecasts{F, I} for storing the series of point predictions, along with the observations and identifiers.

The shape of pred should be such that pred[t, i] is the prediction for time t from the forecaster i.

If id is not provided, it will default to 1:length(obs).

source

QuantForecasts

QuantForecasts is a type designed for storing the series of probabilistic predictions, represented as quantiles of predictive distribution corresponding to probability levels, along with the observations and identifiers (timestamps). The package provides functions for computing probabilstic forecasts from PointForecasts objects, averaging distributions across quantiles or probabilities, and evaluating probabilistic forecasts.

PostForecasts.QuantForecastsType
QuantForecasts(pred::AbstractMatrix{F}, obs::AbstractVector{F}[, id::AbstractVector{I}, prob::Union{F, AbstractVector{F}}]) where {F<:AbstractFloat, I<:Integer}

Create QuantForecasts{F, I} for storing the series of probabilistic predictions, represented as quantiles of predictive distribution at specified probabilities, along with the observations and identifiers.

The shape of pred should be such that pred[t, i] is the prediction for time t of the prob[i]-quantile.

If id is not provided, it will default to 1:length(obs). If prob is not provided, it will default to size(pred, 2) equidistant quantiles.

source

Position-based indexing and slicing

PointForecasts and QuantForecasts support position-based indexing and slicing. Accessing a series with a scalar index results in a named tuple, while slicing creates a new Forecasts object built from pred, observations and identifiers stored at respective indices.

pf = loaddata(:epex1);
firstday = pf[1]
#(pred = [27.640966097698737, 24.423563275081627, 23.54144377224293, 25.061033846927558], obs = 10.07, id = 20190101)
firstweek = pf[1:7]
#PointForecasts{Float64, Int64} with a pool of 4 forecasts at 7 timesteps, between 20190101 and 20190107

Label-based indexing and slicing

Since PointForecasts and QuantForecasts objects have id field storing an integer identifier for every timestep, it is posibble to access the elements by providng their identifier values. Use () for label-based indexing and slicing. Analogously to positional indices, providing a single label results in a named tuple, while a vector creates a new Forecasts object. Additionally, you can provide two labels, (id1, id2), to return Forecasts starting at the timestep with identifier id1 and ending at the timestep with identifier id2.

pf = loaddata(:epex1);
firstday = pf(20190101)
#(pred = [27.640966097698737, 24.423563275081627, 23.54144377224293, 25.061033846927558], obs = 10.07, id = 20190101)
firstweek = pf([20190101, 20190102, 20190103, 20190104, 20190105, 20190106, 20190107])
#PointForecasts{Float64, Int64} with a pool of 4 forecasts at 7 timesteps, between 20190101 and 20190107
firstweek2 = pf(20190101, 20190107) # same as `firstweek`
#PointForecasts{Float64, Int64} with a pool of 4 forecasts at 7 timesteps, between 20190101 and 20190107

Methods

PostForecasts.coupleFunction
couple(fs::AbstractVector{<:T}) where T<:Union{PointForecasts, QuantForecasts}

Merge elements of fs into a single Forecasts object.

source
PostForecasts.decoupleFunction
decouple(f:<Forecasts})

Return a vector of PointForecasts or QuantForecasts objects, where each element contains an individual forecast series from f.

source
PostForecasts.npredFunction
npred(f::Forecasts)

Return the number of point forecasts in f::PointForecasts or the number of forecasted quantiles in f::QuantForecasts.

source
PostForecasts.setpredFunction
setpred(f::Forecasts, t::Integer, i::Integer, val::AbstractFloat)

Set the element of field f.pred at indices t, i to val.

source
PostForecasts.getpredFunction
getpred(f::Forecasts[, T, I])

Return the copy of predictions from f.

Provide optional argument T::Union{Integer, AbstractVector{<:Integer}} to get predictions at specified time indices.

Additionally, provide I::Union{Integer, AbstractVector{<:Integer}} to get predicitons at specified forecast indices.

source
PostForecasts.getobsFunction
getobs(f::Forecasts[, T])

Return the copy of observations from f.

Provide optional argument T::Union{Integer, AbstractVector{<:Integer}} to get observations at specified time indices.

source
PostForecasts.getidFunction
getid(f::Forecasts[, T])

Return the copy of identifiers from f.

Provide optional argument T::Union{Integer, AbstractVector{<:Integer}} to get identifiers at specified time indices.

source
PostForecasts.getprobFunction
getprob(qf::QuantForecasts[, I])

Return the copy of probabilities from qf.

Provide optional argument I::Union{Integer, AbstractVector{<:Integer}} to get probabilities at specified forecast indices.

source
PostForecasts.viewpredFunction
viewpred(f::Forecasts[, T, I])

Return the view of predictions from f.

Provide optional argument T::Union{Integer, AbstractVector{<:Integer}} to get predictions at specified time indices.

Additionally, provide I::Union{Integer, AbstractVector{<:Integer}} to get predicitons at specified forecast indices.

source
PostForecasts.viewobsFunction
viewobs(f::Forecasts[, T])

Return the view of observations from f.

Provide optional argument T::Union{Integer, AbstractVector{<:Integer}} to get observations at specified time indices.

source
PostForecasts.viewidFunction
viewid(f::Forecasts[, T])

Return the view of identifiers from f.

Provide optional argument T::Union{Integer, AbstractVector{<:Integer}} to get identifiers at specified time indices.

source
PostForecasts.viewprobFunction
viewprob(qf::QuantForecasts[, I])

Return the view of probabilities from qf.

Provide optional argument I::Union{Integer, AbstractVector{<:Integer}} to get probabilities at specified forecast indices.

source