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"
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"
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