<jupyter_start><jupyter_text>Part 1: Averaging of only noise<jupyter_code># fix the size of the sample
size = 1000
# generate noise from an array of available choices
noise = np.random.choice([-1,1] , size=size)
# declaring a sample mean array
sample_mean = np.zeros_like(noise , dtype=np.float)

# loop to calculate the sample mean for every time step
for t in range(size):
    sample_mean[t] = np.mean(noise[:t+1])
    
plt.plot(range(sample_mean.shape[0]) , sample_mean , "k--", label="Sample Mean")

# plotting the 1/sqrt(t) on the same figure
sqrt_t = 1/(np.sqrt(np.arange(sample_mean.shape[0])) + 1)
plt.plot(range(sample_mean.shape[0]) , sqrt_t , "b-" , range(sample_mean.shape[0]) , -sqrt_t , "b-" , label="sqrt_t")

# plottin the 1/t on the same figure
inv_t = 1/(np.arange(sample_mean.shape[0]) + 1)
plt.plot(range(sample_mean.shape[0]) , inv_t , "r-" , range(sample_mean.shape[0]) , -inv_t , "r-" , label="1/t")

plt.legend()<jupyter_output><empty_output><jupyter_text>Part 2: Averaging of only noise using recursion<jupyter_code># fix the size of the sample
size = 1000
k = 100
# generate noise from an array of available choices
noise = np.random.choice([-1,1] , size=size)
# declaring a sample mean array
sample_mean = np.zeros_like(noise , dtype=np.float)

# loop to calculate the sample mean for every time step
sample_mean[0] = 0
for t in range(1 , size):
    alpha = 1/(t+k)
    sample_mean[t] = sample_mean[t-1] + alpha* (noise[t] - sample_mean[t-1])
    
plt.plot(range(sample_mean.shape[0]) , sample_mean , "k--" , label="Sample Mean")


# plotting the 1/sqrt(t) on the same figure
sqrt_t = 1/(np.sqrt(np.arange(sample_mean.shape[0])) + 1)
plt.plot(range(sample_mean.shape[0]) , sqrt_t , "b-" , range(sample_mean.shape[0]) , -sqrt_t , "b-" , label="sqrt_t")

# plottin the 1/t on the same figure
inv_t = 1/(np.arange(sample_mean.shape[0]) + 1)
plt.plot(range(sample_mean.shape[0]) , inv_t , "r-" , range(sample_mean.shape[0]) , -inv_t , "r-" , label="1/t")

plt.legend()
# # plottin the 1/t on the same figure
# inv_t_plus_k = 1/(np.arange(sample_mean.shape[0]) + k)
# plt.plot(range(sample_mean.shape[0]) , inv_t_plus_k , "g-" , range(sample_mean.shape[0]) , -inv_t_plus_k , "g-")<jupyter_output><empty_output><jupyter_text>Part 3: Averaging of only noise using recursion with fixed alpha<jupyter_code># fix the size of the sample
size = 100
alpha = 0.9
# generate noise from an array of available choices
noise = np.random.choice([-1,1] , size=size)
# declaring a sample mean array
sample_mean = np.zeros_like(noise , dtype=np.float)

# loop to calculate the sample mean for every time step
sample_mean[0] = noise[0]
for t in range(1 , size):
    sample_mean[t] = sample_mean[t-1] + alpha* (noise[t] - sample_mean[t-1])
    
plt.plot(range(sample_mean.shape[0]) , sample_mean , "k--", label="Sample Mean")

# plotting the 1/sqrt(t) on the same figure
sqrt_t = 1/(np.sqrt(np.arange(sample_mean.shape[0])) + 1)
plt.plot(range(sample_mean.shape[0]) , sqrt_t , "b-" , range(sample_mean.shape[0]) , -sqrt_t , "b-", label="sqrt_t")

# plottin the 1/t on the same figure
inv_t = 1/(np.arange(sample_mean.shape[0]) + 1)
plt.plot(range(sample_mean.shape[0]) , inv_t , "r-" , range(sample_mean.shape[0]) , -inv_t , "r-" , label="1/t")

plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16438772409601946, 'fraction_numerical': 0.02552415679124886, 'mean_word_length': 4.735191637630662, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '431548', 'license': 'MIT', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1263, 'n_words': 306, 'path': 'week13/temporal_difference_learning.ipynb', 'repo_name': 'KishoreKaushal/ailab', 'size': '3291'}