Skip to content

Commit

Permalink
plot done with zoomed section
Browse files Browse the repository at this point in the history
  • Loading branch information
aadeshnpn committed Feb 7, 2022
1 parent 50bb554 commit 0dd4345
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
69 changes: 59 additions & 10 deletions examples/coevolution/plots.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from cProfile import label
from email import header
import os
import numpy as np
Expand Down Expand Up @@ -1416,7 +1417,7 @@ def plot_lt_foraging_gentic(ip=0.85, time=1000):
plt.close(fig)


def plot_lt_foraging_gentic_baseline_foraging(ip=0.85, time=10000):
def plot_foraging_baseline(ip=0.85, time=10000):
fig = plt.figure(figsize=(8,6), dpi=200)
# data = np.mean(np.squeeze(read_data_n_agent_perturbations_all(
# n=100, iter=12000, threshold=7, time=time, iprob=0.85,
Expand All @@ -1434,13 +1435,6 @@ def plot_lt_foraging_gentic_baseline_foraging(ip=0.85, time=10000):
xvalues = np.array(list(range(12002)))
# mask = xvalues % 500 == 0
mask = [True] * len(xvalues)
# ax1.plot(xvalues[mask], data[1,:][mask], 'o-', label='Lateral Transfer Rate')
# ax1.plot(xvalues[mask], data[2,:][mask], 'o-', label='Genetic Step Rate')
# ax1.legend(fontsize="small", loc="upper left", title='Metric')
# ax1.set_xlabel('Evolution Steps')
# ax1.set_ylabel('Rate per step')
# ax1.set_yticks(range(0, 50, 10))

ax1.plot(xvalues[mask], q2[0,:][mask], '-', label='Foraging', color='green')
ax1.fill_between(
xvalues[mask], q1[0,:][mask], q3[0,:][mask], color='seagreen', alpha=0.3)
Expand All @@ -1457,14 +1451,67 @@ def plot_lt_foraging_gentic_baseline_foraging(ip=0.85, time=10000):
plt.title('Baseline')
plt.tight_layout()
maindir = '/tmp/swarm/data/experiments/'
fig.savefig(
maindir + 'baselineallplot'+ '.png')
plt.close(fig)


def plot_foraging_baseline_trap(ip=0.85, time=1000):
fig = plt.figure(figsize=(8,6), dpi=200)
basedata = np.squeeze(read_data_n_agent_perturbations_all(
n=100, iter=12000, threshold=7, time=10000, iprob=0.85,
no_objects=1, radius=5, idx=[2,4]))

baseq2 = np.median(basedata, axis=1)
baseq1 = np.quantile(basedata, axis=1, q=0.25)
baseq3 = np.quantile(basedata, axis=1, q=0.75)
ax1 = fig.add_subplot(1, 1, 1)
xvalues = np.array(list(range(12002)))
mask = xvalues % 500 == 0
# mask = [True] * len(xvalues)
ax1.plot(xvalues[mask], baseq2[0,:][mask], '-', label='Baseline Foraging', color='green')
ax1.fill_between(
xvalues[mask], baseq1[0,:][mask], baseq3[0,:][mask], color='seagreen', alpha=0.3)

ax_zoom = ax1.inset_axes([0.05,0.5,0.47,0.47])
data = np.squeeze(read_data_n_agent_perturbations_all(
n=100, iter=12000, threshold=7, time=time, iprob=0.85, addobject='Traps',
no_objects=1, radius=10, idx=[2,4]))

q2 = np.median(data, axis=1)
q1 = np.quantile(data, axis=1, q=0.25)
q3 = np.quantile(data, axis=1, q=0.75)
xvalues = np.array(list(range(12002)))
mask = [True] * len(xvalues)
ax1.plot(xvalues[mask], q2[0,:][mask], '-', label='Foraging with Trap', color='red')
ax1.fill_between(
xvalues[mask], q1[0,:][mask], q3[0,:][mask], color='salmon', alpha=0.3)

ax_zoom.plot(xvalues[mask], q2[0,:][mask], '-', label='Trap', color='red')
ax_zoom.plot(xvalues[mask], baseq2[0,:][mask], '-', label='Baseline', color='green')
ax_zoom.set_xlim(1000,2000)
ax_zoom.set_ylim(0,8)
ax1.indicate_inset_zoom(ax_zoom, edgecolor="black", label="Zoomed", alpha=0.5)

ax1.legend(fontsize="small", loc="lower right", title="Learning Efficiency")
ax1.set_xlabel('Evolution Steps')
ax1.set_ylabel('Foraging (%)')
ax1.set_yticks(range(0, 105, 20))
ax2 = ax1.twinx()
ax2.set_yticks(range(0, 105, 20))

plt.title('Trap Added at 1000 Step')
plt.tight_layout()
maindir = '/tmp/swarm/data/experiments/'
# fname = 'agentsitecomp' + agent
# nadir = os.path.join(maindir, str(100))

fig.savefig(
maindir + 'baselineallplot'+ '.png')
maindir + 'baseline_trap_zoom_'+ str(time)+ '.png')
plt.close(fig)



def obstacle_introduced_compare():
timings = range(7000, 11001, 1000)
# data50 = [read_data_n_agent_perturbations(
Expand Down Expand Up @@ -1523,7 +1570,9 @@ def main():
# obstacle_introduced_compare()
# for t in range(1000,11001,1000):
# plot_lt_foraging_gentic(time=t)
plot_lt_foraging_gentic_baseline_foraging()
# plot_foraging_baseline()
# plot_foraging_baseline_obstacle()
plot_foraging_baseline_trap()


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy
psycopg2-binary
joblib
joblib

0 comments on commit 0dd4345

Please sign in to comment.