我执行的Sigmoid工作正常,但sigmoidDerivative给出的结果与nd4j中的Sigmoid相同。 Transforms.sigmoidDerivative(x)
和Transforms.sigmoidDerivative(x, true)
有什么区别?
INDArray x = Nd4j.create(new double[] { 0.1812, 0.1235, 0.8466 });
System.out.println(x);
System.out.println(Transforms.sigmoid(x));
System.out.println(Transforms.sigmoidDerivative(x));
System.out.println(Transforms.sigmoidDerivative(x, true));
给出输出:
[[ 0.1812, 0.1235, 0.8466]]
[[ 0.5452, 0.5308, 0.6999]]
[[ 0.5452, 0.5308, 0.6999]]
[[ 0.2480, 0.2490, 0.2101]]
与python的numpy比较:
>>> def sigmoid(x):
... return 1.0 / (1 + np.exp(-x))
...
>>> def sigmoid_derivative(x):
... a = sigmoid(x)
... return a * (1.0 - a)
>>> x = np.array([ 0.1812, 0.1235, 0.8466])
>>> sigmoid(x)
array([0.54517646, 0.53083582, 0.69985343])
>>> sigmoid_derivative(x)
array([0.24795909, 0.24904915, 0.21005861])
Nd4j pom:
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>1.0.0-beta3</version>
</dependency>
最佳答案
没错,Transforms.sigmoidDerivative(x)
和Transforms.sigmoidDerivative(x, true)
应该给出相同的结果,这是dl4j中的错误。正确的行为具有后一种方法。我已经提交了pull request来解决它。