# =========================================================================
# Cross validation mode for best OLS combination model (bocm)
# dependence: bocm.R and bocm_wrapper.R 
# requires Exp to be a two dimensional array (no. of years * no. of exp)
# requires Obs to be a vector of length=no. of years
# =========================================================================


# Data_WMMt <- Data_WMM[,,16,25]
# Exp <- Data_WMMt[,1:4]
# Obs <- Data_WMMt[,5]


bocm_cv <- function(obs, exp) {
  
  #source("/home/Earth/nmishra/2_SForecastAssessment/R/Tests/bocm/bocm_wrapper.R")
  #source("~/Desktop/BSC/Journal/R/Tests/bocm/bocm_wrapper.R")
  
  nyear <- length(obs)
  pred_CV <- rep(NA, nyear)
  
  # for each of the 21 years, extract cross-validated prediction set
  for (year in 1:nyear) {
    pred_CV[year] <- bocm_wrapper(year, obs, exp)[1]
  }
  
  
  return(pred_CV)
}

#bocm_cv(Obs, Exp)