The TD model of classical conditioning turns the trial-level Rescorla–Wagner model into a real-time model: time inside a trial is divided into steps, the US prediction is learned with TD(), and stimuli are represented by a complete serial compound (CSC), a tapped delay line with one feature per CS per time step.
Implement td_model_csc(trials, n_cs, trial_len, alpha, gamma, lam, w=None).
Trials. Each trial is a pair (cs_list, us). cs_list holds (i, onset, offset) triples: CS i is present at steps with onset offset. us is None or (u, magnitude): the US is received as the target on the transition from step to step , with where = trial_len.
Features. The weights have shape (n_cs, L). At step the feature vector has a 1 at position for every CS present at , and 0 elsewhere. The US prediction is . After step the trial moves to an inter-trial state with no features, so there.
Learning. At the start of every trial reset the trace to zero. Then for :
w (if given) holds starting weights; do not modify it in place. Return the final weights as a float array of shape (n_cs, L).