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 pred
ictions (single predictions or prediction pools), along with the obs
ervations and id
entifiers (timestamps). The package provides functions for building PointForecasts
objects from delimited files, averaging point forecasts and calculating error measures.
PostForecasts.PointForecasts
— TypePointForecasts(pred::AbstractVecOrMat{F}, obs::AbstractVector{F}[, id::AbstractVector{I}]) where {F<:AbstractFloat, I<:Integer}
Create PointForecasts{F, I}
for storing the series of point pred
ictions, along with the obs
ervations and id
entifiers.
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 pred
ictions, represented as quantiles of predictive distribution corresponding to prob
ability levels, along with the obs
ervations and id
entifiers (timestamps). The package provides functions for computing probabilstic forecasts from PointForecasts
objects, averaging distributions across quantiles or probabilities, and evaluating probabilistic forecasts.
PostForecasts.QuantForecasts
— TypeQuantForecasts(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 pred
ictions, represented as quantiles of predictive distribution at specified prob
abilities, along with the obs
ervations and id
entifiers.
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 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 id
entifier 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.findindex
— Functionfindindex(f::Forecasts, i::Integer)
Return the index of f
, for which the element of field id
equals i
.
PostForecasts.couple
— Functioncouple(fs::AbstractVector{<:T}) where T<:Union{PointForecasts, QuantForecasts}
Merge elements of fs
into a single Forecasts
object.
PostForecasts.decouple
— Functiondecouple(f:<Forecasts})
Return a vector of PointForecasts
or QuantForecasts
objects, where each element contains an individual forecast series from f
.
PostForecasts.npred
— Functionnpred(f::Forecasts)
Return the number of point forecasts in f::PointForecasts
or the number of forecasted quantiles in f::QuantForecasts
.
PostForecasts.setpred
— Functionsetpred(f::Forecasts, t::Integer, i::Integer, val::AbstractFloat)
Set the element of field f.pred
at indices t, i
to val
.
PostForecasts.getpred
— Functiongetpred(f::Forecasts[, T, I])
Return the copy of pred
ictions from f
.
Provide optional argument T::Union{Integer, AbstractVector{<:Integer}}
to get pred
ictions at specified time indices.
Additionally, provide I::Union{Integer, AbstractVector{<:Integer}}
to get pred
icitons at specified forecast indices.
PostForecasts.getobs
— Functiongetobs(f::Forecasts[, T])
Return the copy of obs
ervations from f
.
Provide optional argument T::Union{Integer, AbstractVector{<:Integer}}
to get obs
ervations at specified time indices.
PostForecasts.getid
— Functiongetid(f::Forecasts[, T])
Return the copy of id
entifiers from f
.
Provide optional argument T::Union{Integer, AbstractVector{<:Integer}}
to get id
entifiers at specified time indices.
PostForecasts.getprob
— Functiongetprob(qf::QuantForecasts[, I])
Return the copy of prob
abilities from qf
.
Provide optional argument I::Union{Integer, AbstractVector{<:Integer}}
to get prob
abilities at specified forecast indices.
PostForecasts.viewpred
— Functionviewpred(f::Forecasts[, T, I])
Return the view of pred
ictions from f
.
Provide optional argument T::Union{Integer, AbstractVector{<:Integer}}
to get pred
ictions at specified time indices.
Additionally, provide I::Union{Integer, AbstractVector{<:Integer}}
to get pred
icitons at specified forecast indices.
PostForecasts.viewobs
— Functionviewobs(f::Forecasts[, T])
Return the view of obs
ervations from f
.
Provide optional argument T::Union{Integer, AbstractVector{<:Integer}}
to get obs
ervations at specified time indices.
PostForecasts.viewid
— Functionviewid(f::Forecasts[, T])
Return the view of id
entifiers from f
.
Provide optional argument T::Union{Integer, AbstractVector{<:Integer}}
to get id
entifiers at specified time indices.
PostForecasts.viewprob
— Functionviewprob(qf::QuantForecasts[, I])
Return the view of prob
abilities from qf
.
Provide optional argument I::Union{Integer, AbstractVector{<:Integer}}
to get prob
abilities at specified forecast indices.