View source: R/scoreopt_functions.R
scoreopt | R Documentation |
Function to find a reconciliation matrix that optimises total score using training data. Stochastic gradient descent is used for optimisation with gradients found using automatic differentiation.
scoreopt(
data,
prob,
S,
Ginit = c(rep(0, ncol(S)), as.vector(solve(t(S) %*% S, t(S)))),
control = list(),
score = list(score = "energy", alpha = 1),
trace = FALSE,
matches = FALSE
)
data |
Past data realisations as vectors in a list. Each list element corresponds to a period of training data. |
prob |
List of functions to simulate from probabilistic forecasts. Each list element corresponds to a period of training data. The output of each function should be a matrix. |
S |
Matrix encoding linear constraints. |
Ginit |
Initial values of reconciliation parameters |
control |
Tuning parameters for SGD. See |
score |
Score to be used. This must be a list with two elements: score for the scoring rule (currently only energy score and variogram score supported) and alpha, an additional parameter used in the score (e.g. power in energy score, default is 1). |
trace |
Flag to keep details of SGD. Default is FALSE |
matches |
A flag that checks for exact matches between samples from reconciled distribution. This causes NaNs in the automatic differentiation. For approaches that rely on bootstrapping set to TRUE. Otherwise set to FALSE (the default) to speed up code. |
Optimised reconciliation parameters.
d |
Translation vector for reconciliation. |
G |
Reconciliation matrix. |
val |
The estimated optimal total score. |
Gvec_store |
A matrix of Gvec ( |
val_store |
A vector where each element gives the value of the objective function for each iterate of SGD (only produced when trace=TRUE). |
Other ProbReco functions:
inscoreopt()
,
scoreopt.control()
,
total_score()
#Use purr library to setup
library(purrr)
#Define S matrix
S<-matrix(c(1,1,1,0,0,1),3,2, byrow = TRUE)
#Set data (only 10 training observations used for speed)
data<-map(1:10,function(i){S%*%(c(1,1)+rnorm(2))})
#Set list of functions to generate 50 iterates from probabilistic forecast
prob<-map(1:10,function(i){f<-function(){matrix(rnorm(3*50),3,50)}})
#Find weights by SGD (will take a few seconds)
out<-scoreopt(data,prob,S)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.