def predict(self, x: np.array) -> np.array:
     W1, W2 = self.params['W1'], self.params['W2']
     b1, b2 = self.params['b1'], self.params['b2']
     a1 = np.dot(x, W1) + b1
     z1 = act.sigmoid(a1)
     a2 = np.dot(z1, W2) + b2
     y = act.softmax(a2)
     return y
def predict(network, x):
    W1, W2, W3 = network['W1'], network['W2'], network['W3']
    b1, b2, b3 = network['b1'], network['b2'], network['b3']
    a1 = np.dot(x, W1) + b1
    z1 = act.sigmoid(a1)
    a2 = np.dot(z1, W2) + b2
    z2 = act.sigmoid(a2)
    a3 = np.dot(z2, W3) + b3
    y = act.softmax(a3)
    return y
    def gradient(self, x, t):
        W1, W2 = self.params['W1'], self.params['W2']
        b1, b2 = self.params['b1'], self.params['b2']
        grads = {}

        batch_num = x.shape[0]

        # forward
        a1 = np.dot(x, W1) + b1
        z1 = act.sigmoid(a1)
        a2 = np.dot(z1, W2) + b2
        y = act.softmax(a2)

        # backward
        dy = (y - t) / batch_num
        grads['W2'] = np.dot(z1.T, dy)
        grads['b2'] = np.sum(dy, axis=0)

        da1 = np.dot(dy, W2.T)
        dz1 = act.sigmoid_grad(a1) * da1
        grads['W1'] = np.dot(x.T, dz1)
        grads['b1'] = np.sum(dz1, axis=0)

        return grads
 def forward(self, x: np.array, t: np.array) -> np.array:
     self.t = t
     self.y = act.softmax(x)
     self.loss = loss.cross_entropy_error(self.y, self.t)
 def loss(self, x: np.array, t: np.array) -> np.array:
     z = self.predict(x)
     y = act.softmax(z)
     return loss.cross_entropy_error(y, t)