R 中 neuralnet 包中的 Sigmoid 函数

Sigmoid function in the neuralnet package in R

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

neuralnet(...,act.fct="sigmoid")

然而这又回来了;

Error: ''act.fct' is not known

您正在寻找该包裹的 "logistic"。

neuralnet(..., act.fct = "logistic")

尽管如此,如果您有一个函数不在那里(而且那个包中没有很多),您可以自己传递该函数。

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