From a0d7734d2ca1f26f48cde9b34e60e5093cf6cc04 Mon Sep 17 00:00:00 2001 From: eduzenli Date: Mon, 13 May 2024 11:40:27 +0200 Subject: [PATCH 1/3] dimension problem with 2 categories has been solved --- R/LogisticReg.R | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/R/LogisticReg.R b/R/LogisticReg.R index d42c39e..a14f3d9 100644 --- a/R/LogisticReg.R +++ b/R/LogisticReg.R @@ -532,13 +532,6 @@ LogisticReg <- function(exp, obs, exp_cor = NULL, exp_lats, exp_lons, obs_lats, } ## case hindcast - forecast else { - if ( time_dim %in% names(dim(predictor)) ) { - if (dim(predictor)[time_dim] > 1) { - target_dims_predictor <- c(target_dims_predictor, time_dim) - target_dims_predictand <- c(target_dims_predictand, time_dim) - target_dims_forecast <- c(target_dims_forecast, time_dim) - } - } res <- Apply(list(predictor, obs_cat, forecast), target_dims = list(target_dims_predictor, target_dims_predictand, target_dims_forecast), @@ -698,9 +691,9 @@ LogisticReg <- function(exp, obs, exp_cor = NULL, exp_lats, exp_lons, obs_lats, pred_vals <- do.call(rbind, pred_vals_ls) if( length(probs_cat) + 1 == 2) { - pred_vals_dum<-array(NA, dim=c(nrow(df), 2)) - pred_vals_dum[, 2]<-pred_vals - pred_vals_dum[, 1] <- 1-pred_vals + pred_vals_dum<-array(NA, dim = c(nrow(df), 2)) + pred_vals_dum[, 2] <- t(pred_vals) + pred_vals_dum[, 1] <- 1 - pred_vals_dum[, 2] pred_vals <- pred_vals_dum colnames(pred_vals) <- c(1, 2) } @@ -715,8 +708,8 @@ LogisticReg <- function(exp, obs, exp_cor = NULL, exp_lats, exp_lons, obs_lats, if( length(probs_cat) + 1 == 2) { pred_vals_dum <- array(NA, dim = c(nrow(df), 2)) - pred_vals_dum[, 2] <- pred_vals - pred_vals_dum[, 1] <- 1 - pred_vals + pred_vals_dum[, 2] <- t(pred_vals) + pred_vals_dum[, 1] <- 1 - pred_vals_dum[, 2] pred_vals<-pred_vals_dum colnames(pred_vals) <- c(1,2) } -- GitLab From 4c274002ff9110a8535b04f7bb11aaa79cc8a032 Mon Sep 17 00:00:00 2001 From: eduzenli Date: Mon, 13 May 2024 11:41:00 +0200 Subject: [PATCH 2/3] dimension problem of observational return has been solved --- R/Intlr.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/Intlr.R b/R/Intlr.R index 6f7e124..3f97fc6 100644 --- a/R/Intlr.R +++ b/R/Intlr.R @@ -614,6 +614,7 @@ Intlr <- function(exp, obs, exp_cor = NULL, exp_lats, exp_lons, obs_lats, obs_lo if ( time_dim %in% names(dim(predictor)) ) { daily <- TRUE k_out <- as.numeric (dim(predictor)[time_dim]) ## in case loocv = TRUE and the data is daily, leave one-year data out + sdate_num <- as.numeric (dim(predictand)[sdate_dim]) ## sdate_num of hindcast predictor <- MergeDims (predictor, merge_dims = c(time_dim, sdate_dim), rename_dim = sdate_dim) predictand <- MergeDims (predictand, merge_dims = c(time_dim, sdate_dim), rename_dim = sdate_dim) output_dims <- c(time_dim, sdate_dim) # for hindcast dwn @@ -646,9 +647,14 @@ Intlr <- function(exp, obs, exp_cor = NULL, exp_lats, exp_lons, obs_lats, obs_lo output_dims = output_dims)$output1 } + if (daily) { + predictand <- SplitDim(data = predictand, split_dim = sdate_dim, new_dim_name = time_dim, + indices = rep (1:k_out, sdate_num)) + } + # restore ensemble dimension in observations if it existed originally if (restore_ens) { - predictand <- s2dv::InsertDim(predictand, posdim = 1, lendim = 1, name = member_dim) + predictand <- MergeDims (predictand, merge_dims = c(time_dim, sdate_dim), rename_dim = sdate_dim) } # Return a list of three elements -- GitLab From 2888c2cec0b700155c02c7ac1596995ab4b2459b Mon Sep 17 00:00:00 2001 From: eduzenli Date: Mon, 13 May 2024 12:01:08 +0200 Subject: [PATCH 3/3] fine tuning --- R/Intlr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Intlr.R b/R/Intlr.R index 3f97fc6..beb8d7e 100644 --- a/R/Intlr.R +++ b/R/Intlr.R @@ -649,7 +649,7 @@ Intlr <- function(exp, obs, exp_cor = NULL, exp_lats, exp_lons, obs_lats, obs_lo if (daily) { predictand <- SplitDim(data = predictand, split_dim = sdate_dim, new_dim_name = time_dim, - indices = rep (1:k_out, sdate_num)) + indices = rep (1:k_out, sdate_num)) } # restore ensemble dimension in observations if it existed originally -- GitLab