function v = fastrl(v0, x, lambda) %FASTRL Generates reinforcement learning expectations without using loops %written by Ryan Jessup, 20090206 %v = FASTRL(v0,x,lambda) generates reinforcement learning trial by trial %expectations v using the initialized value v0, the vector of observed %outcomes in x, and the learning rate lambda. %v0 scalar initial expectation for v %x vector of observed outcomes %lambda scalar learning parameter %set the weights on preceding information in a form the filter uses a=[1 lambda-1]; %modify the v0; this must be done because otherwise the filter does not %correctly apply the initial expectation modv0=v0/lambda; x=[modv0 x]; %append the intial expectation onto the dataset v = filter(lambda,a,x); v = v(1:end-1);