[英]Defining acivation function, Should I write lambda x: numpy.tanh(x) OR only numpy.tanh?
While defining activation function (tanh), do I need to write lambda x: numpy.tanh(x)?在定义激活 function (tanh) 时,是否需要编写 lambda x: numpy.tanh(x)? Or Should I write only activation function = numpy.tanh?
或者我应该只写激活 function = numpy.tanh?
This is my code class neuralNetwork:这是我的代码 class 神经网络:
# initialise the neural network
def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):
# set number of nodes in each input, hidden, output layer
self.inodes = inputnodes
self.hnodes = hiddennodes
self.onodes = outputnodes
# link weight matrices, wih and who
# weights inside the arrays are w_i_j, where link is from node i to node j in the next layer
# w11 w21
# w12 w22 etc
self.wih = numpy.random.normal(0.0, pow(self.inodes, -0.5), (self.hnodes, self.inodes))
self.who = numpy.random.normal(0.0, pow(self.hnodes, -0.5), (self.onodes, self.hnodes))
# learning rate
self.lr = learningrate
# activation function is the sigmoid function
self.activation_function = numpy.tanh
pass
The difference is that不同之处在于
g = lambda x: f(x)
vs对比
g = f
creates an additional, anonymous function, that acts by calling f.创建一个额外的匿名 function,它通过调用 f. Consequently this introduced an extra computational cost for absolutely no benefit.
因此,这引入了额外的计算成本,绝对没有任何好处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.