3
votes

I just started to study the "deepnet" package: http://cran.r-project.org/web/packages/deepnet/index.html

It is about "deep leaning", so about the usage of multi-layer neural networks. I've started to use the train() functions available in the package, but I really cannot understand how to add more hidden layers in the neural networks. The standard setting includes 2 hidden layers, but I would like to add more, like 5. Does some of you have an idea?

I am using the sae.dnn.train() function but I cannot understand which parameter controls the number of hidden layers. Here's the example code:

Var1 <- c(rnorm(50, 1, 0.5), rnorm(50, -0.6, 0.2))
Var2 <- c(rnorm(50, -0.8, 0.2), rnorm(50, 2, 1))
x <- matrix(c(Var1, Var2), nrow = 100, ncol = 2)
y <- c(rep(1, 50), rep(0, 50))
dnn <- sae.dnn.train(x, y, hidden = c(5, 5))
## predict by dnn
test_Var1 <- c(rnorm(50, 1, 0.5), rnorm(50, -0.6, 0.2))
test_Var2 <- c(rnorm(50, -0.8, 0.2), rnorm(50, 2, 1))
test_x <- matrix(c(test_Var1, test_Var2), nrow = 100, ncol = 2)
nn.test(dnn, test_x, y)

Which parameter sets the number of hidden layers in the neural network? How to add more hidden layers?

1
btw, h2o is really fast w/ high usability and you can try it.Patric

1 Answers

8
votes

Although I am unfamiliar with the deepnet package, it appears it is structured the same as other neural net packages. After looking at the documentation (?sae.dnn.train) you will see:

hidden:    vector for number of units of hidden layers.Default is c(10).

Now this isn't the clearest description but I believe it supposed to be the same as the neuralnet function in the neuralnet package. ?neural::neuralnet

hidden:    a vector of integers specifying the number of hidden neurons 
           (vertices) in each layer.

This is much more clear where you can understand that you are creating a vector specifying the number of neurons (nodes, vertices, etc.) in each layer.

So, to sum up, your example with hidden = c(5, 5) is for two layers with 5 neurons in each layer. So if you wanted 5 hidden layers with 5 neurons in each you would simply put hidden = c(5, 5, 5, 5, 5).