user1885528
user1885528

Reputation: 53

specifying "initial weights" for nnet in R programming neural network

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)

Upvotes: 2

Views: 3933

Answers (2)

Krzysztof Radka
Krzysztof Radka

Reputation: 21

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.

Upvotes: 2

ThiS
ThiS

Reputation: 977

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

Upvotes: 1

Related Questions