Get weights for a neural network
Get weights for a neural network in an organized list by extracting values from a neural network object. This function is generally not called by itself.
neuralweights(mod_in, ...) ## S3 method for class 'numeric' neuralweights(mod_in, rel_rsc = NULL, struct, ...) ## S3 method for class 'nnet' neuralweights(mod_in, rel_rsc = NULL, ...) ## S3 method for class 'mlp' neuralweights(mod_in, rel_rsc = NULL, ...) ## S3 method for class 'nn' neuralweights(mod_in, rel_rsc = NULL, ...)
mod_in |
input object for which an organized model list is desired. The input can be an object of class |
... |
arguments passed to other methods |
rel_rsc |
numeric indicating the scaling range for the width of connection weights in a neural interpretation diagram. Default is |
struct |
numeric vector equal in length to the number of layers in the network. Each number indicates the number of nodes in each layer starting with the input and ending with the output. An arbitrary number of hidden layers can be included. |
Each element of the returned list is named using the construct 'layer node', e.g. 'out 1' is the first node of the output layer. Hidden layers are named using three values for instances with more than one hidden layer, e.g., 'hidden 1 1' is the first node in the first hidden layer, 'hidden 1 2' is the second node in the first hidden layer, 'hidden 2 1' is the first node in the second hidden layer, etc. The values in each element of the list represent the weights entering the specific node from the preceding layer in sequential order, starting with the bias layer if applicable. For example, the elements in a list item for 'hidden 1 1' of a neural network with a 3 5 1 structure (3 inputs, 5 hidden nodes, 1 output) would have four values indicating the weights in sequence from the bias layer, first input layer, second input layer, and third input layer going to the first hidden node.
Returns a two-element list with the first element being a vector indicating the number of nodes in each layer of the neural network and the second element being a named list of weight values for the input model.
data(neuraldat) set.seed(123) ## using numeric input wts_in <- c(13.12, 1.49, 0.16, -0.11, -0.19, -0.16, 0.56, -0.52, 0.81) struct <- c(2, 2, 1) #two inputs, two hidden, one output neuralweights(wts_in, struct = struct) ## using nnet library(nnet) mod <- nnet(Y1 ~ X1 + X2 + X3, data = neuraldat, size = 5, linout = TRUE) neuralweights(mod) ## Not run: ## using RSNNS, no bias layers library(RSNNS) x <- neuraldat[, c('X1', 'X2', 'X3')] y <- neuraldat[, 'Y1'] mod <- mlp(x, y, size = 5, linOut = TRUE) neuralweights(mod) # pruned model using code from RSSNS pruning demo pruneFuncParams <- list(max_pr_error_increase = 10.0, pr_accepted_error = 1.0, no_of_pr_retrain_cycles = 1000, min_error_to_stop = 0.01, init_matrix_value = 1e-6, input_pruning = TRUE, hidden_pruning = TRUE) mod <- mlp(x, y, size = 5, pruneFunc = "OptimalBrainSurgeon", pruneFuncParams = pruneFuncParams) neuralweights(mod) ## using neuralnet library(neuralnet) mod <- neuralnet(Y1 ~ X1 + X2 + X3, data = neuraldat, hidden = 5) neuralweights(mod) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.