def backward(self) -> ndarray: self.input_grad = self._input_grad() assert_same_shape(self.prediction, self.input_grad) return self.input_grad
def backward(self, output_grad: ndarray) -> ndarray: assert_same_shape(self.output, output_grad) self.input_grad = self._input_grad(output_grad) assert_same_shape(self.input_, self.input_grad) return self.input_grad
def forward(self, prediction: ndarray, target: ndarray) -> float: # batch size x num_classes assert_same_shape(prediction, target) self.prediction = prediction self.target = target self.output = self._output() return self.output
def backward(self, output_grad: ndarray) -> ndarray: assert_same_shape(self.output, output_grad) for operation in self.operations[::-1]: output_grad = operation.backward(output_grad) input_grad = output_grad assert_same_shape(self.input_, input_grad) self._param_grads() return input_grad