<jupyter_start><jupyter_text><jupyter_code>from matplotlib import pyplot as plt
import tensorflow as tf
import numpy as np


K = 10
global K_bandit_means
global K_bandit_vars

K_bandit_means = tf.random.uniform([K], 0, 2, tf.float32).numpy()
K_bandit_vars =  tf.random.uniform([K],0.1, 1, tf.float32).numpy()

x = np.arange(0,10)
# print(x.shape, K_bandit_means.shape)
plt.errorbar(x, K_bandit_means, yerr=K_bandit_vars, fmt='.k')
plt.grid(True)
plt.title("Bandit Values")

def get_kth_bandit(k):
  # print(K_bandit_means.shape)
  val = tf.random.normal([1], K_bandit_means[k], K_bandit_vars[k], tf.float32).numpy()
  # print(val)
  return val
  

T = 1000
vals = np.zeros((K,T))
for k in range(K):
  for t in range(T):
    vals[k,t] = get_kth_bandit(k)

q_mean = np.mean(vals,axis=1)
q_std = np.std(vals, axis=1)

print(q_mean, q_std)
print(K_bandit_means, K_bandit_vars)<jupyter_output>[1.45053046 0.25549218 0.55656233 0.8177176  0.03424681 1.24148839
 0.80659681 0.43705813 1.00382836 0.38333468] [0.82779041 0.58756646 0.38347883 0.59979563 0.41258981 0.80264331
 0.75297759 0.87258822 0.15797625 0.31771076]
[1.4217489  0.2654376  0.54407024 0.8282423  0.04768038 1.2321141
 0.8501394  0.47880268 1.0044949  0.3967774 ] [0.83289057 0.6139224  0.37383753 0.5866643  0.41467342 0.823012
 0.74582285 0.8908649  0.15955791 0.3211022 ]
{'fraction_non_alphanumeric': 0.13622754491017963, 'fraction_numerical': 0.27619760479041916, 'mean_word_length': 4.787878787878788, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '92579', 'license': 'MIT', 'n_tokens_mistral': 860, 'n_tokens_neox': 632, 'n_words': 113, 'path': 'Reinforcement_Learning_An_Introduction_by_RSutton/Code/Chapter2.ipynb', 'repo_name': 'AjayNandoriya/RLBooks', 'size': '1336'}