def _forward(self, X_timestamp, Y_timestamp, state):
     """
     RNN forward propagation.
     """
     state = tanh(X_timestamp.dot(self.Wax) + state.dot(self.Waa) + self.ba)
     Y_hat_timestamp = sigmoid(state.dot(self.Wy) + self.by)
     loss = self._loss(Y_timestamp, Y_hat_timestamp)
     return loss, Y_hat_timestamp, state
    def _forward(self, X):
        """
        RNN forward propagation.

        Parameters
        ----------
        X: time series input, shape = (N, T, D)
        """
        m, timesteps, _ = X.shape
        self.h0 = np.zeros(shape=(m, self.hidden_units))
        self.states = np.zeros(shape=(m, timesteps, self.hidden_units))
        self.states[:, 0, :] = tanh(np.dot(X[:, 0, :], self.Wax) + np.dot(self.h0, self.Waa) + self.ba)
        for t in range(1, timesteps):
            self.states[:, t, :] = tanh(np.dot(X[:, t, :], self.Wax) + np.dot(self.states[:, t-1, :], self.Waa) + self.ba)
        Y_hat = np.einsum("nth,hc->ntc", self.states, self.Wy)
        Y_hat = softmax(Y_hat + self.by)
        return Y_hat