# Load 1D Chain and Plot

```+ Tutorial 2:
1. Initiate and Save 1D Chain
2. Load 1D Chain and Plot```

Load all the data simulated from part 1, and plot them in figure 1.As expected, mean number of action P tends to 0.75 and Q 0.25. These values as they appear in figure 1(b) will be closer to 0.75 and 0.25 if the simulation is run over longer period.

Figure 1(b) only shows the plot for members “1” and “2”. To show other members, adjust the variable member_set_to_display.

Figure 1(c) shows the probability for action Q. If we want to show the plot for action P, adjust the variable action_index_to_display=0, pointing to the action index of P.

Figure 1. (a) The actions of each member (color-coded) over the past 25 time-steps. Action is either P or Q, and the plot shows their action indices 0 and 1 respectively. (b) The ratio of the number of actions to total number of actions over the last 20 steps. This ratio is plotted over time. (c) The network in the form of 1D chain, where each label is the name of the member. Color intensity denotes the probability that the action Q is performed (action index = 1).

The code imports peripheral.py from here.

```import kero.multib.nDnet as nd
import matplotlib.pyplot as plt
from peripheral import *

import pickle
f = open("save_folder/test_beta1.pckl","rb")
f.close()
# spt.data={
# 	# Save any more data here
# 	"N": N, # chain length
# 	"mean_over_N": mean_over_N,
# 	"interval_mean_history": interval_mean_history,
# }

# network_save_pack={
# 	"network" : chain,
# 	"processor" : processor,
# 	"SAVEPOINT" : spt
# }

chain = network_save_pack["network"]
processor = network_save_pack["processor"]
spt = network_save_pack["SAVEPOINT"]

Tset=processor.Tset
action_history=processor.action_history
action_set = [x for x in processor.action_to_index_map]
action_index_set = [x for x in processor.index_to_action_map]
# for a,ai in zip(action_set,action_index_set):
# 	print("(action,index) = (",a,",",ai,")")
field_history = processor.field_history
mean_over_N=spt.data["mean_over_N"]
interval_mean_history=spt.data["interval_mean_history"]

fig=plt.figure()

# --------------------------------------------------------
# --------------------------------------------------------
start2=time.time()
processor.plot_action_over_time(
ax2,
plot_interval=(len(Tset)-24,None),
title="Action-time",
)
time_keeper("Action-time",start2)

# --------------------------------------------------------
# --------------------------------------------------------
start3=time.time()
member_set_to_display= ["1","2"] # chain.member_set #
action_index_set_to_display=action_index_set # [0,1] #

processor.plot_interval_mean_over_time(
ax3,
interval_mean_history,
member_set_to_display,
action_index_set_to_display,
plotting_interval= (1,None), # (1,None)
plotting_interval_step_length=1,
title="Mean over last " + str(mean_over_N) +" steps"
)
time_keeper("Mean-time",start3)

# --------------------------------------------------------
# --------------------------------------------------------
start4=time.time()
action_index_to_display=1
time_step=None
interval_mean_at_t=processor.extract_interval_mean_at_a_time_step(interval_mean_history,time_step=time_step)
# print("interval_mean_at_t:\n",interval_mean_at_t)
CS=[interval_mean_at_t[action_index_to_display][v][0] for v in interval_mean_at_t[action_index_to_display]]
# import numpy as np
# print(CS)
# print("shape=",np.array(CS).shape, " / len = ",len(CS))
chain.visualize_3D_graph(ax,color_set=CS,
this_figure=fig,
no_of_points_per_edge=4,
title="1D chain: act="+str(action_index_to_display),
cmap=plt.cm.spring
)
time_keeper("Graph",start4)

plt.show()```

Simulation is done using kero version: 0.5.1.