问题
I am new to R and I am trying to build a neural network for a regression task.
I am using neuralnet library to construct my neuralnet and I notice it accepts several arguments. act.fct being one of it.
act.fct
a differentiable function that is used for smoothing the result of the cross product of the covariate or neurons and the weights. Additionally the strings, 'logistic' and 'tanh' are possible for the logistic function and tangent hyperbolicus.
By default a logistic activation function is supplied but I would like to use a custom softplus function.
My code is able to run just fine but how do I know if softplus is used instead of the default activation function?
Below is my R code snippet.
softplus <- function(x) log(1+exp(x))
net <- neuralnet(formula = f,
data = as.matrix(train),
act.fct = softplus,
stepmax = 1e7,
hidden = c(10, 8, 6),
linear.output = T)
回答1:
Just check the object net:
net$act.fct(x)
should and will return the same as softplus(x).
来源:https://stackoverflow.com/questions/47818075/how-to-use-custom-activation-function-in-neuralnet-in-r