move total_parley update to update_counters
@@ -245,13 +245,14 @@ class World(object):
"""Performs any cleanup, if appropriate."""
pass
- def update_total_epochs(self):
+ def update_counters(self):
"""Update how many epochs have completed"""
+ self.total_parleys += 1
if not self.max_exs:
self.max_exs = self.num_examples() * self.opt['num_epochs'] if self.num_examples() else -1
# when we know the size of the data
if self.max_exs > 0:
- self.total_epochs = int(self.total_parleys * self.opt['batchsize'] / self.num_examples())
+ self.total_epochs = self.total_parleys * self.opt['batchsize'] / self.num_examples()
# when we do not know the size of the data
else:
if self.epoch_done():
@@ -284,8 +285,7 @@ class DialogPartnerWorld(World):
agents[1].observe(validate(acts[0]))
acts[1] = agents[1].act()
agents[0].observe(validate(acts[1]))
- self.total_parleys += 1
- self.update_total_epochs()
+ self.update_counters()
def episode_done(self):
""" Only the first agent indicates when the episode is done."""
@@ -346,8 +346,7 @@ class MultiAgentDialogWorld(World):
for other_agent in self.agents:
if other_agent != agent:
other_agent.observe(validate(acts[index]))
- self.total_parleys += 1
- self.update_total_epochs()
+ self.update_counters()
def epoch_done(self):
done = False
@@ -422,8 +421,7 @@ class ExecutableWorld(MultiAgentDialogWorld):
obs = self.observe(other_agent, acts[index])
if obs is not None:
other_agent.observe(obs)
- self.total_parleys += 1
- self.update_total_epochs()
+ self.update_counters()
class MultiWorld(World):
@@ -514,8 +512,7 @@ class MultiWorld(World):
def parley(self):
self.parley_init()
self.worlds[self.world_idx].parley()
- self.total_parleys += 1
- self.update_total_epochs()
+ self.update_counters()
def display(self):
if self.world_idx != -1:
@@ -656,8 +653,7 @@ class BatchWorld(World):
obs = self.batch_observe(other_index, batch_act, agent_idx)
if obs is not None:
batch_observations[other_index] = obs
- self.total_parleys += 1
- self.update_total_epochs()
+ self.update_counters()
def display(self):
s = ("[--batchsize " + str(len(self.worlds)) + "--]\n")
@@ -798,8 +794,7 @@ class HogwildWorld(World):
with self.cnt.get_lock():
self.cnt.value += 1
self.queued_items.release()
- self.total_parleys += 1
- self.update_total_epochs()
+ self.update_counters()
def getID(self):
return self.inner_world.getID()
