in jsuarez/extra/figures.py [0:0]
def individual(log, label, npop, logDir='resource/data/exps/', train=True):
if train:
split = 'train'
else:
split = 'test'
savedir = osp.join(logDir, label, split)
if not osp.exists(savedir):
os.makedirs(savedir)
if len(log['return']) > 0:
loglib.dark()
keys = reversed('return lifespan value value_loss pg_loss entropy grad_mean grad_std grad_min grad_max'.split())
colors = Neon.color12()
fName = 'frag.png'
for idx, key in enumerate(keys):
if idx == 0:
c = colors[idx]
loglib.plot(log[key], key, (1.0, 0, 0))
else:
c = colors[idx]
loglib.plot(log[key], key, c.norm)
maxLife = np.max(log['return'])
loglib.limits(ylims=[0, 50*(1+maxLife//50)])
loglib.godsword()
savepath = osp.join(logDir, label, split, fName)
loglib.save(savepath)
print(savepath)
plt.close()
# Construct population specific code
pop_mean_keys = ['lifespan{}_mean'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_mean.png')
gen_plot(log, pop_mean_keys, savefile, train=train)
# Per population movement probability
pop_move_keys = ['pop{}_move'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_move.png')
gen_plot(log, pop_move_keys, savefile, train=train)
# Attack probability plots
pop_move_keys = ['pop{}_range'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_range.png')
gen_plot(log, pop_move_keys, savefile, train=train)
pop_move_keys = ['pop{}_melee'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_melee.png')
gen_plot(log, pop_move_keys, savefile, train=train)
pop_move_keys = ['pop{}_mage'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_mage.png')
gen_plot(log, pop_move_keys, savefile, train=train)
# Movement tile entropy
pop_move_keys = ['pop{}_entropy'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_move_entropy.png')
gen_plot(log, pop_move_keys, savefile, train=train)
# Population attack probabilities when action is selected
pop_move_keys = ['pop{}_melee_logit'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_melee_logit.png')
gen_plot(log, pop_move_keys, savefile, train=train)
pop_move_keys = ['pop{}_range_logit'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_range_logit.png')
gen_plot(log, pop_move_keys, savefile, train=train)
pop_move_keys = ['pop{}_mage_logit'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_mage_logit.png')
gen_plot(log, pop_move_keys, savefile, train=train)
# Sum up all the logits to check if they actually sum to zero
for i in range(npop):
logit_sum = np.array(log['pop{}_melee_logit'.format(i)]) + np.array(log['pop{}_range_logit'.format(i)]) + np.array(log['pop{}_mage_logit'.format(i)])
log['pop{}_sum_logit'.format(i)] = logit_sum
pop_move_keys = ['pop{}_sum_logit'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_sum_logit.png')
gen_plot(log, pop_move_keys, savefile, train=train)
# Tile exploration statistics
pop_move_keys = ['pop{}_grass_tiles'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_grass_tiles.png')
gen_plot(log, pop_move_keys, savefile, train=train)
pop_move_keys = ['pop{}_forest_tiles'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_forest_tiles.png')
gen_plot(log, pop_move_keys, savefile, train=train)
pop_move_keys = ['pop{}_forest_tiles_depleted'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_forest_depleted.png')
gen_plot(log, pop_move_keys, savefile, train=train)
# pop_move_keys = ['pop{}_forest_tiles_other'.format(i) for i in range(npop)]
# savefile = osp.join(logDir, label, 'pop_forest_tiles_other.png')
# gen_plot(log, pop_move_keys, savefile, train=train)
for i in range(npop):
forest_tiles = np.array(log['pop{}_forest_tiles'.format(i)])
other_tiles = np.array(log['pop{}_grass_tiles'.format(i)]) + np.array(log['pop{}_forest_tiles_depleted'.format(i)]) + forest_tiles
forage_percent = forest_tiles / other_tiles
log['pop{}_forage_success'.format(i)] = forage_percent
pop_move_keys = ['pop{}_forage_success'.format(i) for i in range(npop)]
savefile = osp.join(logDir, label, split, 'pop_forage_success.png')
gen_plot(log, pop_move_keys, savefile, train=train)