def forward(self): # A stable calculation, xent(sigmoid(x)) = (1 - t) + log(1 + exp(-x)) self._input[1]._result = numeric.sigmoid(self._input[0]._value) labels = self._input[1]._value xent = (1 - labels.astype(DTYPE)) * self._input[0]._value + numeric.log1pexp(-self._input[0]._value) self._value = (np.sum(xent) / DTYPE(xent.size)).reshape(1) self._gradient = np.zeros(self._value.shape, dtype=DTYPE)
def forward(self): self._value = 2 * numeric.sigmoid(2 * self._input[0]._value) - 1 # tanh = 2 sig(2x) - 1 self._gradient = np.zeros(self._value.shape, dtype=DTYPE)
def forward(self): self._value = numeric.sigmoid(self._input[0]._value) self._gradient = np.zeros(self._value.shape, dtype=DTYPE)