R中神经网络包中的Sigmoid函数

Joh*_*han 1 r neural-network sigmoid

我似乎无法找到任何关于如何在Neuralnet包中应用sigmoid函数的文档,我试过:

neuralnet(...,act.fct="sigmoid")
Run Code Online (Sandbox Code Playgroud)

然而这又回来了;

Error: ''act.fct' is not known
Run Code Online (Sandbox Code Playgroud)

cde*_*man 5

您正在寻找该软件包的"后勤".

neuralnet(..., act.fct = "logistic")
Run Code Online (Sandbox Code Playgroud)

虽然如此,如果你有一个不在那里的功能(并且该包中没有很多)你可以自己传递这个功能.

library(neuralnet)

data(infert)

set.seed(123)
net.infert <- neuralnet(case~parity+induced+spontaneous, infert, 
                        err.fct="ce", linear.output=FALSE, likelihood=TRUE)

sigmoid = function(x) {
  1 / (1 + exp(-x))
}

set.seed(123)
net.infert2 <- neuralnet(case~parity+induced+spontaneous, infert, 
                        err.fct="ce", linear.output=FALSE, likelihood=TRUE,
                        act.fct = sigmoid)

all.equal(net.infert$weights, net.infert2$weights)
[1] TRUE
Run Code Online (Sandbox Code Playgroud)