ott_RW_V_base.m 852 B

1234567891011121314151617181920212223242526272829303132333435
  1. function [LH, probSpike, V, mean_predictedSpikes, RPE] = ott_RW_V_base(startValues, spikeCounts, rewards, timeLocked)
  2. % cued experiment
  3. alphaLearn = startValues(1);
  4. slope = startValues(2);
  5. intercept = startValues(3);
  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 = exp(slope*V(1:trials) + intercept);
  17. probSpike = poisspdf(spikeCounts, rateParam(timeLocked)); % mask rateParam to exclude trials where the animal didn't lick fast enough
  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