def update_lstm(input, hiddens, cells): change = np.tanh(concat_and_multiply(params['change'], input, hiddens)) forget = sigmoid(concat_and_multiply(params['forget'], input, hiddens)) ingate = sigmoid(concat_and_multiply(params['ingate'], input, hiddens)) outgate = sigmoid(concat_and_multiply(params['outgate'], input, hiddens)) cells = cells * forget + ingate * change hiddens = outgate * np.tanh(cells) return hiddens, cells
def update_gru(input, hiddens): update = sigmoid( concat_and_multiply(params['transion']['update'], input, hiddens)) reset = sigmoid( concat_and_multiply(params['transion']['reset'], input, hiddens)) hiddens = (1 - update) * hiddens + update * sigmoid( concat_and_multiply(params['transion']['hiddenOut'], input, hiddens * reset)) return hiddens
def test_sigmoid(): assert rnn.sigmoid(0) == 0.5 assert rnn.sigmoid(100) == 1.0 assert rnn.sigmoid(-100) < 0.001 assert rnn.sigmoid(-100) >= 0