'Can you retrieve the random initial connection weights in neuralnet (R)?

My code will create a neural network using RPROP and randomly generated weights, and I want to know which weights were randomly generated. I am aware that you can plug in starting weights using the startweights argument in neuralnet, and I am also aware that you can retrieve a list of connection weights that are used in the converged neural network using NeuralNetTools:neuralweights. However, I want to use the neuralnet command, set startweights = NULL, and create a vector of the starting weights that were randomly generated in R. Is this possible? I give some code below in case you need to play around with it a bit.

If you are curious about my rationale, check out pg. 143 of this paper, and the following explanation:

https://depts.washington.edu/oldenlab/wordpress/wp-content/uploads/2013/03/EcologicalModelling_2002.pdf

Basically, I want to run the neural network a certain amount of times, record the best-performing set of starting weights (in terms of MSE), and then run a neural network with those starting weights 1000 times to "prune" the network of weights which have variances not significantly different from random, and then determine variable importance using NeuralNetTools::olden, taking an average of all of the trials.

library(neuralnet)
library(NeuralNetTools)

sctg_1 <- c(1493906.5, 222814.9, 2019421.3, 761410.3, 547919.1, 0, 13971201, 2413181, 50061.9, 3735876.2,      
            8741.4, 123914.7, 132759.9, 2742649.7, 4842.245, 5112489.5, 
            93346.04, 13110.432, 120822.6, 222947.3)

sctg_2 <- c(13034.8, 362991.4688, 0, 2559556.7, 1215809.62, 0, 0, 17308.4,
            53385.5, 125.8, 319.08, 0, 0, 98113.4, 0, 348682,
            679107.7, 0, 0, 0)

sctg_3 <- c(0, 834788.5, 0, 0, 1198, 0, 0, 3864978.8, 2292815, 19045.8,
            1539491.9, 0, 0, 3030195.8, 3180861.2, 114802.9, 5114067.5,
            0, 1135.6, 0)

sctg_4 <- c(13878012, 319332, 503917, 0, 39, 1861756, 2112385,  
            2968683, 8250070, 2964929, 2174953, 1218664, 0, 13522784,
            7391358, 9564713, 825841, 3948627, 7043228, 0)

sctg_5 <- c(23008, 198340, 911600, 17691, 216618, 1688342,
            9555588, 415008, 2633059, 780138, 317738, 1248618,
            1197830, 0, 0, 467849, 1506839, 0,1561499, 1272532)

sctg_6 <- c(0, 49421, 0, 0, 133588, 0, 0, 2496, 0, 0, 41474, 0, 0, 0,
            0, 0, 0, 0, 0, 0)

sctg_7 <- c(5010, 241192, 237927, 0, 895213, 370, 458, 2484810, 542846,   
            22578, 1692851, 6212, 0, 0, 3712074, 872365, 1186191, 1, 0, 7119802)

foodinsecurity <- c(0.157, 0.134, 0.207, 0.163, 0.145, 0.157, 0.165, 0.172,
                    0.154, 0.161, 0.172, 0.189, 0.186, 0.165, 0.182, 0.157,
                    0.165, 0.160, 0.150, 0.181)

sctg_data <- data.frame(sctg_1, sctg_2, sctg_3, sctg_4, sctg_5, sctg_6, sctg_7, foodinsecurity)


index <- sample(1:nrow(sctg_data),round(0.75*nrow(sctg_data)))
train <- sctg_data[index,]
test <- sctg_data[-index,]
maxs <- apply(sctg_data, 2, max) 
mins <- apply(sctg_data, 2, min)
scaled <- as.data.frame(scale(sctg_data, center = mins, scale = maxs - mins))
train_ <- scaled[index,]
test_ <- scaled[-index,]
n <- names(train_)
f1 <- as.formula(paste("foodinsecurity ~", paste(n[!n %in% "foodinsecurity"], collapse = " + ")))
nn1 <- neuralnet(f1,data=train_, stepmax = 1e07,   hidden=c(4),linear.output=T)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source