<jupyter_start><jupyter_text>The successor representation in human reinforcement learningReimplementation of:<NAME>., <NAME>., <NAME>., <NAME>., <NAME>., and <NAME>. (2017). The successor representation in human reinforcement learning. Nature Human Behaviour 1, 680–692. doi:10.1038/s41562-017-0180-8.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()<jupyter_output><empty_output><jupyter_text>Experiment 1: differential sensitivity to reward and transition revaluation<jupyter_code># Parameters
gamma = 1.0
nb_states = 6

# Reward revaluation
T = np.zeros((nb_states, nb_states))
T[0, 2] = 1.; T[2, 4] = 1.; T[1, 3] = 1.; T[3, 5] = 1.;  
R1 = np.zeros((nb_states, nb_states))
R1[2, 4] = 10.0; R1[3, 5] = 1.0
R2 = np.zeros((nb_states, nb_states))
R2[2, 4] = 1.0; R2[3, 5] = 10.0

# Transition revaluation
T1 = np.zeros((nb_states, nb_states))
T1[0, 2] = 1.; T1[2, 4] = 1.; T1[1, 3] = 1.; T1[3, 5] = 1.;  
T2 = np.zeros((nb_states, nb_states))
T2[0, 2] = 1.; T2[2, 5] = 1.; T2[1, 3] = 1.; T2[3, 4] = 1.; 
R3 = np.zeros((nb_states, nb_states))
R3[2, 4] = 10.0; R3[3, 5] = 1.0
R4 = np.zeros((nb_states, nb_states))
R4[2, 5] = 1.0; R4[3, 4] = 10.0
b = sns.xkcd_rgb["denim blue"]
r = sns.xkcd_rgb["pale red"]

fig, ax = plt.subplots(figsize=(10, 5))

reward = ax.bar(
    [0, 3, 6, 9], 
    [0.01, 0.5, 0.5, 0.51],
    color=r,
    width=1.0, bottom=0.0)

transition = ax.bar(
    [1, 4, 7, 10], 
    [0.01, 0.5, 0.01, 0.45],
    color=b,
    width=1.0, bottom=0.0)

ax.set_ylabel("Revaluation score")
ax.set_xticks([0.5, 3.5, 6.5, 9.5])
ax.set_xticklabels(["MF", "MB", "SR", "Human"])
ax.legend((reward[0], transition[0]), ('Reward', 'Transition'))
plt.savefig("sr_results.png", dpi=150)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20835686053077357, 'fraction_numerical': 0.10276679841897234, 'mean_word_length': 4.136231884057971, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '172248', 'license': 'MIT', 'n_tokens_mistral': 924, 'n_tokens_neox': 818, 'n_words': 191, 'path': 'content/post/successor_representations/SR_humanRL.ipynb', 'repo_name': 'vitay/academic-kickstart', 'size': '1810'}