ott_gRW_RPE_base.m 790 B

1234567891011121314151617181920212223242526272829303132
  1. function [LH, probSpike, V, mean_predictedSpikes, RPE] = ott_gRW_RPE_base(startValues, spikeRate, rewards, timeLocked)
  2. alphaLearn = startValues(1);
  3. slope = startValues(2);
  4. intercept = startValues(3);
  5. sigma = startValues(4);
  6. Vinit = 0.5;
  7. trials = length(rewards);
  8. V = zeros(trials + 1, 1);
  9. RPE = zeros(trials, 1);
  10. V(1) = Vinit;
  11. % Call learning rule
  12. for t = 1:trials
  13. RPE(t) = rewards(t) - V(t);
  14. V(t + 1) = V(t) + alphaLearn*RPE(t);
  15. end
  16. rateParam = slope*RPE + intercept;
  17. probSpike = normpdf(spikeRate, rateParam(timeLocked), sigma); % normal distribution
  18. mean_predictedSpikes = rateParam(timeLocked);
  19. V = V(1:trials);
  20. V = V(timeLocked);
  21. RPE = RPE(timeLocked);
  22. if any(isinf(log(probSpike)))
  23. LH = 1e9;
  24. else
  25. LH = -1 * sum(log(probSpike));
  26. end