Re: Help using the exclude option in the neuralnet package

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Help using the exclude option in the neuralnet package

Dan Ryan
Good Morning,

I am using the neuralnet package in R, and am able to produce some basic neural nets, and use the output.

I would like to exclude some of the weights and biases from the iteration process and fix their values.

However I do not seem to be able to correctly define the exclude and constant.weights vectors.

Question:  Can someone point me to an example where exclude and contant.weights are used.  I have search the R help archive, and haven't found any examples which use these on the web.

Thank you in advance for any help.

Sincerely

Dan

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Help using the exclude option in the neuralnet package

Sebastian Mueller
Hi Dan,

the easiest way to declare `exclude` and `constant.weights` is as a
vector of indices. You can determine the index of the neuron as follows:

The layers are arranged in sequence, with the bias neuron being the
first in each layer. So in a neural net with 6 input neurons and a layer
of 3 hidden neurons, the bias neurons would be at indices 1 and 8.

HTH.

Sebastian

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Help using the exclude option in the neuralnet package

Frauke Günther
In reply to this post by Dan Ryan
Dear all,

the exclude and constant.weights options are used as follows:

exclude: A matrix with n rows and 3 columns will exclude n weights. The the first column refers to the layer, the second column to the input neuron and the third column to the output neuron of the weight.

constant.weights: A vector specifying the values of the weights that are excluded from the training process and treated as fix.

Please refer to the following example:

Not using exclude and constant.weights (all weights are trained):

> nn <- neuralnet(Species == "setosa" ~ Petal.Length + Petal.Width, iris, linear.output = FALSE)
>
> nn$weights
[[1]]
[[1]][[1]]
[,1]
[1,] 6.513239
[2,] -0.815920
[3,] -5.859802
[[1]][[2]]
[,1]
[1,] -4.597934
[2,] 9.179436

Using exclude (2 weights are excluded --> NA):

> nn <- neuralnet(Species == "setosa" ~ Petal.Length + Petal.Width, iris, linear.output = FALSE,
exclude = matrix(c(1,2,1, 2,2,1),byrow=T, nrow=2))
> nn$weights
[[1]]
[[1]][[1]]
[,1]
[1,] -0.2815942
[2,] NA
[3,] 0.2481212
[[1]][[2]]
[,1]
[1,] -0.6934932
[2,] NA

Using exclude and constant.weights (2 weights are excluded and treated as fix --> 100 and 1000, respectively):

> nn <- neuralnet(Species == "setosa" ~ Petal.Length + Petal.Width, iris, linear.output = FALSE,
exclude = matrix(c(1,2,1, 2,2,1),byrow=T, nrow=2),
constant.weights=c(100,1000))
> nn$weights
[[1]]
[[1]][[1]]
[,1]
[1,] 0.554119
[2,] 100.000000
[3,] 1.153611
[[1]][[2]]
[,1]
[1,] -0.3962524
[2,] 1000.0000000

I hope you will find this example helpful.

Sincerely,
Frauke


>     William Michels <[hidden email] mailto:[hidden email] > hat am 10.10.2020 18:16 geschrieben:
>      
>      
>     Forwarding: Question re "neuralnet" package on the R-Help mailing list:
>      
>     https://stat.ethz.ch/pipermail/r-help/2020-October/469020.html
>      
>     If you are so inclined, please reply to:
>      
>     [hidden email] mailto:[hidden email] <[hidden email] mailto:[hidden email] >
>      
>     ---------- Forwarded message ---------
>     From: Dan Ryan <[hidden email] mailto:[hidden email] >
>     Date: Fri, Oct 9, 2020 at 3:52 PM
>     Subject: Re: [R] Help using the exclude option in the neuralnet package
>     To: [hidden email] mailto:[hidden email] <[hidden email] mailto:[hidden email] >
>      
>     Good Morning,
>      
>     I am using the neuralnet package in R, and am able to produce some
>     basic neural nets, and use the output.
>      
>     I would like to exclude some of the weights and biases from the
>     iteration process and fix their values.
>      
>     However I do not seem to be able to correctly define the exclude and
>     constant.weights vectors.
>      
>     Question: Can someone point me to an example where exclude and
>     contant.weights are used. I have search the R help archive, and
>     haven't found any examples which use these on the web.
>      
>     Thank you in advance for any help.
>      
>     Sincerely
>      
>     Dan
>      
>     [[alternative HTML version deleted]]
>      
>     ______________________________________________
>     [hidden email] mailto:[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>     and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.