How to use custom activation function in neuralnet in R

你说的曾经没有我的故事 提交于 2020-06-27 05:00:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!