scoreopt: Score optimisation by Stochastic Gradient Descent

Description Usage Arguments Value See Also Examples

View source: R/scoreopt_functions.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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
)

Arguments

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 d and G where \tilde{y}=S(d+G\hat{y}). The first m elements correspond to a translation vector d, while the remaining elements correspond to the matrix G where the elements are filled in column-major order. Default is least squares.

control

Tuning parameters for SGD. See scoreopt.control for more details

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.

Value

Optimised reconciliation parameters.

d

Translation vector for reconciliation.

G

Reconciliation matrix.

val

The estimated optimal total score.

Gvec_store

A matrix of Gvec (d and G vectorised) where each column corresponds to an iterate of SGD (only produced when trace=TRUE).

val_store

A vector where each element gives the value of the objective function for each iterate of SGD (only produced when trace=TRUE).

See Also

Other ProbReco functions: inscoreopt(), scoreopt.control(), total_score()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#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)

ProbReco documentation built on Jan. 13, 2021, 6:12 p.m.