如何在 VB 上为 segmoid 函数创建模块?

how to create a module for segmoid function on VB?

我试过了

 Module module1
    <System.Runtime.CompilerServices.Extension()> _
Public Function sigmoid(ByRef x As Integer, ByVal y As Integer) As Integer
        y = 1 / (1 + Math.Exp(-x))
        Return y
        Return Nothing
    End Function
End Module

当我想调用它时,我使用

 y3 = (x1 * w13 + x2 * w23 - seta3).sigmoid

我只想将 x 设为 (x1 * w13 + x2 * w23 - seta3) 并得到它的y值 它与神经网络有关 但我总是出错.. 怎么了??

我看到我要为 Sigmoid 函数更改的几项内容:

Public Module module1
    <System.Runtime.CompilerServices.Extension()> _
    Public Function Sigmoid(ByRef x As Integer) As Double
        Return 1 / (1 + Math.Exp(-x))
    End Function

    <System.Runtime.CompilerServices.Extension()> _
    Public Function Sigmoid(ByRef x As Double) As Double
        Return 1 / (1 + Math.Exp(-x))
    End Function
End Module
  1. 当模块为 Public 时,扩展方法往往会更好地工作。否则,您可能在需要时看不到可用的方法。
  2. Return Nothing 没有意义,因为它直接跟在另一个 return 语句之后。
  3. 函数的 y 输入从未使用过,所以不要要求它。
  4. 您需要 Double,而不是 return 类型的 Integer。第一项带有 1 的除法表达式不太可能产生可行的整数。
  5. 这意味着您还想对 y3 变量使用 Double,这反过来让我们想知道这里还有多少其他值应该真正是双精度值,因此重载方法。

现在你可以这样称呼它了:

y3 = (x1 * w13 + x2 * w23 - seta3).Sigmoid()

请注意,在 VB.Net 中,最佳做法是在调用函数时始终使用 () 表示法。这不是必需的,但仍然是一个好习惯。这是对旧 VB6/VBA/VBScript 代码的更改,在旧代码中使用括号在某些情况下会产生不良副作用。