<jupyter_start><jupyter_text>NOTES USING run.py and NOT run2.py sys path (or run2.py)  may interfere with overwriting configs, NEED TO LOOK INTO MORE WILL ONLY WORK FOR SIMULATIONS WHERE N>1. CAN STILL VISUALIZE SINGLE RUN DATA AS SEEN BELOW, BUT cadCAD RUN MUST BE N>1.<jupyter_code># import sys
# sys.path.append('../')
import pandas as pd

import matplotlib.pyplot as plt
# import run2

from src.sim import run

import seaborn as sns

# For analysis
import numpy as np
import pandas as pd

sns.set_style("whitegrid")
!pip list | grep cadCAD
experiments = run.run()
experiments
experiments.dataset[0].head()
experiments.dataset[0].tail()
experiments.dataset[1].head()
len(experiments.dataset[0])
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)
# df = experiments
cols = 1
rows = 1
cc_idx = 0

# len(experiments)
# df = experiments.copy()
# print(df.head())

while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0]       
#         print(df['price'])

        df = df.groupby('timestep').agg({'price': ['min', 'mean', 'max']}).reset_index()

#         print(df.head())
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Price' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Price')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y=('price','mean'), label='Mean', ax=ax, legend=True)
        ax.fill_between(df.timestep, df[('price','min')], df[('price','max')], alpha=0.3) 


        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()<jupyter_output><empty_output><jupyter_text>FIRST RUN ONLY!<jupyter_code>experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)
# df = experiments
cols = 1
rows = 1
cc_idx = 0

# len(experiments)
# df = experiments.copy()
# print(df.head())

while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]       
#         print(df['price'])

        df = df.groupby('timestep').agg({'price': ['min', 'mean', 'max']}).reset_index()

#         print(df.head())
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Price' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Price')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y=('price','mean'), label='Mean', ax=ax, legend=True)
        ax.fill_between(df.timestep, df[('price','min')], df[('price','max')], alpha=0.3) 


        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)
# df = experiments
cols = 1
rows = 1
cc_idx = 0

# len(experiments)
# df = experiments.copy()
# print(df.head())

while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

        df = df.groupby('timestep').agg({'spot_price': ['min', 'mean', 'max']}).reset_index()

#         print(df.head())
        plot_label = experiment['rules_price']
        ax = axs
        title = 'spot_price' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('spot_price')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y=('spot_price','mean'), label='Mean', ax=ax, legend=True)
        ax.fill_between(df.timestep, df[('spot_price','min')], df[('spot_price','max')], alpha=0.3) 


        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)
# df = experiments
cols = 1
rows = 1
cc_idx = 0

# len(experiments)
# df = experiments.copy()
# print(df.head())

while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  
        df = df.groupby('timestep').agg({'alpha': ['min', 'mean', 'max']}).reset_index()

#         print(df.head())
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Alpha' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Alpha')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y=('alpha','mean'), label='Mean', ax=ax, legend=True)
        ax.fill_between(df.timestep, df[('alpha','min')], df[('alpha','max')], alpha=0.3) 


        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)
# df = experiments
cols = 1
rows = 1
cc_idx = 0

# len(experiments)
# df = experiments.copy()
# print(df.head())

while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

        df = df.groupby('timestep').agg({'reserve': ['min', 'mean', 'max']}).reset_index()

#         print(df.head())
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Reserve' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y=('reserve','mean'), label='Mean', ax=ax, legend=True)
#         ax.fill_between(df.timestep, df[('reserve','min')], df[('reserve','max')], reserve=0.3) 


        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)
# df = experiments
cols = 1
rows = 1
cc_idx = 0

# len(experiments)
# df = experiments.copy()
# print(df.head())

while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

        df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()

#         print(df.head())
        plot_label = experiment['rules_price']
        ax = axs
        title = 'supply' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y=('supply','mean'), label='Mean', ax=ax, legend=True)
#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 


        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()<jupyter_output><empty_output><jupyter_text>INTO AGENT LEVEL across AGENTS  This plot is across agents of the same variable (this case is agent_attestations_1) Can be repeated for all other columns in agents dataframe<jupyter_code>experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  
        

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_attest_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
        df['agent_2_attest_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][1]))
        df['agent_3_attest_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][2]))
        df['agent_4_attest_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][3]))
        df['agent_5_attest_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][4]))
    
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'agent_attest_1' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_attest_1', label='agent_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_attest_1', label='agent_2', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_attest_1', label='agent_3', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_attest_1', label='agent_4', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_attest_1', label='agent_5', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()<jupyter_output><empty_output><jupyter_text>INTO AGENT LEVEL across columns in AGENTS dataframe THIS CASE FIRST AGENT CAN ADD MORE VARS and REPEAT FOR OTHER AGENTS<jupyter_code>experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
        df['agent_1_supply_1'] = df.agents.apply(lambda x: np.array(x['agent_supply_1'][0]))
        df['agent_1_supply_0'] = df.agents.apply(lambda x: np.array(x['agent_supply_0'][0]))
        df['agent_1_supply_free'] = df.agents.apply(lambda x: np.array(x['agent_supply_free'][0]))
        df['agent_1_attest_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
        df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][0]))

    
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'agent_attest_1' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_reserve', label='agent_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_1_supply_1', label='agent_supply_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_1_supply_0', label='agent_supply_0', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_1_supply_free', label='agent_supply_free', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_1_attest_1', label='agent_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_1_attest_0', label='agent_attestations_0', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()<jupyter_output><empty_output><jupyter_text>DIfference in Agents to See Response This example compares reserve<jupyter_code>experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
        df['agent_2_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][1]))
        df['agent_3_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][2]))
        df['agent_4_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][3]))
        df['agent_5_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
#         print( df['agent_1_reserve'])
        df['agent_1_reserve'] = df.agent_1_reserve.diff()
        df['agent_2_reserve'] = df.agent_2_reserve.diff()
        df['agent_3_reserve'] = df.agent_3_reserve.diff()
        df['agent_4_reserve'] = df.agent_4_reserve.diff()
        df['agent_5_reserve'] = df.agent_5_reserve.diff()
        
        # hack subtracting starting amount
        df['reserve'] = df.reserve.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent Reserve Differnce vs Global Reserve' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_reserve', label='agent_1_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_reserve', label='agent_2_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_reserve', label='agent_3_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_reserve', label='agent_4_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_reserve', label='agent_5_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='reserve', label='Global_reserve', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()

experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
        df['agent_2_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][1]))
        df['agent_3_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][2]))
        df['agent_4_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][3]))
        df['agent_5_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
#         print( df['agent_1_reserve'])
        df['agent_1_reserve'] = df.agent_1_reserve.diff()
        df['agent_2_reserve'] = df.agent_2_reserve.diff()
        df['agent_3_reserve'] = df.agent_3_reserve.diff()
        df['agent_4_reserve'] = df.agent_4_reserve.diff()
        df['agent_5_reserve'] = df.agent_5_reserve.diff()
        
        # hack subtracting starting amount
        df['reserve'] = df.reserve.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent Reserve Differnce vs Global Reserve' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_reserve', label='agent_1_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_reserve', label='agent_2_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_reserve', label='agent_3_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_reserve', label='agent_4_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_reserve', label='agent_5_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='price', label='Price', ax=ax, legend=True)
        df.plot(x='timestep', y='reserve', label='Global Reserve', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()

experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
        df['agent_2_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][1]))
        df['agent_3_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][2]))
        df['agent_4_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][3]))
        df['agent_5_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
#         print( df['agent_1_reserve'])
        df['agent_1_reserve'] = df.agent_1_reserve.diff()
        df['agent_2_reserve'] = df.agent_2_reserve.diff()
        df['agent_3_reserve'] = df.agent_3_reserve.diff()
        df['agent_4_reserve'] = df.agent_4_reserve.diff()
        df['agent_5_reserve'] = df.agent_5_reserve.diff()
        
        # hack subtracting starting amount
        df['alpha'] = df.alpha.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent Reserve Differnce vs Global Reserve' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_reserve', label='agent_1_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_reserve', label='agent_2_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_reserve', label='agent_3_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_reserve', label='agent_4_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_reserve', label='agent_5_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='price', label='Price', ax=ax, legend=True)
        df.plot(x='timestep', y='alpha', label='Alpha', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
        df['agent_2_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][1]))
        df['agent_3_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][2]))
        df['agent_4_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][3]))
        df['agent_5_reserve'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_reserve'][0]))
#         print( df['agent_1_reserve'])
        df['agent_1_reserve'] = df.agent_1_reserve.diff()
        df['agent_2_reserve'] = df.agent_2_reserve.diff()
        df['agent_3_reserve'] = df.agent_3_reserve.diff()
        df['agent_4_reserve'] = df.agent_4_reserve.diff()
        df['agent_5_reserve'] = df.agent_5_reserve.diff()
        
        # hack subtracting starting amount
#         df['alpha'] = df.alpha.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent Reserve Differnce vs Global Reserve' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']
        
#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_reserve', label='agent_1_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_reserve', label='agent_2_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_reserve', label='agent_3_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_reserve', label='agent_4_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_reserve', label='agent_5_reserve', ax=ax, legend=True)
        df.plot(x='timestep', y='private_price', label='Private Price', ax=ax, legend=True)
        df.plot(x='timestep', y='price', label='Alpha', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
        df['agent_2_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][1]))
        df['agent_3_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][2]))
        df['agent_4_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][3]))
        df['agent_5_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
#         print( df['agent_1_attestations_1'])
        df['agent_1_attestations_1'] = df.agent_1_attestations_1.diff()
        df['agent_2_attestations_1'] = df.agent_2_attestations_1.diff()
        df['agent_3_attestations_1'] = df.agent_3_attestations_1.diff()
        df['agent_4_attestations_1'] = df.agent_4_attestations_1.diff()
        df['agent_5_attestations_1'] = df.agent_5_attestations_1.diff()
        
        # hack subtracting starting amount
#         df['alpha'] = df.alpha.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent attestations_1 Difference vs Global attestations_1' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']

#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_attestations_1', label='agent_1_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_attestations_1', label='agent_2_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_attestations_1', label='agent_3_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_attestations_1', label='agent_4_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_attestations_1', label='agent_5_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='private_alpha', label='Private Alpha', ax=ax, legend=True)
        df.plot(x='timestep', y='alpha', label='Alpha', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
        df['agent_2_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][1]))
        df['agent_3_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][2]))
        df['agent_4_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][3]))
        df['agent_5_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
#         print( df['agent_1_attestations_1'])
        df['agent_1_attestations_1'] = df.agent_1_attestations_1.diff()
        df['agent_2_attestations_1'] = df.agent_2_attestations_1.diff()
        df['agent_3_attestations_1'] = df.agent_3_attestations_1.diff()
        df['agent_4_attestations_1'] = df.agent_4_attestations_1.diff()
        df['agent_5_attestations_1'] = df.agent_5_attestations_1.diff()
        
        
        df['agent_1_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][0]))
        df['agent_2_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][1]))
        df['agent_3_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][2]))
        df['agent_4_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][3]))
        df['agent_5_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
#         print( df['agent_1_attestations_1'])
        df['agent_1_attestations_0'] = - df.agent_1_attestations_0.diff()
        df['agent_2_attestations_0'] = - df.agent_2_attestations_0.diff()
        df['agent_3_attestations_0'] = - df.agent_3_attestations_0.diff()
        df['agent_4_attestations_0'] = - df.agent_4_attestations_0.diff()
        df['agent_5_attestations_0'] = - df.agent_5_attestations_0.diff()
        
        
        # hack subtracting starting amount
#         df['alpha'] = df.alpha.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent attestations_1 Difference vs Global attestations_1' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']

#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_attestations_1', label='agent_1_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_attestations_1', label='agent_2_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_attestations_1', label='agent_3_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_attestations_1', label='agent_4_attestations_1', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_attestations_1', label='agent_5_attestations_1', ax=ax, legend=True)
        
        df.plot(x='timestep', y='agent_1_attestations_0', label='agent_1_attestations_0', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_2_attestations_0', label='agent_2_attestations_0', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_3_attestations_0', label='agent_3_attestations_0', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_4_attestations_0', label='agent_4_attestations_0', ax=ax, legend=True)
        df.plot(x='timestep', y='agent_5_attestations_0', label='agent_5_attestations_0', ax=ax, legend=True)
        df.plot(x='timestep', y='private_alpha', label='Private Alpha', ax=ax, legend=True)
        df.plot(x='timestep', y='alpha', label='Alpha', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][0]))
        df['agent_2_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][1]))
        df['agent_3_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][2]))
        df['agent_4_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][3]))
        df['agent_5_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][4]))
# #         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
# #         print( df['agent_1_attestations_1'])
#         df['agent_1_attestations_1'] = df.agent_1_attestations_1.diff()
#         df['agent_2_attestations_1'] = df.agent_2_attestations_1.diff()
#         df['agent_3_attestations_1'] = df.agent_3_attestations_1.diff()
#         df['agent_4_attestations_1'] = df.agent_4_attestations_1.diff()
#         df['agent_5_attestations_1'] = df.agent_5_attestations_1.diff()
        
        
#         df['agent_1_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][0]))
#         df['agent_2_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][1]))
#         df['agent_3_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][2]))
#         df['agent_4_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][3]))
#         df['agent_5_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][4]))
# #         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
# #         print( df['agent_1_attestations_1'])
#         df['agent_1_attestations_0'] = - df.agent_1_attestations_0.diff()
#         df['agent_2_attestations_0'] = - df.agent_2_attestations_0.diff()
#         df['agent_3_attestations_0'] = - df.agent_3_attestations_0.diff()
#         df['agent_4_attestations_0'] = - df.agent_4_attestations_0.diff()
#         df['agent_5_attestations_0'] = - df.agent_5_attestations_0.diff()
        
        
        # hack subtracting starting amount
#         df['alpha'] = df.alpha.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent Private Alpha vs Global Alpha' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Alpha Value')
        colors = ['b','orange', 'g', 'magenta', 'r', 'k' ]
#         df['agent_1_attestations_1'] = df['agent_1_attestations_1'][0]
        
        plt.hlines(y= max(df['agent_1_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 1 Private Alpha',  color = colors[0])
        plt.hlines(y= max(df['agent_2_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 2 Private Alpha',  color = colors[1])
        plt.hlines(y= max(df['agent_3_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 3 Private Alpha',  color = colors[2])
        plt.hlines(y= max(df['agent_4_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 4 Private Alpha',  color = colors[3])
        plt.hlines(y= max(df['agent_5_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 5 Private Alpha',  color = colors[4])

#         df.plot(x='timestep', y='agent_1_attestations_1', label='agent_1_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_2_attestations_1', label='agent_2_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_3_attestations_1', label='agent_3_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_4_attestations_1', label='agent_4_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_5_attestations_1', label='agent_5_attestations_1', ax=ax, legend=True)
        
#         df.plot(x='timestep', y='agent_1_attestations_0', label='agent_1_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_2_attestations_0', label='agent_2_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_3_attestations_0', label='agent_3_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_4_attestations_0', label='agent_4_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_5_attestations_0', label='agent_5_attestations_0', ax=ax, legend=True)
        df.plot(x='timestep', y='private_alpha', label='Private Alpha', ax=ax, legend=True, kind= 'scatter')
        df.plot(x='timestep', y='alpha', label='Alpha', ax=ax, legend=True, color = colors[5])

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
#         df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][0]))
        df['agent_2_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][1]))
#         df['agent_3_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][2]))
#         df['agent_4_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][3]))
#         df['agent_5_private_alpha'] = df.agents.apply(lambda x: np.array(x['agent_private_alpha'][4]))
# #         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
# #         print( df['agent_1_attestations_1'])
#         df['agent_1_attestations_1'] = df.agent_1_attestations_1.diff()
#         df['agent_2_attestations_1'] = df.agent_2_attestations_1.diff()
#         df['agent_3_attestations_1'] = df.agent_3_attestations_1.diff()
#         df['agent_4_attestations_1'] = df.agent_4_attestations_1.diff()
#         df['agent_5_attestations_1'] = df.agent_5_attestations_1.diff()
        
        
#         df['agent_1_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][0]))
#         df['agent_2_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][1]))
#         df['agent_3_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][2]))
#         df['agent_4_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][3]))
#         df['agent_5_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][4]))
# #         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
# #         print( df['agent_1_attestations_1'])
#         df['agent_1_attestations_0'] = - df.agent_1_attestations_0.diff()
#         df['agent_2_attestations_0'] = - df.agent_2_attestations_0.diff()
#         df['agent_3_attestations_0'] = - df.agent_3_attestations_0.diff()
#         df['agent_4_attestations_0'] = - df.agent_4_attestations_0.diff()
#         df['agent_5_attestations_0'] = - df.agent_5_attestations_0.diff()
        
        
        # hack subtracting starting amount
#         df['alpha'] = df.alpha.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent Private Alpha vs Global Alpha' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Alpha Value')
        colors = ['b','orange', 'g', 'magenta', 'r', 'k' ]
#         df['agent_1_attestations_1'] = df['agent_1_attestations_1'][0]
        
        plt.hlines(y= max(df['agent_1_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 1 Private Alpha',  color = colors[0])
        plt.hlines(y= max(df['agent_2_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 2 Private Alpha',  color = colors[1])
#         plt.hlines(y= max(df['agent_3_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 3 Private Alpha',  color = colors[2])
#         plt.hlines(y= max(df['agent_4_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 4 Private Alpha',  color = colors[3])
#         plt.hlines(y= max(df['agent_5_private_alpha']), xmin=0, xmax=max(df.timestep), label = 'Agent 5 Private Alpha',  color = colors[4])

#         df.plot(x='timestep', y='agent_1_attestations_1', label='agent_1_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_2_attestations_1', label='agent_2_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_3_attestations_1', label='agent_3_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_4_attestations_1', label='agent_4_attestations_1', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_5_attestations_1', label='agent_5_attestations_1', ax=ax, legend=True)
        
#         df.plot(x='timestep', y='agent_1_attestations_0', label='agent_1_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_2_attestations_0', label='agent_2_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_3_attestations_0', label='agent_3_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_4_attestations_0', label='agent_4_attestations_0', ax=ax, legend=True)
#         df.plot(x='timestep', y='agent_5_attestations_0', label='agent_5_attestations_0', ax=ax, legend=True)
        df.plot(x='timestep', y='private_alpha', label='Private Alpha', ax=ax, legend=True, kind= 'scatter')
        df.plot(x='timestep', y='alpha', label='Alpha', ax=ax, legend=True, color = colors[5])

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
experiments = experiments.sort_values(by =['rules_price']).reset_index(drop=True)

cols = 1
rows = 1
cc_idx = 0
# config_labels = ['RULE 1,'RULE 2']


while cc_idx<len(experiments):
    cc = experiments.iloc[cc_idx]['rules_price']
    cc_label = experiments.iloc[cc_idx]['rules_price']
#     secondary_label = experiments.iloc[cc_idx]['string']
    sub_experiments = experiments[experiments['rules_price']==cc]
    cc_idx += len(sub_experiments)
    fig, axs = plt.subplots(ncols=cols, nrows=rows, figsize=(15*cols,7*rows))
    sub_experiments.reset_index(drop=False)
    for i, experiment in sub_experiments.iterrows():
        df = experiment['dataset'].copy()
        # filter out starting point
        df = df[df.timestep > 0] 
        # FIRST RUN ONLY
        df = df[df.run == 1]  

# MAKE A FOR LOOP or FUNCTION FOR ALL AGENTS
        df['agent_1_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
        df['agent_2_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][1]))
        df['agent_3_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][2]))
        df['agent_4_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][3]))
        df['agent_5_attestations_1'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
#         print( df['agent_1_attestations_1'])
        df['agent_1_attestations_1'] = df.agent_1_attestations_1.diff()
        df['agent_2_attestations_1'] = df.agent_2_attestations_1.diff()
        df['agent_3_attestations_1'] = df.agent_3_attestations_1.diff()
        df['agent_4_attestations_1'] = df.agent_4_attestations_1.diff()
        df['agent_5_attestations_1'] = df.agent_5_attestations_1.diff()
        
        
        df['agent_1_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][0]))
        df['agent_2_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][1]))
        df['agent_3_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][2]))
        df['agent_4_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][3]))
        df['agent_5_attestations_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_0'][4]))
#         df['agent_1_attest_0'] = df.agents.apply(lambda x: np.array(x['agent_attestations_1'][0]))
#         print( df['agent_1_attestations_1'])
        df['agent_1_attestations_0'] = - df.agent_1_attestations_0.diff()
        df['agent_2_attestations_0'] = - df.agent_2_attestations_0.diff()
        df['agent_3_attestations_0'] = - df.agent_3_attestations_0.diff()
        df['agent_4_attestations_0'] = - df.agent_4_attestations_0.diff()
        df['agent_5_attestations_0'] = - df.agent_5_attestations_0.diff()
        
        
        # hack subtracting starting amount
#         df['alpha'] = df.alpha.diff()
        
#         df = df.groupby('timestep').agg({'supply': ['min', 'mean', 'max']}).reset_index()
    
#         df['agent_attest_1'] = np.array(df.agent_attest_1,dtype = float)
#         print(df['agent_attest_1'])
#         print(df['agent_attest_1'][10])
        plot_label = experiment['rules_price']
        ax = axs
        title = 'Agent attestations_1 Difference vs Global attestations_1' + '\n' + 'Scenario: ' + str(cc_label)  + ' rules_price'
        ax.set_title(title)
        ax.set_ylabel('Amount')
        colors = ['b','orange', 'g', 'magenta', 'r']

#         ax.plot(df.timestep, df['price'],color = colors[0], label='Price')
        df.plot(x='timestep', y='agent_1_attestations_1', label='agent_1_attestations_1', ax=ax, legend=True, color = colors[0])
        df.plot(x='timestep', y='agent_2_attestations_1', label='agent_2_attestations_1', ax=ax, legend=True, color = colors[1])
        df.plot(x='timestep', y='agent_3_attestations_1', label='agent_3_attestations_1', ax=ax, legend=True, color = colors[2])
        df.plot(x='timestep', y='agent_4_attestations_1', label='agent_4_attestations_1', ax=ax, legend=True, color = colors[3])
        df.plot(x='timestep', y='agent_5_attestations_1', label='agent_5_attestations_1', ax=ax, legend=True, color = colors[4])
        
        df.plot(x='timestep', y='agent_1_attestations_0', label='agent_1_attestations_0', ax=ax, legend=True, color = colors[0])
        df.plot(x='timestep', y='agent_2_attestations_0', label='agent_2_attestations_0', ax=ax, legend=True, color = colors[1])
        df.plot(x='timestep', y='agent_3_attestations_0', label='agent_3_attestations_0', ax=ax, legend=True, color = colors[2])
        df.plot(x='timestep', y='agent_4_attestations_0', label='agent_4_attestations_0', ax=ax, legend=True, color = colors[3])
        df.plot(x='timestep', y='agent_5_attestations_0', label='agent_5_attestations_0', ax=ax, legend=True, color = colors[4])
#         df.plot(x='timestep', y='private_alpha', label='Private Alpha', ax=ax, legend=True)
#         df.plot(x='timestep', y='alpha', label='Alpha', ax=ax, legend=True)

#         ax.fill_between(df.timestep, df[('supply','min')], df[('supply','max')], supply=0.3) 

        ax.legend()

        ax.set_xlabel('Timesteps')
        ax.grid(color='0.9', linestyle='-', linewidth=1)

        plt.tight_layout()
        
fig.tight_layout(rect=[0, 0, 1, .97])
fig.patch.set_alpha(1)
display(fig)
plt.close()
print(df['private_alpha'].unique())
df.private_alpha.hist()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup