示例#1
0
 def sigmoid(self, x):
     try:
         #r = 1 /(1+np.exp(-x))
         r = 1 /(1+tools.safe_exp(-x))
         return r
     except Exception as e:
         print e
         print "exception when calculating sigmoid"
示例#2
0
 def sigmoid(self, x):
     try:
         #r = 1 /(1+np.exp(-x))
         r = 1 / (1 + tools.safe_exp(-x))
         return r
     except Exception as e:
         print e
         print "exception when calculating sigmoid"
示例#3
0
 def softmax(self, x):
     # rows of x are expected to be vectors where softmax is to be applied
     r = np.copy(x)
     for index, col in enumerate(x):
         #m = np.max(col)
         #r[index] = np.exp(col - m)
         #r[index] = tools.safe_exp(col - m)
         r[index] = tools.safe_exp(col)
         r[index] = r[index] / np.sum(r[index])
     return r
示例#4
0
 def softmax(self, x):
     # rows of x are expected to be vectors where softmax is to be applied
     r = np.copy(x)
     for index, col in enumerate(x):
         #m = np.max(col)
         #r[index] = np.exp(col - m)
         #r[index] = tools.safe_exp(col - m)
         r[index] = tools.safe_exp(col)
         r[index] = r[index] / np.sum(r[index])
     return r