这个函数在做什么(softmax)

What is this function doing (softmax)

这个函数中的"ih"和"ho"是什么。是softmax激活函数我看不懂字符串检查原因

public double sim(double x, string layer)
    {
      // Determine max
      double max = double.MinValue;
      if (layer == "ih")
        max = (ihSum0 > ihSum1) ? ihSum0 : ihSum1;
      else if (layer == "ho")
        max = (hoSum0 > hoSum1) ? hoSum0 : hoSum1;

      // Compute scale
      double scale = 0.0;
      if (layer == "ih")
        scale = Math.Exp(ihSum0 - max) + Math.Exp(ihSum1 - max);
      else if (layer == "ho")
        scale = Math.Exp(hoSum0 - max ) + Math.Exp(hoSum1 - max);

      return Math.Exp(x - max) / scale;
    }

函数不是太难理解。您可能想花点时间看看函数如何实现神经网络激活函数的行为。

在神经网络中,典型的激活函数是接收输入集并根据(输入中的)最大值决定哪个触发函数。

你的情况也一样。

似乎有两组输入(每个"set"称为"layer",因此有两层)代号"ih"和 "ho"。每个集合还有两个元素,称为 Sum0Sum1,因此组合了四个输入: 1. ihSum0ihSum1(对于 ih 层) 2. hoSum0hoSum1(对于 ho 层)

无论 ihholayer 在您的上下文中是什么意思,您都会更好地理解。但是该函数只是检查要使用哪个输入集(或 "layer")(即 "ih" 或 "ho")以确定两个变量(maxscale).

if (layer == "ih")
    max = (ihSum0 > ihSum1) ? ihSum0 : ihSum1;
else if (layer == "ho")
    max = (hoSum0 > hoSum1) ? hoSum0 : hoSum1;

最终(与 x 一起)将用于确定函数的最终输出。

return Math.Exp(x - max) / scale;