gpt4 book ai didi

c# - 如何在C#中实现MATLAB 'tansig'双曲正切sigmoid传递函数

转载 作者:太空宇宙 更新时间:2023-11-03 21:42:52 26 4
gpt4 key购买 nike

我正在尝试按照这篇文章中的描述复制 MATLAB“sim”函数:Export a neural network trained with MATLAB in other programming languages然而,我正在努力寻找一种在 C# 中实现 MATLAB tansig 函数的方法。它被定义为:a = (2 ./(1 + exp(-2*n)) - 1) 我读它的方式是我需要对矩阵执行指数运算。网上的研究表明这是一个重要的数学问题,尤其是当矩阵不对称时。任何帮助表示赞赏。

最佳答案

虽然有些不清楚,但我猜您指的是将压缩函数应用于神经元的输出信号。

您必须将该函数应用于神经元输出向量中的每个元素。

因此,您有效地将函数应用于 float 而不是矩阵本身。

output = [ 1, 0, 1, 0, 1 ] # output vector from a neuron

def sqash( n ):
return (2 ./ (1 + exp(-2*n)) - 1)

squashed_output = [ sqash(1), sqash(0), sqash(1), sqash(0), sqash(1) ]

Matlab 可能支持与 Python 中的 NumPy 相同的语法 sqash( output )。因此,在使用向量参数调用函数时,将函数分别应用于每个元素。

output = [ 1, 0, 1, 0, 1 ] # output vector from a neuron

def sqash( vector ):
return (2 ./ (1 + exp(-2 * vector)) - 1)

squashed_output = sqash( output )

关于c# - 如何在C#中实现MATLAB 'tansig'双曲正切sigmoid传递函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18480547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com