def train(_, network, lock, loss_record): game_index = network.count() print('{} game start'.format(game_index)) tree = mcts.MCTS(network, game_index) game_begin_time = int(time.time()) tree.game() learn_begin_time = int(time.time()) lock.acquire() print('{} learn start'.format(game_index)) mse_total, cross_entropy_total = 0, 0 np.random.seed(int.from_bytes(os.urandom(4), byteorder='little')) for _ in range(TRAINING_STEP): mse, cross_entropy = network.learn() mse_total += mse cross_entropy_total += cross_entropy loss_record.add( [mse_total / TRAINING_STEP, cross_entropy_total / TRAINING_STEP]) print([mse_total / TRAINING_STEP, cross_entropy_total / TRAINING_STEP]) if loss_record.size() % SAVE_INTERVAL == 0: print('save') network.save_state("{}state_{}.pkl".format(STATE_SAVE_FOLDER, loss_record.size())) network.save_memory("memory.npy") loss_record.save("loss_record.pkl") print('{} learn end'.format(game_index)) lock.release() print('{} game end'.format(game_index)) learn_end_time = int(time.time()) learn_min, learn_sec = utils.compute_time(learn_begin_time, learn_end_time) print('learning cost {} mins {} seconds'.format(learn_min, learn_sec)) game_end_time = int(time.time()) game_min, game_sec = utils.compute_time(game_begin_time, game_end_time) print('{} game cost {} mins {} seconds'.format(game_index, game_min, game_sec))
def recent_activities(self): context = aq_inner(self.context) for brain in self._data(): activity = brain[1] yield dict(time=compute_time(int(time.time()) - brain[0]), action=activity['action'], user=activity['user'], user_url="%s/author/%s" % (context.portal_url(), activity['user']), object=activity['object'], object_url=activity['object_url'], parent=activity['parent'], parent_url=activity['parent_url'], )
def recent_activities(self): context = aq_inner(self.context) activities = getUtility(IRecentActivityUtility) return [ dict(time=compute_time(int(time.time()) - activity[0]), action=activity[1]['action'], user=activity[1]['user'], user_url="%s/author/%s" % (context.portal_url(), activity[1]['user']), object=activity[1]['object'], object_url=activity[1]['object_url'], parent=activity[1]['parent'], parent_url=activity[1]['parent_url'], ) for activity in activities.getRecentActivity(100) ]
def recent_activities(self): """Recent activities, most recent activities come first. """ context = aq_inner(self.context) for brain in self._data(): activity = brain[1] fullname = '' if 'fullname' in activity: fullname = activity['fullname'] yield dict(time=compute_time(int(time.time()) - brain[0]), action=activity['action'], user=activity['user'], fullname=fullname, user_url="%s/author/%s" % (context.portal_url(), activity['user']), object=activity['object'], object_url=activity['object_url'], parent=activity['parent'], parent_url=activity['parent_url'], )