A binary label (0 or 1) is associated with each input. The output values are all 0. Once the cumulative sum of the input values in the sequence exceeds a threshold, then the output value flips from 0 to 1. A threshold of 1/4 the sequence length is used. For example, below is a sequence of 10 input timesteps (X): 0.63144003 0.29414551 0.91587952 0.95189228 0.32195638 0.60742236 0.83895793 0.18023048 0.84762691 0.29165514 The corresponding classification output (y) would be: 0 0 0 1 1 1 1 1 1 1 """ lstm = LSTM(1, 1, 32) lstm_params = lstm._init_params() def loss_fn(pred, target): one = np.ones_like(pred) epsilon = 1.e-20 # to prevent log(0) a = target * np.log(pred + epsilon) b = (one - target) * np.log(one - pred + epsilon) return np.mean(-(a + b)) def print_training_prediction(params, iters): X, y = get_sequence(10) h, s = None, None result = []