简体   繁体   English

sigmoid 函数中的操作数无效

[英]Invalid operands in sigmoid function

I am working on a Neural Network, and when trying to do the sigmoid function, it shows an error which I do not understand: invalid operands to binary ^ (have 'double' and 'int').我正在研究神经网络,并且在尝试执行 sigmoid 函数时,它显示了一个我不明白的错误:二进制 ^ 的无效操作数(具有“double”和“int”)。 Here's my piece of code:这是我的一段代码:

double neuron(const int num_in, const double input[num_in], const double weight[num_in], const double bias) {
    int i;
    int asubj = 0;
    int zsubj;
    for (i = 0; i < num_in; i++)
    {
        asubj = asubj + input[i]*weight[i]+bias;
    }
    zsubj = (1)/(1 - (int)(M_E)^(-asubj)); // When I run the program, it stops here, I don

    return 0;
}

Any help would be much appreciated.任何帮助将非常感激。

As noted elsewhere ^ is exclusive-or operator in C. The following might do what you want a little better:正如其他地方所指出的^是 C 中的异或运算符。以下可能会更好地执行您想要的操作:

double neuron(const int num_in,
              const double input[num_in],
              const double weight[num_in],
              const double bias)
  {
  int i;
  double asubj = 0.0;
  double zsubj;

  for (i = 0; i < num_in; i++)
    asubj = asubj + input[i]*weight[i]+bias;

  zsubj = 1.0 / (1.0 - pow(M_E, -asubj));

  return 0;
  }

Note that the code above retains the return 0;注意上面的代码保留了return 0; at the end shown in the original function.在原始函数中显示的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM