Problems
Loading...
Step 3 of 6
Cell State
Easy

Update the LSTM cell state by combining retained memory with the gated candidate.

Ct=ft⊙Ct−1+it⊙C~t.C_t=f_t\odot C_{t-1}+i_t\odot\widetilde{C}_t.

Here, f_t is the forget gate, i_t is the input gate, C_prev is the previous cell state, c_tilde is the proposed content, and the multiplication is elementwise. Return C_t as a float64 NumPy array with the same shape.

Loading visualization...

Examples

Input: C_prev = [1,-0.5], f_t = [0.8,0.2], i_t = [0.5,0.9], c_tilde = [0.3,-0.7]

Output: [0.95,-0.73]

Explanation: Each feature independently combines its retained memory and gated candidate contribution.

Input: C_prev = [2,-3], f_t = [0,0], i_t = [1,1], c_tilde = [0.4,-0.2]

Output: [0.4,-0.2]

Input: C_prev = [[1,2],[-1,0.5]], f_t = [[0.5,0.25],[1,0]], i_t = [[0.5,0.75],[0,1]], c_tilde = [[0.2,0.4],[0.8,-0.6]]

Output: [[0.6,0.8],[-1,-0.6]]

Hint 1

Compute f_t * C_prev + i_t * c_tilde elementwise.

Requirements

  • Multiply the previous state by the forget gate.
  • Multiply the candidate state by the input gate.
  • Add both contributions elementwise and return float64 values.

Constraints

  • All inputs have the same shape, either (H,) or (N, H).
  • f_t and i_t contain values between 0 and 1.
  • c_tilde contains values between -1 and 1.