Skip to content

Commit

Permalink
news and bug fix in downscaleCV
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge committed Feb 5, 2020
1 parent 4030b40 commit 3e7bf98
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

See the [Releases section](https://github.com/SantanderMetGroup/downscaleR/releases) for older version changes


## v3.0.0 (14 Jun 2018)

* New user interface for flexible definition of predictors (`prepareData`) and prediction data (`prepareNewData`).
Expand Down Expand Up @@ -49,3 +50,10 @@ See the [Releases section](https://github.com/SantanderMetGroup/downscaleR/relea
* downscale.predict renamed --> downscalePredict
* Other minor changes and documentation updates

## v3.1.1 (5 Feb 2020)

* Bug fix in `downscaleCV'
* Improve the internal code of `downscaleChunk'
* Add qdm and dqm bias correction methods
* Bug fix in `biasCorrection'

38 changes: 20 additions & 18 deletions R/downscaleCV.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#' @param y The observations dataset. It should be an object as returned by \pkg{loadeR}.
#' @param method A string value. Type of transer function. Currently implemented options are \code{"analogs"}, \code{"GLM"} and \code{"NN"}.
#' @param sampling.strategy Specifies a sampling strategy to define the training and test subsets. Possible values are
#' \code{"kfold.chronological"} (the default), \code{"kfold.random"} and \code{"leave-one-year-out"}.
#' \code{"kfold.chronological"} (the default), \code{"kfold.random"}, \code{"leave-one-year-out"} and NULL.
#' The \code{sampling.strategy} choices are next described:
#' \itemize{
#' \item \code{"kfold.random"} creates the number of folds indicated in the \code{folds} argument by randomly sampling the entries along the time dimension.
#' \item \code{"kfold.chronological"} is similar to \code{"kfold.random"}, but the sampling is performed in ascending order along the time dimension.
#' \item \code{"leave-one-year-out"}. This schema performs a leave-one-year-out cross validation. It is equivalent to introduce in the argument \code{folds} a list of all years one by one.
#' \item \code{"leave-one-year-out"}. This scheme performs a leave-one-year-out cross validation. It is equivalent to introduce in the argument \code{folds} a list of all years one by one.
#' \item \code{NULL}. The folds are specified by the user in the function parameter \code{folds}.
#' }
#' The first two choices will be controlled by the argument \code{folds} (see below)
#' @param folds This arguments controls the number of folds, or how these folds are created (ignored if \code{sampling.strategy = "leave-one-year-out"}). If it is given as a fraction in the range (0-1),
Expand Down Expand Up @@ -120,24 +121,25 @@ downscaleCV <- function(x, y, method,
x <- getTemporalIntersection(x,y,which.return = "obs")
y <- getTemporalIntersection(x,y,which.return = "prd")

if (sampling.strategy == "leave-one-year-out") {
type <- "chronological"
folds <- as.list(getYearsAsINDEX(y) %>% unique())
}

if (sampling.strategy == "kfold.chronological") {
type <- "chronological"
if (!is.numeric(folds)) {
folds.user <- unlist(folds) %>% unique() %>% sort()
folds.data <- getYearsAsINDEX(y) %>% unique()
if (any(folds.user != folds.data)) stop("In the parameters folds you have indicated years that do not belong to the dataset. Please revise the setup of this parameter.")
if (!is.null(sampling.strategy)) {
if (sampling.strategy == "leave-one-year-out") {
type <- "chronological"
folds <- as.list(getYearsAsINDEX(y) %>% unique())
}

if (sampling.strategy == "kfold.chronological") {
type <- "chronological"
if (!is.numeric(folds)) {
folds.user <- unlist(folds) %>% unique() %>% sort()
folds.data <- getYearsAsINDEX(y) %>% unique()
if (any(folds.user != folds.data)) stop("In the parameters folds you have indicated years that do not belong to the dataset. Please revise the setup of this parameter.")
}
}
if (sampling.strategy == "kfold.random") {
type <- "random"
if (!is.numeric(folds)) stop("In kfold.random, the parameter folds represent the NUMBER of folds and thus, it should be a NUMERIC value.")
}
}
if (sampling.strategy == "kfold.random") {
type <- "random"
if (!is.numeric(folds)) stop("In kfold.random, the parameter folds represent the NUMBER of folds and thus, it should be a NUMERIC value.")
}

if (is.list(folds)) {
if (any(duplicated(unlist(folds)))) stop("Years can not appear in more than one fold")
}
Expand Down
5 changes: 3 additions & 2 deletions man/downscaleCV.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e7bf98

Please sign in to comment.