[英]Defining acivation function, Should I write lambda x: numpy.tanh(x) OR only numpy.tanh?
在定義激活 function (tanh) 時,是否需要編寫 lambda x: numpy.tanh(x)? 或者我應該只寫激活 function = numpy.tanh?
這是我的代碼 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
不同之處在於
g = lambda x: f(x)
對比
g = f
創建一個額外的匿名 function,它通過調用 f. 因此,這引入了額外的計算成本,絕對沒有任何好處。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.