RAnEnExtra::weightSearch is a grid search function for weight optimization.

weightSearch(
  weights,
  forecasts,
  observations,
  test.times,
  search.times,
  config,
  metric = "RMSE",
  return.best.only = F,
  combine.weights = T,
  ...
)

Arguments

weights

Either a numeric matrix or a single numeral. If it is a matrix, each row is a certain weight combination and the number of rows equal to the number of iterations; if it is a single numeral, it is the number of iterations and the weights will be randomly generated.

forecasts

Forecasts for RAnEn::generateAnalogs.Forecasts

observations

Observations for RAnEn::generateAnalogs.Forecasts

test.times

Test times for RAnEn::generateAnalogs.Forecasts

search.times

Search times for RAnEn::generateAnalogs.Forecasts

config

Config for RAnEn::generateAnalogs.Forecasts

metric

This can either be a function or a metric for RAnEnExtra::verify. If it is a metric, please note two things: (1) the member mean exists in the verification results because it is used to evaluate different combinations of weights; (2) it is assumed that the metric is an error measurement so that the lowest metric is considered the best, when return.best.only = T. If it is a function, the first two arguments are obs.aligned and AnEn$analogs. obs.aligned is a 3-dimensional array of shape [stations, times, lead times], and AnEn$analogs is a 4-dimensional array of shape [stations, times, lead times, members]. The return of this function is the error metric.

return.best.only

Whether to only return the best combination of weights

combine.weights

Whether to combine errors as an extra column to weight matrix. This does not work when metric is a function that returns multiple values.

...

Extra parameters for metric if it is a function

Value

Either a vector or a matrix. If a vector is returned, it is the best combination of weights; if a matrix is returned, it is the combinations of weights that have been searched and the last column is the verification metric.