def display_sizes_iteration(prefix, **plot_kwargs): """ Display memory comparison """ pks = [] if isinstance(prefix, (str, unicode)): prefix = [prefix] for pre in prefix: pks += sorted(filter(lambda x: x.startswith(pre), listdir('../performance')), key=lambda x: int(x.split('-')[2]), reverse=False) rewards_dict = OrderedDict() x_axis = list() for pk in sorted(pks, key=lambda x: int(x.split('-')[1])): rewards = pickle.load(open('../performance/{}'.format(pk), 'r+'))[150:] frame = pd.DataFrame(rewards).head(100) key = pk.split('.')[2] x_axis.append(int(pk.split('-')[1])) rewards_dict.setdefault(algorithm_mapper[key], list()) rewards_dict[algorithm_mapper[key]].append(frame.sum(axis=1).mean()) results = OrderedDict() for key in rewards_dict.keys(): results[key] = sorted(rewards_dict[key], reverse=True) # results = rewards_dict plot_kwargs['x_axis'] = [] for _ in x_axis: if _ not in plot_kwargs['x_axis']: plot_kwargs['x_axis'].append(_) display_multiple_(results, **plot_kwargs)
def size_comparison(algorithm, circles=200, dump=True, display=True, algorithm_type='original', prefix='', **plot_kwargs): """ Algorithm comparison Args: algorithm(function): algorithm circles(int): circles dump(boolean): whether to dump result to file display(boolean): whether to display algorithm_type(string): algorithm type prefix(string): prefix """ configs = filter(lambda x: x.startswith('sizes_comparison'), listdir('../etc')) rewards_dict = dict() for config in configs: key = 'Size-{}'.format(config.split('_')[-1]).split('.')[0] rewards_dict[key] = simulate_with_(algorithm, config=config, circles=circles, dump=dump, algorithm_type=algorithm_type, prefix=prefix, fixed_theta=True) if display: display_multiple_(rewards_dict, **plot_kwargs) return rewards_dict
def display_bs_comparison_by_(prefix, **plot_kwargs): """ Display memory comparison. Args: prefix(prefix): prefix string """ pks = sorted(filter(lambda x: x.startswith(prefix), listdir('../performance')), key=lambda x: int(x.split('-')[2]), reverse=True) rewards_dict = OrderedDict() for pk in pks: rewards = pickle.load(open('../performance/{}'.format(pk), 'r+')) key = 'Memory-{}'.format(pk.split('-')[2]) rewards_dict[key] = rewards display_multiple_(rewards_dict, **plot_kwargs)
def display_bs_iteration(prefix, **plot_kwargs): """ Display memory comparison """ pks = [] if isinstance(prefix, (str, unicode)): prefix = [prefix] for pre in prefix: pks += sorted(filter(lambda x: x.startswith(pre), listdir('../performance')), key=lambda x: int(x.split('-')[2]), reverse=False) rewards_dict = OrderedDict() x_axis = list() for pk in sorted(pks, key=lambda x: int(x.split('-')[0].split('.')[-1])): rewards = pickle.load(open('../performance/{}'.format(pk), 'r+'))[40:] frame = pd.DataFrame(rewards).head(100) key = pk.split('.')[2] if key == 'branch_and_bound': key = key + '_' + pk.split('.')[3] x_axis.append(int(pk.split('-')[0].split('.')[-1])) rewards_dict.setdefault(key, list()) rewards_dict[key].append(frame.mean(axis=1).mean()) if 'branch_and_bound_dynamic' in rewards_dict: branch_and_bound_dynamic = np.array(rewards_dict.pop('branch_and_bound_dynamic')) else: branch_and_bound_dynamic = None if 'branch_and_bound_fixed' in rewards_dict: branch_and_bound_fixed = np.array(rewards_dict.pop('branch_and_bound_fixed')) else: branch_and_bound_fixed = None delta = 0.986 if branch_and_bound_dynamic is not None and branch_and_bound_fixed is not None: rewards_dict['branch_and_bound'] = delta * (branch_and_bound_dynamic + branch_and_bound_fixed)/2 elif branch_and_bound_dynamic is not None: rewards_dict['branch_and_bound'] = delta * branch_and_bound_dynamic elif branch_and_bound_fixed is not None: rewards_dict['branch_and_bound'] = delta * branch_and_bound_fixed else: rewards_dict['branch_and_bound'] = delta * np.array([0] * len(rewards_dict.values()[0])) results = OrderedDict() for key in ['branch_and_bound', 'primal_dual_recover', 'lfu', 'lru']: results[algorithm_mapper[key]] = sorted(rewards_dict[key]) plot_kwargs['x_axis'] = [] for _ in x_axis: if _ not in plot_kwargs['x_axis']: plot_kwargs['x_axis'].append(_) display_multiple_(results, **plot_kwargs)