R/bm_comp.R

Defines functions bm_comp

Documented in bm_comp

#
#
# Copyright (c) 2017-2023 King Abdullah University of Science and Technology
# All rights reserved.
#
# ExaGeoStat-R is a software package provided by KAUST
#
#
#
# @file bm_comp.R
# ExaGeoStat R wrapper functions
#
# @version 1.2.0

#
# @author Faten Alamri
# @author Sameh Abdulah
# @date 2021-12-27

###############################################
#' Running KAUST 2021 competition using the Benchmark function 
#' Benchmark function to run a given FUN on KAUST 2021 competition datasets generated by ExaGeoStatR
#' @param FUN: A predefined function to perform both modeling and prediction operations
#' @param Data_train_list: A list of trainig data 
#' @param Data_predict_list: A list of predict data 
#' @return a list of prediction errors (MS, RMSE, MAE, MSLE) and the estimate of the parameters (sigma, beta, nu, nuggets)

bm_comp<- function(FUN, Data_train_list, Data_predict_list)
{
    # Container to store the output vector for each seed.
    theta_out <- list()

    tryCatch({
        start.time <- Sys.time()
        # Modeling_predicting
        result<-FUN(Data_train_list, Data_predict_list)
        theta_out=result$theta
        z_out<- result$z_out
                end.time <- Sys.time()
        Time=end.time - start.time
        sigma = theta_out[1]
        beta = theta_out[2]
        nu = theta_out[3]
        nuggets = theta_out[4]

        MSE <-mean( Data_test$z- z_out)^2
        RMSE <- sqrt( mean(Data_test$z- z_out)^2)
        MAE <-mean(abs(Data_test$z- z_out))
        MSLE <- mean(log(abs( z_out+ 1))-log(abs(Data_test$z   +1)))^2
        Time <-mean(Time)

        error=function(cond){
            message(paste("Error occure here"))
            message("Here's the original error message:")
            message(cond)
        }

    })

    print("Done\n")
    return(list(MSE, RMSE, MAE, MSLE, sigma, beta, nu, nuggets))
}
ecrc/exageostatR documentation built on June 9, 2025, 9:06 p.m.