2
votes

In R programming,I am trying to understand how to use nnet to have user specified initial weights instead of defaults for running a neural network algorithm? The R documentation mentions below arguments. Any example of how to use weights?

nnet(formula, data, weights, ...,
subset, na.action, contrasts = NULL)
2
I have often wondered the same thing. Since this is a question about the nature of neural networks (and less about programming), there might be more answers on stack exchange. I know that weights= specifies the number of weights, and that you can see the actual weights by doing NNET <- nnet(....) ; NNET$wts, but I'm not sure how it relates to the building of the model. - SeƱor O

2 Answers

1
votes

Look at the documentation http://cran.r-project.org/web/packages/nnet/nnet.pdf

Default S3 method:

nnet(x, y, weights, size, Wts, mask,
linout = FALSE, entropy = FALSE, softmax = FALSE,
censored = FALSE, skip = FALSE, rang = .7, decay = ,
maxit = 1 , Hess = FALSE, trace = TRUE, MaxNWts = 1 ,
abstol = 1. e-4, reltol = 1. e-8, ...)

Wts: Initial parameter vector. If missing chosen at random.

So you have to define yourself Wts based on your network topology and it should work

1
votes

The custom weights shall have the following form:

weights <- c(

 BH1, I1H1, I2H1, .., InH1,
 BH2, I1H2, I2H2, .., InH2,
 ...
 BHn, I1Hn, I2Hn, .., InHn,
 BO,
 I1Out, .., InOut)

i.e.

c(
 weights from bias & inputs to 1st hidden unit,
 from bias & inputs to second hidden unit H2,
 from bias & inputs to last hidden unit Hn,
 biast of output unit,
 skip layer weights ( if any)
 )

Regards

P.S. Remember to keep standard deviation of all weights connected to a unit below 1.0. Otherwise you will get units saturated pretty fast.