如何在 R 中的神经网络中使用自定义激活函数 [英] How to use custom activation function in neuralnet in R

查看:80
本文介绍了如何在 R 中的神经网络中使用自定义激活函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 的新手,我正在尝试为回归任务构建一个神经网络.

I am new to R and I am trying to build a neural network for a regression task.

我正在使用 neuralnet 库来构建我的神经网络,我注意到它接受多个参数.act.fct 就是其中之一.

I am using neuralnet library to construct my neuralnet and I notice it accepts several arguments. act.fct being one of it.

act.fct

一个可微函数,用于平滑协变量或神经元与权重的叉积结果.此外,字符串 'logistic' 和 'tanh' 可能用于逻辑函数和切线双曲线.

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.

默认提供逻辑激活函数,但我想使用自定义的 softplus 函数.

By default a logistic activation function is supplied but I would like to use a custom softplus function.

我的代码可以正常运行,但我怎么知道是否使用了 softplus 而不是默认激活函数?

My code is able to run just fine but how do I know if softplus is used instead of the default activation function?

下面是我的 R 代码片段.

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)

推荐答案

只要检查对象net:

net$act.fct(x)

应该并且将返回与 softplus(x) 相同的值.

should and will return the same as softplus(x).

这篇关于如何在 R 中的神经网络中使用自定义激活函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆