plot_simAdaptation.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. clear; clc
  2. Vinit = 0.5;
  3. alpha = 0.7;
  4. blockLen = 5;
  5. tTotal = blockLen*2;
  6. nRepeat_max = 1e5;
  7. myColors = importColors_bb();
  8. c_suc = myColors.bluishGreen;
  9. c_mal = myColors.blue;
  10. h_sim = figure;
  11. h_random = subplot(131); hold on
  12. h_suc_first = subplot(132); hold on
  13. h_mal_first = subplot(133); hold on
  14. % random
  15. V = NaN(nRepeat_max, blockLen + 2);
  16. RPE = NaN(nRepeat_max, blockLen + 1);
  17. for nRepeat = 1:nRepeat_max
  18. V(nRepeat,1) = Vinit;
  19. for t = 1:blockLen + 1
  20. r = binornd(1, 0.5);
  21. RPE(nRepeat, t) = r - V(nRepeat, t);
  22. V(nRepeat, t+1) = V(nRepeat, t) + alpha*RPE(nRepeat, t);
  23. end
  24. end
  25. subplot(h_random)
  26. suc_trials = RPE > 0;
  27. mal_trials = RPE < 0;
  28. suc_RPE = RPE;
  29. mal_RPE = RPE;
  30. suc_RPE(~suc_trials) = NaN;
  31. mal_RPE(~mal_trials) = NaN;
  32. plot(1:5, nanmean(suc_RPE(:,2:end)), 'linewidth',2,'Color',myColors.orange)
  33. plot(1:5, nanmean(mal_RPE(:,2:end)), 'linewidth',2,'Color',myColors.reddishPurple)
  34. clear V RPE
  35. % sucrose first
  36. V(1) = Vinit;
  37. for t = 1:tTotal
  38. if t <= blockLen
  39. r = 1;
  40. else
  41. r = 0;
  42. end
  43. RPE(t) = r - V(t);
  44. V(t+1) = V(t) + alpha*RPE(t);
  45. end
  46. subplot(h_suc_first); hold on
  47. plot(1:blockLen, RPE(1:blockLen), 'linewidth', 2, 'Color', c_suc)
  48. plot(blockLen+1:length(RPE), RPE(blockLen+1:end), 'linewidth', 2, 'Color', c_mal)
  49. clear V RPE
  50. % mal first
  51. V(1) = Vinit;
  52. for t = 1:tTotal
  53. if t <= blockLen
  54. r = 0;
  55. else
  56. r = 1;
  57. end
  58. RPE(t) = r - V(t);
  59. V(t+1) = V(t) + alpha*RPE(t);
  60. end
  61. subplot(h_mal_first); hold on
  62. plot(1:blockLen, RPE(1:blockLen), 'linewidth', 2, 'Color', c_mal)
  63. plot(blockLen+1:length(RPE), RPE(blockLen+1:end), 'linewidth', 2, 'Color', c_suc)
  64. % clean up figure
  65. for cp = [h_random h_suc_first h_mal_first]
  66. subplot(cp)
  67. ylim([-1 1])
  68. set(cp,'tickdir','out')
  69. ylabel('RPE')
  70. switch cp
  71. case h_random
  72. title('Random')
  73. legend('Sucrose','Maltodextrin')
  74. case h_suc_first
  75. title('Blocked (sucrose first)')
  76. legend('Sucrose','Maltodextrin')
  77. case h_mal_first
  78. title('Blocked (maltodextrin first)')
  79. end
  80. xlabel('Session progress')
  81. end