Setup
 Packages and options
library(NNbenchmark)
library(kableExtra)
options(scipen = 999)
 
 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
 
 ANN2 trainPredict arguments - inputs x, y
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(ANN2)
ANN2.method <- c("sgd", "adam", "rmsprop")
hyperParams.ANN2 <- function(optim_method, ...) {
    
    if (optim_method == "sgd")     { iter <- maxit1storderA; lr <- 0.01} 
    if (optim_method == "adam")    { iter <- maxit1storderA; lr <- 0.01} 
    if (optim_method == "rmsprop") { iter <- maxit1storderA; lr <- 0.01} 
    
    out <- list(iter = iter, lr = lr)
    return(out)
}
NNtrain.ANN2 <- 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
    
    NNreg <- ANN2::neuralnetwork(X = x, y = y, 
                           val.prop = 0, 
                           standardize = FALSE, 
                           hidden.layers = hidden_neur, 
                           regression = TRUE,
                           loss.type = "squared",
                           n.epochs = iter,
                           optim.type = optim_method,
                           learn.rates = lr,
                           verbose = FALSE,
                           random.seed = as.integer(runif(1)*10000000))
    
   return (NNreg)
}
NNpredict.ANN2 <- function(object, x, ...)
    as.numeric(predict(object, x)$predictions)    
NNclose.ANN2 <- function()
  if("package:ANN2" %in% search())
    detach("package:ANN2", unload=TRUE)
ANN2.prepareZZ <- list(xdmv = "m", ydmv = "m", zdm = "d", scale = TRUE)
if(FALSE)
res <- train_and_predict_1data(1, ANN2.method, "NNtrain.ANN2", "hyperParams.ANN2", "NNpredict.ANN2", 
                               NNsummary, "NNclose.ANN2", NA, ANN2.prepareZZ, nrep=2, echo=TRUE, doplot=FALSE,
                               pkgname="ANN2", pkgfun="neuralnetwork", rdafile=TRUE, odir=odir)
 
 
 Launch package’s trainPredict
res <- trainPredict_1pkg(1:12, pkgname = "ANN2", pkgfun = "neuralnetwork", ANN2.method,
  prepareZZ.arg = ANN2.prepareZZ, nrep = nrep, doplot = FALSE,
  csvfile = TRUE, rdafile = TRUE, odir = odir, echo = FALSE)
 
 Results
#print(res)
kable(apply(res[,,1,], c(3,1), min), caption = "sgd")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
sgd
|  | RMSE | MSE | MAE | WAE | time | 
| mDette | 1.0794 | 1.1651 | 0.7815 | 6.2998 | 0.17 | 
| mFriedman | 0.0179 | 0.0003 | 0.0141 | 0.0449 | 0.18 | 
| mIshigami | 0.7507 | 0.5635 | 0.5727 | 2.8148 | 1.02 | 
| mRef153 | 3.3665 | 11.3335 | 2.4208 | 12.7772 | 0.01 | 
| uDmod1 | 0.2832 | 0.0802 | 0.2370 | 0.6137 | 0.00 | 
| uDmod2 | 0.2717 | 0.0738 | 0.2371 | 0.4805 | 0.00 | 
| uDreyfus1 | 0.3401 | 0.1156 | 0.2655 | 0.7467 | 0.00 | 
| uDreyfus2 | 0.3641 | 0.1326 | 0.2780 | 0.9345 | 0.00 | 
| uGauss1 | 5.6746 | 32.2006 | 4.4060 | 17.6233 | 0.07 | 
| uGauss2 | 7.3355 | 53.8096 | 5.6616 | 20.2730 | 0.06 | 
| uGauss3 | 4.9299 | 24.3043 | 3.8940 | 13.5305 | 0.06 | 
| uNeuroOne | 0.3057 | 0.0934 | 0.2504 | 0.6017 | 0.00 | 
kable(apply(res[,,2,], c(3,1), min), caption = "adam")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
adam
|  | RMSE | MSE | MAE | WAE | time | 
| mDette | 0.4764 | 0.2270 | 0.3445 | 1.9013 | 0.20 | 
| mFriedman | 0.0165 | 0.0003 | 0.0130 | 0.0503 | 0.22 | 
| mIshigami | 0.7178 | 0.5153 | 0.5509 | 2.7656 | 1.03 | 
| mRef153 | 3.1487 | 9.9142 | 2.2287 | 12.7430 | 0.03 | 
| uDmod1 | 0.2203 | 0.0485 | 0.1741 | 0.5159 | 0.00 | 
| uDmod2 | 0.1648 | 0.0271 | 0.1285 | 0.3765 | 0.00 | 
| uDreyfus1 | 0.2766 | 0.0765 | 0.2268 | 0.6076 | 0.00 | 
| uDreyfus2 | 0.2886 | 0.0833 | 0.2216 | 0.7302 | 0.00 | 
| uGauss1 | 3.7599 | 14.1372 | 3.0289 | 10.3446 | 0.06 | 
| uGauss2 | 2.7069 | 7.3272 | 2.1519 | 8.2788 | 0.06 | 
| uGauss3 | 2.7411 | 7.5134 | 2.2167 | 7.7006 | 0.06 | 
| uNeuroOne | 0.2948 | 0.0869 | 0.2442 | 0.6013 | 0.01 | 
kable(apply(res[,,3,], c(3,1), min), caption = "rmsprop")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
rmsprop
|  | RMSE | MSE | MAE | WAE | time | 
| mDette | 0.4975 | 0.2475 | 0.3631 | 2.4228 | 0.17 | 
| mFriedman | 0.0258 | 0.0007 | 0.0209 | 0.0735 | 0.18 | 
| mIshigami | 0.7597 | 0.5772 | 0.5672 | 3.4488 | 1.03 | 
| mRef153 | 3.1876 | 10.1606 | 2.2463 | 11.9919 | 0.03 | 
| uDmod1 | 0.2253 | 0.0508 | 0.1766 | 0.5399 | 0.00 | 
| uDmod2 | 0.1694 | 0.0287 | 0.1335 | 0.3788 | 0.01 | 
| uDreyfus1 | 0.2231 | 0.0498 | 0.1478 | 0.6429 | 0.00 | 
| uDreyfus2 | 0.2745 | 0.0754 | 0.1980 | 0.6799 | 0.00 | 
| uGauss1 | 5.1283 | 26.2993 | 3.8756 | 15.0177 | 0.07 | 
| uGauss2 | 2.9072 | 8.4518 | 2.2943 | 9.2093 | 0.07 | 
| uGauss3 | 2.5864 | 6.6894 | 2.0802 | 7.6802 | 0.07 | 
| uNeuroOne | 0.2853 | 0.0814 | 0.2312 | 0.5946 | 0.00 |