Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude bias neurons in neuralnet in R

I want to train a neural network with the neuralnet package in R - but without using bias nodes.

I think I should somehow use the exclude argument for that but I don't know how.

My question
How do I e.g. train a model with 6 input neurons, 3 hidden neurons and 7 output neurons - but without any bias neurons?

like image 486
vonjd Avatar asked Oct 27 '25 04:10

vonjd


2 Answers

The logic is as follows:

It starts with the first bias neuron, then the first input neuron, the second input neuron and so forth.

When you got through all input neurons the next layer comes, starting again with the bias neuron, then the first hidden neuron, the second hidden neuron and so forth.

In the above case this gives: exclude = c(1, 8, 15, 22, 26, 30, 34, 38, 42, 46)

like image 58
vonjd Avatar answered Oct 28 '25 19:10

vonjd


Using exclude works, but it creates problems for predict.

exclude introduces "NA" in weights, which causes predict to return "NA". Manual workaround, set NA weights to zeros: nn$weights = lapply(nn$weights, lapply, function(x) replace(x, is.na(x), 0))

like image 31
IndustryUser1942 Avatar answered Oct 28 '25 17:10

IndustryUser1942



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!