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.PointForecasts — Type
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).
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.QuantForecasts — Type
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.
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 20190107Label-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 20190107Methods
PostForecasts.findindex — Function
findindex(f::Forecasts, i::Integer)Return the index of f, for which the element of field id equals i.
PostForecasts.couple — Function
couple(fs::AbstractVector{<:T}) where T<:Union{PointForecasts, QuantForecasts}Merge elements of fs into a single Forecasts object.
PostForecasts.decouple — Function
decouple(f:<Forecasts})Return a vector of PointForecasts or QuantForecasts objects, where each element contains an individual forecast series from f.
PostForecasts.npred — Function
npred(f::Forecasts)Return the number of point forecasts in f::PointForecasts or the number of forecasted quantiles in f::QuantForecasts.
PostForecasts.setpred — Function
setpred(f::Forecasts, t::Integer, i::Integer, val::AbstractFloat)Set the element of field f.pred at indices t, i to val.
PostForecasts.getpred — Function
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.
PostForecasts.getobs — Function
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.
PostForecasts.getid — Function
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.
PostForecasts.getprob — Function
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.
PostForecasts.viewpred — Function
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.
PostForecasts.viewobs — Function
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.
PostForecasts.viewid — Function
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.
PostForecasts.viewprob — Function
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.