R version 4.4.0 beta (2024-04-10 r86396 ucrt) -- "Puppy Cup" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(deepNN) > > N <- 1000 > d <- matrix(rnorm(5*N),ncol=5) > > fun <- function(x){ + lp <- 2*x[2] + pr <- exp(lp) / (1 + exp(lp)) + ret <- c(0,0) + ret[1+rbinom(1,1,pr)] <- 1 + return(ret) + } > > d <- lapply(1:N,function(i){return(d[i,])}) > > truth <- lapply(d,fun) > > net <- network( dims = c(5,10,2), + activ=list(ReLU(),softmax())) > > netwts <- train( dat=d, + truth=truth, + net=net, + eps=0.01, + tol=100, # run for 100 iterations + batchsize=10, # note this is not enough + loss=multinomial(), # for convergence + stopping="maxit") [1] 6.933189 0.000000 [1] 6.950091 0.000000 [1] 6.933873 0.000000 [1] 6.984492 0.000000 [1] 6.976321 0.000000 [1] 6.888918 0.000000 [1] 6.995339 0.000000 [1] 7.00649 0.00000 [1] 6.930438 0.000000 [1] 6.922481 0.000000 [1] 6.800637 0.000000 [1] 6.84142 0.00000 [1] 6.713437 0.000000 [1] 7.110403 0.000000 [1] 7.073489 0.000000 [1] 6.74711 0.00000 [1] 6.68745 0.00000 [1] 6.631985 0.000000 [1] 7.176194 0.000000 [1] 6.797863 0.000000 [1] 6.9699723 0.4955718 [1] 7.1380309 0.4935322 [1] 6.9542747 0.4950035 [1] 6.8176846 0.4965759 [1] 6.9573765 0.4981195 [1] 6.6732691 0.5003049 [1] 6.9676917 0.5021173 [1] 6.9626113 0.4994666 [1] 6.959308 0.497169 [1] 7.2526867 0.4953377 [1] 7.1437037 0.4965008 [1] 6.8207583 0.4963722 [1] 6.939622 0.496273 [1] 6.6717971 0.4987209 [1] 6.9547467 0.4988035 [1] 6.5387581 0.4957091 [1] 6.5923843 0.4923142 [1] 6.9887972 0.4912649 [1] 7.4002361 0.4868058 [1] 7.1158639 0.4872817 [1] 6.8193798 0.4876907 [1] 7.2385988 0.4915599 [1] 6.9361789 0.4924323 [1] 7.0281705 0.4918687 [1] 6.9996900 0.4911113 [1] 7.0986332 0.4888449 [1] 6.9264027 0.4867518 [1] 6.965489 0.485120 [1] 6.8935829 0.4872431 [1] 7.0342436 0.4884427 [1] 6.9116607 0.4900835 [1] 7.0205733 0.4885343 [1] 6.926643 0.489608 [1] 6.8403491 0.4889002 [1] 6.8409103 0.4889269 [1] 6.8384497 0.4894158 [1] 7.175683 0.489580 [1] 7.0671985 0.4926905 [1] 7.0138696 0.4957161 [1] 6.9867887 0.4986344 [1] 6.945640 0.500668 [1] 6.9428492 0.5018749 [1] 6.9230618 0.5002584 [1] 6.9252184 0.5012439 [1] 6.9364720 0.5003335 [1] 6.9183771 0.4994338 [1] 6.9138117 0.5000993 [1] 6.9191407 0.5002349 [1] 6.9396867 0.5001856 [1] 6.9097019 0.4998821 [1] 6.8976883 0.5007975 [1] 6.898398 0.500845 [1] 6.8886410 0.5008191 [1] 6.9011233 0.4997902 [1] 6.8961749 0.5000684 [1] 6.8621097 0.4985641 [1] 7.0825069 0.5003416 [1] 6.9066894 0.5018991 [1] 6.9154334 0.5011912 [1] 7.0773187 0.5016796 [1] 6.8955970 0.5012926 [1] 6.8500984 0.5008123 [1] 6.7915808 0.5004836 [1] 6.9950463 0.4994323 [1] 6.7824946 0.5003918 [1] 6.8924339 0.5014063 [1] 6.5772161 0.5027217 [1] 6.8720804 0.5008134 [1] 7.0365131 0.4992847 [1] 6.7594735 0.5004454 [1] 7.175000 0.498809 [1] 6.6396905 0.4980598 [1] 6.5886326 0.5003198 [1] 7.1326897 0.5029167 [1] 6.687077 0.505217 [1] 6.5698490 0.5068865 [1] 6.7265203 0.5101548 [1] 6.9405391 0.5074227 [1] 6.2294394 0.5045163 > > pred <- NNpredict( net=net, + param=netwts$opt, + newdata=d, + newtruth=truth, + record=TRUE, + plot=TRUE) 1000 > > proc.time() user system elapsed 1.93 0.31 2.20