1 Setup

1.1 Packages and options

library(NNbenchmark)
library(kableExtra)
options(scipen = 999)

1.2 Datasets to test

NNdataSummary(NNdatasets)
##      Dataset n_rows n_inputs n_neurons n_parameters
## 1     mDette    500        3         5           26
## 2  mFriedman    500        5         5           36
## 3  mIshigami    500        3        10           51
## 4    mRef153    153        5         3           22
## 5     uDmod1     51        1         6           19
## 6     uDmod2     51        1         5           16
## 7  uDreyfus1     51        1         3           10
## 8  uDreyfus2     51        1         3           10
## 9    uGauss1    250        1         5           16
## 10   uGauss2    250        1         4           13
## 11   uGauss3    250        1         4           13
## 12 uNeuroOne     51        1         2            7

1.3 AMORE trainPredict arguments - inputs

if(dir.exists("D:/GSoC2020/Results/2020run03/"))
{  
  odir <- "D:/GSoC2020/Results/2020run03/"
}else if(dir.exists("~/Documents/recherche-enseignement/code/R/NNbenchmark-project/NNtempresult/"))
{  
  odir <- "~/Documents/recherche-enseignement/code/R/NNbenchmark-project/NNtempresult/"
}else
  odir <- "~"

nrep <- 10
maxit2ndorder  <-    200
maxit1storderA <-   1000
maxit1storderB <-  10000
maxit1storderC <- 100000

#library(AMORE)
hyperParams.AMORE <- function(optim_method, ...) {
    
    if (!is.element(optim_method, c("ADAPTgd", "ADAPTgdwm", "BATCHgd", "BATCHgdwm"))) stop("Invalid Parameters.")
    if (optim_method == "ADAPTgd") {iter <- maxit1storderA; lr <- 0.01; momentum <- 0; hidden_activation <- "tansig"} 
    if (optim_method == "ADAPTgdwm") {iter <- maxit1storderA; lr <- 0.01; momentum <- 0.8; hidden_activation <- "sigmoid"} 
    if (optim_method == "BATCHgd") {iter <- maxit1storderB; lr <- 0.1; momentum <- 0; hidden_activation <- "tansig"}
    if (optim_method == "BATCHgdwm") {iter <- maxit1storderB; lr <- 0.1; momentum <- 0.8; hidden_activation <- "tansig"}

    out <- list(iter = iter, lr = lr, momentum = momentum, hidden_activation = hidden_activation)
    
    return (out)
}

NNtrain.AMORE <- function(x, y, dataxy, formula, hidden_neur, optim_method, hyperParams, ...) {
    
    hyper_params <- do.call(hyperParams, list(optim_method, ...))
    
    iter <- hyper_params$iter
    lr <- hyper_params$lr
    momentum <- hyper_params$momentum
    hidden_activation <- hyper_params$hidden_activation
    
    net_structure <- AMORE::newff(n.neurons = c(ncol(x), hidden_neur, 1), 
                                  learning.rate.global = lr, 
                                  error.criterium = "LMS", 
                                  hidden.layer = hidden_activation, 
                                  method = optim_method, 
                                  momentum.global = momentum)
    
    NNreg <- AMORE::train(net = net_structure, 
                          P = x, 
                          T = y, 
                          error.criterium = "LMS", 
                          report = FALSE, 
                          n.shows = iter, 
                          show.step = 1)
    return (NNreg)
}
NNpredict.AMORE <- function(object, x, ...)
    AMORE::sim.MLPnet(object$net, x)    
NNclose.AMORE <- function()
  if("package:AMORE" %in% search())
    detach("package:AMORE", unload=TRUE)
AMORE.method <- c("ADAPTgd", "ADAPTgdwm", "BATCHgd", "BATCHgdwm")
AMORE.prepareZZ <- list(xdmv = "d", ydmv = "v", zdm = "d", scale = TRUE)

if(FALSE)
res <- train_and_predict_1data(1, AMORE.method, "NNtrain.AMORE", "hyperParams.AMORE", "NNpredict.AMORE", 
                               NNsummary, "NNclose.AMORE", NA, AMORE.prepareZZ, nrep=2, echo=TRUE, 
                               doplot=FALSE, echoreport=0,
                               pkgname="AMORE", pkgfun="train", rdafile=TRUE, odir=odir)

2 Launch package’s trainPredict

res <- trainPredict_1pkg(1:12, pkgname = "AMORE", pkgfun = "train", AMORE.method,
  prepareZZ.arg = AMORE.prepareZZ, nrep = nrep, doplot = FALSE,
  csvfile = TRUE, rdafile = TRUE, odir = odir, echo = FALSE)

3 Results

#print(res)
kable(apply(res[,,1,], c(3,1), min), caption = "ADAPTgd")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
ADAPTgd
RMSE MSE MAE WAE time
mDette 1.6532 2.7330 1.2296 7.6420 0.11
mFriedman 0.0268 0.0007 0.0215 0.0784 0.12
mIshigami 0.6630 0.4396 0.4887 2.5491 0.20
mRef153 3.3127 10.9738 2.3505 12.9992 0.02
uDmod1 0.2028 0.0411 0.1602 0.4981 0.03
uDmod2 0.2537 0.0644 0.2251 0.4973 0.02
uDreyfus1 0.3449 0.1189 0.2661 0.7619 0.01
uDreyfus2 0.3345 0.1119 0.2600 0.8535 0.01
uGauss1 12.1677 148.0537 9.9965 28.2968 0.04
uGauss2 7.3477 53.9887 5.6976 21.0875 0.04
uGauss3 4.7265 22.3395 3.7936 12.1983 0.04
uNeuroOne 0.2954 0.0873 0.2440 0.6419 0.01
kable(apply(res[,,2,], c(3,1), min), caption = "ADAPTgdwm")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
ADAPTgdwm
RMSE MSE MAE WAE time
mDette 0.3895 0.1517 0.2986 1.6714 0.17
mFriedman 0.0439 0.0019 0.0315 0.1660 0.19
mIshigami 0.8131 0.6612 0.5943 3.1618 0.31
mRef153 3.3399 11.1548 2.3877 12.9869 0.04
uDmod1 0.1813 0.0329 0.1486 0.3999 0.03
uDmod2 0.1179 0.0139 0.0997 0.2625 0.03
uDreyfus1 0.1383 0.0191 0.1166 0.3069 0.02
uDreyfus2 0.1856 0.0344 0.1333 0.5125 0.01
uGauss1 3.4947 12.2133 2.5236 15.3243 0.08
uGauss2 4.8675 23.6928 3.8736 15.6405 0.07
uGauss3 4.0064 16.0509 3.1019 11.1709 0.07
uNeuroOne 0.2849 0.0812 0.2282 0.6242 0.01
kable(apply(res[,,3,], c(3,1), min), caption = "BATCHgd")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
BATCHgd
RMSE MSE MAE WAE time
mDette 1.1249 1.2654 0.8003 7.6593 1.83
mFriedman 0.0174 0.0003 0.0136 0.0552 1.80
mIshigami 2.5010 6.2550 2.1099 6.3023 2.58
mRef153 3.3372 11.1368 2.3747 12.8511 1.39
uDmod1 0.2777 0.0771 0.2170 0.6637 1.76
uDmod2 0.1589 0.0253 0.1266 0.3880 1.62
uDreyfus1 0.2360 0.0557 0.1795 0.5969 1.36
uDreyfus2 0.2570 0.0660 0.2028 0.6037 1.37
uGauss1 12.0712 145.7150 10.2094 25.9779 1.68
uGauss2 8.7187 76.0160 6.4030 25.4519 1.54
uGauss3 5.1436 26.4569 4.0217 14.4848 1.53
uNeuroOne 0.2924 0.0855 0.2410 0.6281 1.26
kable(apply(res[,,4,], c(3,1), min), caption = "BATCHgdwm")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
BATCHgdwm
RMSE MSE MAE WAE time
mDette 1.8460 3.4076 1.4793 7.6908 1.82
mFriedman 0.0174 0.0003 0.0136 0.0546 1.85
mIshigami 2.4568 6.0360 2.0688 6.0389 2.62
mRef153 3.3346 11.1198 2.3439 13.2163 1.42
uDmod1 0.1883 0.0354 0.1521 0.4173 1.76
uDmod2 0.2514 0.0632 0.2243 0.4591 1.62
uDreyfus1 0.1547 0.0239 0.1134 0.4293 1.36
uDreyfus2 0.1825 0.0333 0.1350 0.5424 1.36
uGauss1 11.9912 143.7900 10.1183 25.8322 1.68
uGauss2 8.4071 70.6802 6.2189 24.4918 1.55
uGauss3 5.1542 26.5656 4.0282 14.5604 1.56
uNeuroOne 0.2927 0.0857 0.2413 0.6289 1.27